-
select
db.name('teacher').where('username', '').select().then(res => {})
async function find() {
let res = await db.name('teacher').where('username','').find()
}
-
update
db.name('teacher').where('username', '').update({
username:'张三'
}).then(res => {
console.log(res)
})
-
delete
db.name('teacher').where('username', '').delete().then(res => {
console.log(res)
})
-
insert
db
.name('teacher')
.insert([{
username: '李四',
create_time: new Date(),
}])
.then((res) => {
console.log(res)
})
-
insertGetId
db
.name('teacher')
.insertGetId([{
username: '李四',
create_time: new Date(),
}])
.then((res) => {
console.log(res)
})
-
query
db.query("SELECT * FROM `sc_teacher` WHERE `username` = ''").then(res => {
})
db.exec("SELECT * FROM `sc_teacher` WHERE `username` = ?", ['']).then(res => {
})
-
name (names: string | string[] )
db.name('teacher').where('username', '').select()
-
table (names:string | string[] )
db.table('sc_teacher').where('username', '').select()
-
where (field:string|object, operator?:string|number, condition?:string|string[]|number|number[])
db.name('teacher').where('username = \'\'')
db.name('teacher').where('username', '')
db.name('teacher').where('username', '=', '')
db.name('teacher').where({
username:['']
})
db.name('teacher').where({
username:['=', '']
})
db.name('teacher').where('username', 'like', '%张')
db.name('teacher').where({
username:['like','%张']
})
db.name('teacher').where({
username:[
['like', '%张'],
'or',
['like', '张%']
]
})
db.name('teacher').where({
id:[
['>', 1],
['<', 10]
]
})
db.name('teacher').where({
id:[
['>',1],
'and',
['<', 10]
]
})
db.name('teacher').where('id', 'between', [1,4])
db.name('teacher').where('id', 'not between', [1,4])
db.name('teacher').where('id', 'in', [1,2,3])
db.name('teacher').where('id', 'not in', [1,2,3])
db.name('teacher').where('id', 'null')
db.name('teacher').where('id', 'not null')
-
alias (names:string | object )
db.table('sc_teacher').alias('a').where('username', '').select()
db.table(['sc_teacher', 'sc_student']).alias({
'sc_teacher':'a',
'sc_student':'b'
}).where('username', '').select()
-
field (fields:string )
db.table('sc_teacher').field('id,username,create_time').where('username', '').select()
-
limit (star:string|number, end?:number)
db.table('sc_teacher').where('username', '').limit('1,5').select()
db.table('sc_teacher').where('username', '').limit(1,5).select()
-
group (fields:string)
db.table('sc_teacher').where('username', '').group('id').select()
-
distinct (isDistinct: boolean)
db.table('sc_teacher').field('username').distinct(true).select()
-
join (table: string, condition: string, joinType:sqlJoinType = 'INNER')
type JoinType = 'INNER' | 'LEFT' | 'RIGHT' | 'FULL'
db.table('sc_teacher').alias('a').join("sc_student b", "a.username = b.teacher_name").select()
db.table('sc_teacher').alias('a').where('username', '').join("sc_student b", "a.username = b.teacher_name").select()
-
order (field: string)
db.table('sc_teacher').where('username', '').order('id DESC').select()
db.table('sc_teacher').where('username', '').order('id DESC, username ASC').select()
-
db.table('sc_teacher').comment("Query sc_teacher").where('username', '').select()
-
format (sql:string, values:any[])
db.format('SELECT * FROM sc_teacher a WHERE a.username = ?', [''])
-
config (key:string)
db.config('prefix')