范围查询
whereBetween()
可通过链式调用的方式来指定多条件的查询
- @param
field
字段名 - @param
value1
值1 - @param
value2
值2 - (field: string, value1: string | number, value2: string | number)
whereBetween()
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).where('age', 10).whereBetween('score', 60, 80).select()
return user
})
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).where('age', 10).whereBetween('score', 60, 80).select()
return user
})
最终的SQL语句为:
SELECT * FROM user WHERE age = 10 AND score BETWEEN 60 AND 80
SELECT * FROM user WHERE age = 10 AND score BETWEEN 60 AND 80