Skip to content
Christoph Herrmann edited this page Oct 17, 2019 · 3 revisions
const limit = 5
const fallbackLimit = 15
const maxLimit = 50

const result = await sql.query(sql`
  SELECT * FROM users ${sql.limit(limit, { fallbackLimit, maxLimit })}
`)

// text: SELECT * FROM users LIMIT 5
// values: []

The default fallbackLimit 10 can be changed by setting sql.defaultFallbackLimit.

The default maxLimit 100 can be changed by setting sql.defaultMaxLimit.

The limit is dedicated validated and set into the text without parameter placeholder, because a placeholder don't care about the number is negative or positive and a negative number for the limit would result in a SQL error.

Clone this wiki locally