Browse Source

Feature : cmdline option ignore tables - to not generate/expose REST API for certain tables

pull/13/head
oof1lab 7 years ago
parent
commit
21c57180e3
  1. 10
      README.md
  2. 4
      lib/util/cmd.helper.js
  3. 72
      lib/xsql.js
  4. 2
      package.json

10
README.md

@ -80,6 +80,7 @@ Powered by popular node packages : ([express](https://github.com/expressjs/expre
* Upload multiple files
* Download file
Use HTTP clients like [Postman](https://www.getpostman.com/) or [similar tools](https://chrome.google.com/webstore/search/http%20client?_category=apps) to invoke REST API calls
____
@ -638,12 +639,13 @@ http://localhost:3000/download?name=fileName
Options:
-V, --version output the version number
-h, --host <n> hostname of mysql
-d, --database <n> database schema name
-h, --host <n> hostname / localhost by default
-u, --user <n> username of database / root by default
-p, --password <n> password of database / empty by default
-n, --portNumber <n> port number / 3000 by default
-s, --storageFolder <n> storage folder / current working dir by default
-d, --database <n> database schema name
-n, --portNumber <n> port number for app / 3000 by default
-s, --storageFolder <n> storage folder / current working dir by default / available only with local
-i, --ignoreTables <n> comma separated table names to ignore
-h, --help output usage information
Examples:

4
lib/util/cmd.helper.js

@ -11,7 +11,7 @@ program.on('--help', () => {
})
program
.version('0.2.5')
.version('0.2.6')
.option('-h, --host <n>', 'hostname / localhost by default')
.option('-u, --user <n>', 'username of database / root by default')
.option('-p, --password <n>', 'password of database / empty by default')
@ -59,6 +59,8 @@ exports.handle = program => {
for (var i = 0; i < ignoreTables.length; ++i) {
program.ignoreTables[ignoreTables[i]] = ignoreTables[i];
}
} else {
program.ignoreTables = {}
}
program.connectionLimit = 10;

72
lib/xsql.js

@ -513,40 +513,50 @@ class Xsql {
for (var tableName in this.metaDb.tables) {
let routes = []
let tableObj = {}
let table = this.metaDb.tables[tableName];
tableObj['resource'] = tableName;
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/describe', 'describe'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/count', 'count'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/groupby', 'groupby'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/ugroupby', 'ugroupby'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/chart', 'chart'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/aggregate', 'aggregate'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/findOne', 'findOne'))
routes.push(this.prepareRoute(internal, 'post', apiPrefix, tableName, 'create'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName, 'list'))
routes.push(this.prepareRoute(internal, 'post', apiPrefix, tableName + '/bulk', 'bulkInsert'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/bulk', 'bulkRead'))
routes.push(this.prepareRoute(internal, 'delete', apiPrefix, tableName + '/bulk', 'bulkDelete'))
routes.push(this.prepareRoute(internal, 'put', apiPrefix, tableName, 'update'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/:id', 'read'))
routes.push(this.prepareRoute(internal, 'patch', apiPrefix, tableName + '/:id', 'patch'))
routes.push(this.prepareRoute(internal, 'delete', apiPrefix, tableName + '/:id', 'delete'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/:id/exists', 'exists'))
for (var j = 0; j < table['foreignKeys'].length; ++j) {
let fk = table['foreignKeys'][j]
routes.push(this.prepareRoute(internal, 'get', apiPrefix, fk['referenced_table_name'] + '/:id/' + fk['table_name'], 'relational'))
}
if (tableName in this.sqlConfig.ignoreTables) {
//console.log('ignore table', tableName);
} else {
tableObj['routes'] = routes;
let routes = []
let tableObj = {}
let table = this.metaDb.tables[tableName];
tableObj['resource'] = tableName;
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/describe', 'describe'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/count', 'count'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/groupby', 'groupby'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/ugroupby', 'ugroupby'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/chart', 'chart'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/aggregate', 'aggregate'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/findOne', 'findOne'))
routes.push(this.prepareRoute(internal, 'post', apiPrefix, tableName, 'create'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName, 'list'))
routes.push(this.prepareRoute(internal, 'post', apiPrefix, tableName + '/bulk', 'bulkInsert'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/bulk', 'bulkRead'))
routes.push(this.prepareRoute(internal, 'delete', apiPrefix, tableName + '/bulk', 'bulkDelete'))
routes.push(this.prepareRoute(internal, 'put', apiPrefix, tableName, 'update'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/:id', 'read'))
routes.push(this.prepareRoute(internal, 'patch', apiPrefix, tableName + '/:id', 'patch'))
routes.push(this.prepareRoute(internal, 'delete', apiPrefix, tableName + '/:id', 'delete'))
routes.push(this.prepareRoute(internal, 'get', apiPrefix, tableName + '/:id/exists', 'exists'))
for (var j = 0; j < table['foreignKeys'].length; ++j) {
let fk = table['foreignKeys'][j]
if(fk['referenced_table_name'] in this.sqlConfig.ignoreTables){
//console.log('ignore table',fk['referenced_table_name']);
} else {
routes.push(this.prepareRoute(internal, 'get', apiPrefix, fk['referenced_table_name'] + '/:id/' + fk['table_name'], 'relational'))
}
schemaRoutes.push(tableObj);
}
tableObj['routes'] = routes;
schemaRoutes.push(tableObj);
}
}
return schemaRoutes;

2
package.json

@ -1,6 +1,6 @@
{
"name": "xmysql",
"version": "0.2.5",
"version": "0.2.6",
"description": "One command to generate REST APIs for any MySql database",
"main": "index.js",
"scripts": {

Loading…
Cancel
Save