Skip to content

包含查询


whereIn()

可通过链式调用的方式来指定多条件的查询

  • @param field 字段名
  • @param value 值, 一般这里传一个数组
  • (field: string, value: (string | number)[] | string | number)

whereIn()

import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
    const user = await Db('user', mysqlConfig).where('age', 10).whereIn('tag', [1, 2, 3]).select()
    return user
})
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
    const user = await Db('user', mysqlConfig).where('age', 10).whereIn('tag', [1, 2, 3]).select()
    return user
})

最终的SQL语句为:

SELECT * FROM user WHERE age = 10 AND tag IN (1, 2, 3)
SELECT * FROM user WHERE age = 10 AND tag IN (1, 2, 3)

备案号:冀ICP备20015584号-2