排序
order()
对查询结果进行排序,需要传两个参数
- @param
field
排序的字段 - @param
sort
排序规则,DESC倒序 ASC正序 - (field: string, sort: SORT = 'DESC')
order()
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).where('age', '>', 10).order('age').select()
return user
})
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).where('age', '>', 10).order('age').select()
return user
})
最终的SQL语句为:
SELECT * FROM user WHERE age > 10 ORDER BY age DESC
SELECT * FROM user WHERE age > 10 ORDER BY age DESC