Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Buscar paginación con la biblioteca Knex para Postgress

Intentando implementar la paginación basada en el cursor, y me gustaría saber la forma correcta de llamarlo con Knex para Postgres .

Aquí está la declaración estándar:

 SELECT FROM WHERE (timestamp, id) > (cursor.age, cursor.id) ORDER BY timestamp ASC, id ASC LIMIT

Y mi intento con Knex :

 const knexResult = await knex({ 'table_name' }) .select(columns) .where('created_at', '>', cursor.timestamp) .andWhere('id', '>', cursor.id) .orderBy(['timestamp', 'id']) .limit(first) return knexResult;

¿Es esta la forma correcta de llamarlo? Parece que no es correcto... Estoy tratando de evitar knex.raw

Editar

El estándar SQL para la sentencia (x,y) > (a,b) es verdadero si:

 (x > a or (x = a and y > b))

El código anterior no da resultados porque creo que está tratando de hacer coincidir ambas cláusulas where .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede implementar esta condición booleana (x > a or (x = a and y > b)) con knex.

 const knexResult = await knex({ 'table_name' }) .select(columns) .where('created_at', '>', cursor.timestamp) .orWhere((inner) => inner.where('created_at', '=', cursor.timestamp) .andWhere('id', '>', cursor.id) ) .orderBy(['timestamp', 'id']) .limit(first); return knexResult;

Producirá:

 Select `col1`, `col2` from `table_name` where `created_at` > '12323112' or (`created_at` = '12323112' and id > '23') Order by `timestamp`, `id` Limit 1
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!