Browse Source

Merge remote-tracking branch 'o1lab/master'

pull/34/head
Bert Verhelst 6 years ago
parent
commit
fc0063af80
  1. 4
      CONTRIBUTING.md
  2. 5
      README.md
  3. 2
      lib/util/cmd.helper.js
  4. 2
      lib/xapi.js
  5. 9
      lib/xsql.js
  6. 2
      package.json
  7. 83
      tests/tests.js

4
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.

5
README.md

@ -17,6 +17,8 @@ Hence this.
# Setup and Usage
xmysql requires node >= 7.6.0
```
npm install -g xmysql
```
@ -170,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

2
lib/util/cmd.helper.js

@ -20,6 +20,7 @@ program
.option('-d, --database <n>', 'database schema name')
.option('-r, --ipAddress <n>', 'IP interface of your server / locahost by default')
.option('-n, --portNumber <n>', 'port number for app / 3000 by default')
.option('-o, --port <n>', 'port number for mysql / 3306 by default')
.option('-s, --storageFolder <n>', 'storage folder / current working dir by default / available only with local')
.option('-i, --ignoreTables <n>', 'comma separated table names to ignore')
.option('-a, --apiPrefix <n>', '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 || 3306;
program.user = program.user || 'root';
program.password = program.password || '';
program.host = program.host || 'localhost';

2
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']) {

9
lib/xsql.js

@ -193,10 +193,15 @@ 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;
}

2
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": {

83
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

Loading…
Cancel
Save