指定要显示的字段
field()
指定要显示哪些字段,需要传两个参数
- @param
str
字段名用英文逗号隔开,如:id,name,age - @param
isDistinct
是否去重,默认不开启 - (str: string, isDistinct: boolean = false)
field()
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).field('id, name', true).select()
return user
})
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).field('id, name', true).select()
return user
})
最终的SQL语句为:
SELECT DISTINCT id, name FROM user
SELECT DISTINCT id, name FROM user