Skip to content

限定查询数量


limit()

限制查询的条数,一般为了语义化会写在所有条件之后,select() findOne() 之前

  • @param num 要查询的条数

limit()

import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
    const user = await Db('user', mysqlConfig).where('age', '>', 10).limit(10).select()
    return user
})
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
    const user = await Db('user', mysqlConfig).where('age', '>', 10).limit(10).select()
    return user
})

最终的SQL语句为:

SELECT * FROM user WHERE age > 10 LIMIT 10
SELECT * FROM user WHERE age > 10 LIMIT 10

备案号:冀ICP备20015584号-2