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. 12
      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 * Upload multiple files
* Download file * 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 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: Options:
-V, --version output the version number -V, --version output the version number
-h, --host <n> hostname of mysql -h, --host <n> hostname / localhost by default
-d, --database <n> database schema name
-u, --user <n> username of database / root by default -u, --user <n> username of database / root by default
-p, --password <n> password of database / empty by default -p, --password <n> password of database / empty by default
-n, --portNumber <n> port number / 3000 by default -d, --database <n> database schema name
-s, --storageFolder <n> storage folder / current working dir by default -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 -h, --help output usage information
Examples: Examples:

4
lib/util/cmd.helper.js

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

12
lib/xsql.js

@ -513,9 +513,12 @@ class Xsql {
for (var tableName in this.metaDb.tables) { for (var tableName in this.metaDb.tables) {
if (tableName in this.sqlConfig.ignoreTables) {
//console.log('ignore table', tableName);
} else {
let routes = [] let routes = []
let tableObj = {} let tableObj = {}
let table = this.metaDb.tables[tableName]; let table = this.metaDb.tables[tableName];
tableObj['resource'] = tableName; tableObj['resource'] = tableName;
@ -540,14 +543,21 @@ class Xsql {
for (var j = 0; j < table['foreignKeys'].length; ++j) { for (var j = 0; j < table['foreignKeys'].length; ++j) {
let fk = table['foreignKeys'][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')) routes.push(this.prepareRoute(internal, 'get', apiPrefix, fk['referenced_table_name'] + '/:id/' + fk['table_name'], 'relational'))
} }
}
tableObj['routes'] = routes; tableObj['routes'] = routes;
schemaRoutes.push(tableObj); schemaRoutes.push(tableObj);
} }
}
return schemaRoutes; return schemaRoutes;

2
package.json

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

Loading…
Cancel
Save