@stormzx/sqlbuilder
v0.0.11
Published
A simple sql builder.
Downloads
6
Readme
a simple sql builder for mysql.
Todo
- [x] select
- [x] insert
- [x] update
- [ ] delete
Raw:
- raw = raw
- string = raw#string
- table = raw#table
- column = raw#column
- expression = raw#expression
- orderBy = raw#order
api:
- table(tablename:string, as?:string)
import { table } from '@stormzx/sqlbuilder'
let u = table('users', 'u')
let transform = `
# use like object
u => ${u}
u.id => ${u.id}
u.userId => ${u.userId}
u.userId.as('uid') => ${u.userId.as('uid')}
# use like function
u('id', 'userId') = [u.id, u.userId] => ${u('id', 'userId')}
u('id', ['userId', 'uid']) = [u.id, u.userId.as('uid')] => ${u('id', ['userId', 'uid'])}
`
console.log(transform)
// Output:
// # use like object
// u => `users` as `u`
// u.id => `u`.`id`
// u.userId => `u`.`user_id`
// u.userId.as('uid') => `u`.`user_id` as `uid`
// # use like function
// u('id', 'userId') = [u.id, u.userId] => `u`.`id`,`u`.`user_id`
// u('id', ['userId', 'uid']) = [u.id, u.userId.as('uid')] => `u`.`id`,`u`.`0` as `uid`
- raw(rawSql: string)
- escape(value: any)
- escapeId(column: string)
- SQLBuilder
import {SQLBuilder, table} from '@stormzx/sqlbuilder'
let u = table('users', 'u')