Browse Source

feature addition: make file upload and download - available only in local

pull/8/head
oof1lab 7 years ago
parent
commit
8ca85a98a5
  1. 18
      README.md
  2. 4
      lib/util/cmd.helper.js
  3. 12
      lib/xapi.js
  4. 7
      lib/xsql.js

18
README.md

@ -170,6 +170,14 @@ eg: SELECT country,city,count(*) FROM offices GROUP BY country,city ORDER BY cit
eg: SELECT country,city,count(*) FROM offices GROUP BY country,city ORDER BY city ASC, country DESC
## Relational Tables
xmysql identifies foreign key relations automatically and provides GET api.
```
/api/customers/103/payments
```
eg: Customers is parent table and payments is child table. API invocation will result in all payments with customer 103.
## Run dynamic queries
Dynamic queries on a database can be run by POST method to URL localhost:3000/dynamic
@ -188,12 +196,6 @@ POST /dynamic
"params": ["customers"]
}
```
## Relational Tables
xmysql identifies foreign key relations automatically and provides GET api.
```
/api/customers/103/payments
```
eg: Customers is parent table and payments is child table. API invocation will result in all payments with customer 103.
## Upload single file
@ -206,6 +208,7 @@ returns uploaded file name else 'upload failed'
(Note: POSTMAN has issues with file uploading hence examples with curl)
## Upload multiple files
```
POST /uploads
@ -219,7 +222,8 @@ returns uploaded file names as string
## Download file
http://localhost:3000/download?name=fileName
For upload and download of files -> you can specify storage folder using -s option
> For upload and download of files -> you can specify storage folder using -s option
> Upload and download apis are available only with local mysql server
## When to use ?
* You need just REST APIs without much hassle for (ANY) MySql database.

4
lib/util/cmd.helper.js

@ -16,8 +16,8 @@ program
.option('-d, --database <n>', 'database schema name')
.option('-u, --user <n>', 'username of database / root by default')
.option('-p, --password <n>', 'password of database / empty by default')
.option('-n, --portNumber <n>', 'port number : 3000 by default')
.option('-s, --storageFolder <n>', 'storage folder / current working dir by default')
.option('-n, --portNumber <n>', 'port number / 3000 by default')
.option('-s, --storageFolder <n>', 'storage folder / current working dir by default / available only with local')
.parse(process.argv)

12
lib/xapi.js

@ -9,7 +9,7 @@ class Xapi {
constructor(args, mysqlPool, app) {
this.sqlConfig = args;
this.config = args;
this.mysql = new Xsql(args, mysqlPool)
this.app = app;
@ -174,11 +174,10 @@ class Xapi {
/**************** END : setup routes for each table ****************/
if (this.sqlConfig.dynamic === 1) {
if (this.config.dynamic === 1) {
this.app.route('/dynamic*')
.post(this.asyncMiddleware(this.runQuery.bind(this)));
}
/**************** START : multer routes ****************/
this.app.post('/upload', this.upload.single('file'), this.uploadFile.bind(this));
@ -189,6 +188,11 @@ class Xapi {
}
}
async create(req, res) {
let query = 'INSERT INTO ?? SET ?';

7
lib/xsql.js

@ -419,8 +419,13 @@ class Xsql {
r.push(apiPrefix + "tables")
if (this.sqlConfig.dynamic)
if (this.sqlConfig.dynamic) {
r.push(apiPrefix + "dynamic")
r.push("/upload")
r.push("/uploads")
r.push("/download")
}
return r;

Loading…
Cancel
Save