From d9434f29c01759c5adc5ced243ef48350c49b76d Mon Sep 17 00:00:00 2001 From: Bert Verhelst Date: Sun, 18 Mar 2018 14:49:06 +0100 Subject: [PATCH 1/9] Add minimum node version to readme https://github.com/o1lab/xmysql/issues/5#issuecomment-341099409 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9072e0842a..39391ccc83 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Hence this. # Setup and Usage +xmysql requires node >= 7.6.0 + ``` npm install -g xmysql ``` From 19fbff329e0dda184f5327a8e7781e3d7f8ff9c3 Mon Sep 17 00:00:00 2001 From: Bert Verhelst Date: Sat, 24 Mar 2018 14:10:54 +0100 Subject: [PATCH 2/9] Fix minor typo in xapi.js --- lib/xapi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xapi.js b/lib/xapi.js index 032fde41b0..66d952010a 100644 --- a/lib/xapi.js +++ b/lib/xapi.js @@ -148,7 +148,7 @@ class Xapi { stat.apis += resources[j]['routes'].length - // iterate over rach routes in resource and map function + // iterate over each routes in resource and map function for (var i = 0; i < routes.length; ++i) { switch (routes[i]['routeType']) { From 6cc98cc14dff29313c956d042199e121bc82480f Mon Sep 17 00:00:00 2001 From: jaewon Date: Sun, 29 Apr 2018 16:22:17 +0900 Subject: [PATCH 3/9] add database portnumber --- lib/util/cmd.helper.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/util/cmd.helper.js b/lib/util/cmd.helper.js index d70b949e82..6044ea3c51 100644 --- a/lib/util/cmd.helper.js +++ b/lib/util/cmd.helper.js @@ -20,6 +20,7 @@ program .option('-d, --database ', 'database schema name') .option('-r, --ipAddress ', 'IP interface of your server / locahost by default') .option('-n, --portNumber ', 'port number for app / 3000 by default') + .option('-port, --port ', 'port number for mysql / 3306 by default') .option('-s, --storageFolder ', 'storage folder / current working dir by default / available only with local') .option('-i, --ignoreTables ', 'comma separated table names to ignore') .option('-a, --apiPrefix ', 'api url prefix / "/api/" by default') @@ -53,6 +54,7 @@ exports.handle = program => { /**************** START : default values ****************/ program.ipAddress = program.ipAddress || 'localhost'; program.portNumber = program.portNumber || 3000; + program.port = program.port || 3000; program.user = program.user || 'root'; program.password = program.password || ''; program.host = program.host || 'localhost'; From 44851c8d90c9782818a438841914754bb7731d8d Mon Sep 17 00:00:00 2001 From: jaewon Date: Sun, 29 Apr 2018 16:29:31 +0900 Subject: [PATCH 4/9] add mysql port number cmd parameter --- lib/util/cmd.helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/cmd.helper.js b/lib/util/cmd.helper.js index 6044ea3c51..3f44e2ef0f 100644 --- a/lib/util/cmd.helper.js +++ b/lib/util/cmd.helper.js @@ -54,7 +54,7 @@ exports.handle = program => { /**************** START : default values ****************/ program.ipAddress = program.ipAddress || 'localhost'; program.portNumber = program.portNumber || 3000; - program.port = program.port || 3000; + program.port = program.port || 3306; program.user = program.user || 'root'; program.password = program.password || ''; program.host = program.host || 'localhost'; From f85b2d2c92e48a544210e2cfa2bb6541889901bc Mon Sep 17 00:00:00 2001 From: jaewon Date: Sun, 29 Apr 2018 17:04:01 +0900 Subject: [PATCH 5/9] port key is -o --- lib/util/cmd.helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/cmd.helper.js b/lib/util/cmd.helper.js index 3f44e2ef0f..2b4e50940a 100644 --- a/lib/util/cmd.helper.js +++ b/lib/util/cmd.helper.js @@ -20,7 +20,7 @@ program .option('-d, --database ', 'database schema name') .option('-r, --ipAddress ', 'IP interface of your server / locahost by default') .option('-n, --portNumber ', 'port number for app / 3000 by default') - .option('-port, --port ', 'port number for mysql / 3306 by default') + .option('-o, --port ', 'port number for mysql / 3306 by default') .option('-s, --storageFolder ', 'storage folder / current working dir by default / available only with local') .option('-i, --ignoreTables ', 'comma separated table names to ignore') .option('-a, --apiPrefix ', 'api url prefix / "/api/" by default') From 68df8c77d2a8009327425a5cd606ca6d5f5da9cf Mon Sep 17 00:00:00 2001 From: o1lab Date: Mon, 7 May 2018 22:49:14 +0100 Subject: [PATCH 6/9] Create contributing guidelines --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..75ee422162 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,4 @@ +## Contribution guidelines +- Try to keep it close to original design. Key idea here being zero configuration. So automate by going out of the way. +- Tests to cover new functionality. +- If the issue is a major or large change. Please create a PR issue before working on it. From cfa70c459ccab83c55575f8cc3a199f2b6b2a8a6 Mon Sep 17 00:00:00 2001 From: o1lab Date: Sun, 20 May 2018 12:40:09 +0100 Subject: [PATCH 7/9] Fix #33: _size to return right number of records back. --- README.md | 3 ++ lib/xsql.js | 11 +++++-- tests/tests.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 39391ccc83..c0b4498d7e 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,9 @@ By default 20 records and max of 100 are returned per GET request on a table. /api/payments?_p=2&_size=50 ``` +When _size is greater than 100 - number of records defaults to 100 (i.e maximum) + +When _size is less than or equal to 0 - number of records defaults to 20 (i.e minimum) ## Order by / Sorting diff --git a/lib/xsql.js b/lib/xsql.js index e590380cb9..fd31a505f3 100644 --- a/lib/xsql.js +++ b/lib/xsql.js @@ -193,15 +193,20 @@ class Xsql { reqParams._index = 0; reqParams._len = 20; - if ('_size' in reqParams && parseInt(reqParams._size) < 100) { - reqParams._len = parseInt(reqParams._size) + if('_size' in reqParams) { + if (parseInt(reqParams._size) > 0 && parseInt(reqParams._size) <= 100) { + reqParams._len = parseInt(reqParams._size) + } else if (parseInt(reqParams._size) > 100) { + reqParams._len = 100 + } } + if ('_p' in reqParams && parseInt(reqParams._p) > 0) { reqParams._index = (parseInt(reqParams._p) - 1) * reqParams._len; } - //console.log(reqParams._index, reqParams._len); + console.log(reqParams._index, reqParams._len); return [reqParams._index, reqParams._len] diff --git a/tests/tests.js b/tests/tests.js index a97259ac5c..7f5cf1137b 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -241,6 +241,89 @@ describe('xmysql : tests', function () { }); + + it('GET ' + apiPrefix + 'customers should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(20); + + return done(); + + }); + + }); + + it('GET ' + apiPrefix + 'customers?_size=100 should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers?_size=100') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(100); + + return done(); + + }); + + }); + + it('GET ' + apiPrefix + 'customers?_size=1000 should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers?_size=1000') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(100); + + return done(); + + }); + + }); + + it('GET ' + apiPrefix + 'customers?_size=-1 should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers?_size=-1') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(20); + + return done(); + + }); + + }); + + + it('GET ' + apiPrefix + 'payments?_p=2&_size=10 should PASS', function (done) { //http get an url From afc65604590279945957eec4d89c7e8e0568ed71 Mon Sep 17 00:00:00 2001 From: o1lab Date: Sun, 20 May 2018 12:40:48 +0100 Subject: [PATCH 8/9] Removing a log. --- lib/xsql.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xsql.js b/lib/xsql.js index fd31a505f3..f0089871da 100644 --- a/lib/xsql.js +++ b/lib/xsql.js @@ -206,7 +206,7 @@ class Xsql { reqParams._index = (parseInt(reqParams._p) - 1) * reqParams._len; } - console.log(reqParams._index, reqParams._len); + //console.log(reqParams._index, reqParams._len); return [reqParams._index, reqParams._len] From 45eb1dd4c11eb1d65b7d6986912bb23c8a2d8e3e Mon Sep 17 00:00:00 2001 From: o1lab Date: Sun, 20 May 2018 12:43:11 +0100 Subject: [PATCH 9/9] npm version 0.4.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a870f994..78a759ff10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmysql", - "version": "0.4.4", + "version": "0.4.5", "description": "One command to generate REST APIs for any MySql database", "main": "index.js", "scripts": {