Skip to content

Commit 6b14a66

Browse files
authored
Feature/sql database support (#12)
* got mysql to work * more progress. model now works with sql * updated search tag job * sql model is now tested * added sql as a model functionality
1 parent f27f1d3 commit 6b14a66

17 files changed

+18104
-37
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ Then generate your first API endpoint
5151
$ gulp service --name yourFirstEndpoint // This command will create a CRUD endpoint for yourFirstEndpoint.
5252
```
5353

54-
With the `gulp service` command, you have the option of using either Mongo DB for your database model or using an API generated by this Express Generator as a database model. To use an API as a database you can pass the `baseurl` and the `endpoint` for the API to the `gulp service `. See an example below
54+
With the `gulp service` command, you have the option of using either Mongo DB, an SQL compartible DB or using an API generated by this Express Generator as a database model. To use an API as a database you can pass the `baseurl` and the `endpoint` option for the API to the `gulp service `; for an SQL compartible db, pass the `sql` option. See an example below
55+
56+
### Using an API as a DB
5557

5658
```
5759
$ gulp service --name yourEndpointWithAPIAsDB --baseurl http://localhost:8080 --endpoint users
5860
```
5961

62+
### Using an SQL compartible database
63+
64+
```
65+
$ gulp service --name yourEndpointWITHSQL --sql
66+
```
67+
6068
> Note: You can use -n instead of --name, -b instead of --baseurl, -e instead of --endpoint
6169
6270
Try out your new endpoint.

TODO.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
| app.js | 62 | Write a complete Documentation for this project
55
| config/index.js | 12 | Test for production and development senarios
66
| models/index.js | 14 | Automatically generate tests with the schema structure
7-
| routes/index.js | 294 | Test API versioning
8-
| routes/index.js | 295 | Test rate limiting
9-
| routes/index.js | 296 | Test complete route Loader test
10-
| routes/index.js | 297 | Test _sanitizeRequestUrl middleware function
11-
| routes/index.js | 298 | Test _allRequestData middleware function for default value scenario
12-
| routes/index.js | 299 | Test _enforceUserIdAndAppId middle function for when req.body is an array
13-
| routes/index.js | 300 | Make Log requests testable and write unit tests for it
14-
| routes/index.js | 301 | Develop the route loader into a separate node module to be publish on npm
15-
| routes/index.js | 302 | Develop all services onto separate node module to be publish on npm
7+
| routes/index.js | 298 | Test API versioning
8+
| routes/index.js | 299 | Test rate limiting
9+
| routes/index.js | 300 | Test complete route Loader test
10+
| routes/index.js | 301 | Test _sanitizeRequestUrl middleware function
11+
| routes/index.js | 302 | Test _allRequestData middleware function for default value scenario
12+
| routes/index.js | 303 | Test _enforceUserIdAndAppId middle function for when req.body is an array
13+
| routes/index.js | 304 | Make Log requests testable and write unit tests for it
14+
| routes/index.js | 305 | Develop the route loader into a separate node module to be publish on npm
15+
| routes/index.js | 306 | Develop all services onto separate node module to be publish on npm
1616
| services/logger/index.js | 36 | Test Error Handler
1717
| services/queue/clock.js | 11 | work on a clock functionality so kue can support scheduled jobs
1818
| services/queue/clock.js | 12 | Use the cron package here https://www.npmjs.com/package/cron for timer

config/development.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,12 @@ module.exports = {
2323
queueUIPassword: process.env.QUEUE_UI_PASSWORD || 'password123/',
2424
queueUIPort: process.env.QUEUE_UI_PORT || 3000,
2525
enforceUserIdAppIdDeveloperId: process.env.ENFORCE_USER_ID_APP_ID_DEVELOPER_ID || 'no',
26-
apiDBKey: process.env.API_DB_Key || 'MDg4NWM1NTA0ZTZlNTQ5MjAzNzA1ODBlOWVkNzI3MzdlNmYxZTcyMjVkOTA3N2JjYTBhZjA0YmM0N2U4NDZkNi8vLy8vLzQ1MDY='
26+
apiDBKey: process.env.API_DB_Key || 'MDg4NWM1NTA0ZTZlNTQ5MjAzNzA1ODBlOWVkNzI3MzdlNmYxZTcyMjVkOTA3N2JjYTBhZjA0YmM0N2U4NDZkNi8vLy8vLzQ1MDY=',
27+
SQLUsername: process.env.SQL_USERNAME || 'root',
28+
SQLPassword: process.env.SQL_PASSWORD || null,
29+
SQLDatabase: process.env.SQL_DATABASE || 'snipe',
30+
SQLHost: process.env.SQL_HOST || '192.168.99.100',
31+
SQLPort: process.env.SQL_PORT || 3306,
32+
SQLDriver: process.env.SQL_DRIVER || 'mysql', //'mysql'|'sqlite'|'postgres'|'mssql'
33+
SQLTimezone: process.env.SQL_TIMEZONE || '+01:00'
2734
};

config/production.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,12 @@ module.exports = {
2323
queueUIPassword: process.env.QUEUE_UI_PASSWORD || 'password123/',
2424
queueUIPort: process.env.QUEUE_UI_PORT || 3000,
2525
enforceUserIdAppIdDeveloperId: process.env.ENFORCE_USER_ID_APP_ID_DEVELOPER_ID || 'no',
26-
apiDBKey: process.env.API_DB_Key || 'MDg4NWM1NTA0ZTZlNTQ5MjAzNzA1ODBlOWVkNzI3MzdlNmYxZTcyMjVkOTA3N2JjYTBhZjA0YmM0N2U4NDZkNi8vLy8vLzQ1MDY='
26+
apiDBKey: process.env.API_DB_Key || 'MDg4NWM1NTA0ZTZlNTQ5MjAzNzA1ODBlOWVkNzI3MzdlNmYxZTcyMjVkOTA3N2JjYTBhZjA0YmM0N2U4NDZkNi8vLy8vLzQ1MDY=',
27+
SQLUsername: process.env.SQL_USERNAME || 'root',
28+
SQLPassword: process.env.SQL_PASSWORD || null,
29+
SQLDatabase: process.env.SQL_DATABASE || 'snipe',
30+
SQLHost: process.env.SQL_HOST || 'localhost',
31+
SQLPort: process.env.SQL_PORT || 3306,
32+
SQLDriver: process.env.SQL_DRIVER || 'mysql', //'mysql'|'sqlite'|'postgres'|'mssql'
33+
SQLTimezone: process.env.SQL_TIMEZONE || '+01:00'
2734
};

gulpfile.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ gulp.task('service', function(){
6262
var name;
6363
var baseurl;
6464
var endpoint;
65+
var isSQL;
6566
baseurl = args.baseurl;
6667
endpoint = args.endpoint;
6768
if(!baseurl){
@@ -71,7 +72,11 @@ gulp.task('service', function(){
7172
if(!endpoint){
7273
endpoint = args.e;
7374
}
75+
76+
isSQL = args.sql;
77+
7478
name = args.name;
79+
7580
if(!name){
7681
name = args.n;
7782
}
@@ -102,7 +107,7 @@ gulp.task('service', function(){
102107
});
103108

104109
// Create the Route Unit Test
105-
fs.readFile('./template/route_test.tmpl', function(err, data){
110+
fs.readFile(isSQL ? './template/route_sql_test.tmpl' : './template/route_test.tmpl', function(err, data){
106111
if (err){
107112
throw err;
108113
}
@@ -134,7 +139,7 @@ gulp.task('service', function(){
134139
});
135140
});
136141
}else{
137-
fs.readFile('./template/model.tmpl', function(err, data){
142+
fs.readFile(isSQL ? './template/model_sql.tmpl' : './template/model.tmpl', function(err, data){
138143
if (err){
139144
throw err;
140145
}
@@ -151,7 +156,7 @@ gulp.task('service', function(){
151156
}
152157

153158
// Create the Model Unit Test
154-
fs.readFile('./template/model_test.tmpl', function(err, data){
159+
fs.readFile(isSQL ? './template/model_sql_test.tmpl' : './template/model_test.tmpl', function(err, data){
155160
if (err){
156161
throw err;
157162
}
@@ -167,7 +172,7 @@ gulp.task('service', function(){
167172
});
168173

169174
// Create the controller
170-
fs.readFile('./template/controller.tmpl', function(err, data){
175+
fs.readFile(isSQL ? './template/controller_sql.tmpl' : './template/controller.tmpl', function(err, data){
171176
if (err){
172177
throw err;
173178
}
@@ -183,7 +188,7 @@ gulp.task('service', function(){
183188
});
184189

185190
// Create the controller Unit test
186-
fs.readFile('./template/controller_test.tmpl', function(err, data){
191+
fs.readFile(isSQL ? './template/controller_sql_test.tmpl' : './template/controller_test.tmpl', function(err, data){
187192
if (err){
188193
throw err;
189194
}

0 commit comments

Comments
 (0)