模糊查询
whereLike()
可通过链式调用的方式来指定多条件的查询
- @param
field
字段名 - @param
value
值, 注意一般这里传一个字符串,带上通配符,使用 %(代表零个或多个字符)和 _(代表单个字符)进行模糊匹配 - (field: string, value: string | number)
whereLike()
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).where('age', 10).whereLike('name', '%三%').select()
return user
})
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).where('age', 10).whereLike('name', '%三%').select()
return user
})
最终的SQL语句为:
SELECT * FROM user WHERE age = 10 AND name LIKE '%三%'
SELECT * FROM user WHERE age = 10 AND name LIKE '%三%'