1.1.1 • Published 10 years ago
koa-sql-select v1.1.1
koa-select 
Add query SELECT generator for KoaJS app
Setup
npm i -S koa-sql-select
Usage
Generate SQL SELECT request
sqlSelect = require('koa-sql-select');
app = koa();
app.use(sqlSelect);
app.use(function * () {
var sqlString = this.sqlSelect()
.setTable('example')
.addField('id')
.addField('name')
.getSql(); // SELECT id, name FROM example;
});
With WHERE clause
sqlSelect = require('koa-sql-select');
app = koa();
app.use(sqlSelect);
app.use(function * () {
var theId = 2,
sqlString = this.sqlSelect()
.setTable('example')
.addField('id')
.addField('name')
.addWhere('id', 'int', theId, 0) // cf addWhere description for the 0 at the end
.getSql(); // SELECT id, name FROM example WHERE id = 2;
});
addWhere
Four parameters are required : 1. column needed to match 2. type of data 3. value asked to match 4. value used as default in case of theId is undefined
Licence
WTFPL. Do what you want with this.
Thanks to
- Companeo (@Companeo), which lets me create and publish this tool during my working time. They use it and hope you will use it too.
- Benjamin (@benjaminW78), from Companeo, for his help and work during designing this tool.