API
Method
new sqlKit(config:Object)
sql object constructor
@config:Object
- query:Object
- default: {}
- sort:Array
- default: ['-created']
- meta:Object
- default: {limit:10,page:0,skip:0}
new sqlKit(config:Object).clearSort()
clear sort to an empty array
new sqlKit(config:Object).onlySort(attr:String)
set the sort in only one element
example
// set sort to ['+created']
new sqlKit(config:Object).onlySort('+created')
new sqlKit(config:Object).setSort(attr:String)
set the element to sort array
example
let sql = new sqlKit({
sort:['+rank','+money']
});
console.log(sql.sort); // ['+rank','+money']
sql.setSort('+created') // set sort to ['+created']
console.log(sql.sort); // ['+created','+rank','+money']
new sqlKit(config:Object).pushSort(attr:String)
push an element to sort array like Array.push
new sqlKit(config:Object).popSort(attr:String)
pop an element to sort array like Array.pop
new sqlKit(config:Object).shiftSort(attr:String)
shift an element to sort array like Array.shift
new sqlKit(config:Object).unshiftSort(attr:String)
unshift an element to sort array like Array.unshift
new sqlKit(config:Object).removeSort(attr:String)
remove an element from sort array
example
let sql = new sqlKit({
sort:['+rank','+money']
});
console.log(sql.sort); // ['+rank','+money']
sql.removeSort('rank') // set sort to ['+created']
console.log(sql.sort); // ['+money']
new sqlKit(options:Object).toParams()
compile the sqlKit object to url params object
example
let sql = new sqlKit({
query:{
$eq$status:1
},
sort:['-created'],
meta:{
limit:10,
page:0,
skip:0
}
});
let params = sql.toParams()
console.log(params);
/**
{
query:"{'%eq':{status:1}}",
sort:"['-created']",
limit:10,
page:0,
skip:0
}
*/
sqlKit().parserParams()
parser the params which was generated by new sqlKit(config:Object).toParams()
new sqlKit(config:Object).toString()
recover the prototype method to compile the sqlKit object to sql string
example
let sql = new sqlKit({
query:{
$eq$status:1
},
sort:['-created'],
meta:{
limit:10,
page:0,
skip:0
}
});
let params = sql + ''
console.log(params);
/**
[
{
"%eq":{
stataus:1
}
},
{
"%o":['-created']
},
{
"%l":10,
"%p":0,
"%s":0
}
]
*/
Property
- query:Object
- sort:Array
- meta:Object
- MetaQuery:Object
an object prepare to compile to sql string