Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
How to add dynamic Where queries in objection.js?

I have a table which has a global search bar that needs to trigger search for all fields like firstName, lastName, email and role.

Also have a dynamic filter which can have single or multiple filter like "firstName" or/And "lastName"

Obviously they need to be paginated.

For pagination i can use Model.query().page(1, 10)

But how to supply search or filter. assuming only search or filter active at a given time.

Search and filter both using LIKE. How to dynamically do this.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Objections allows you to modify the query:

let filtersArr = [.. build your filters]

await YourModel
.query()
.modify((queryBuilder) => {
    if (hasFilters) {
        filtersArr.forEach(({criteria, value}) => {
            queryBuilder.where(criteria, value)
        })
    }

    if (hasQ) {
        queryBuilder.where('name', 'ilike', `%${q}%`)
    }
  })
 .page(page, paginate)

this can be extended to include relations, or sort and it doesn't have to be exclusive for one at the time, you can filter, sort and search all within the same query

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda