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

282
Vistas
How to apply LOWER() to a ref in Objection

Im using a like where statement in my query like this:

import { ref } from 'objection'

// [...]

query = query.where(ref('data.nested_data').castText(), 'like', `%${value}%`)

And its working fine. The resulting query looks like this:

WHERE CAST("data"#>>'{nested_data}' AS text) like '%example%'

Now I want to use LOWER() funcion in the key, so I can find results case-insensitive. So my query now looks like this:

import { ref, raw } from 'objection'

// [...]

query = query.where(raw(`LOWER(${ref('data.nested_data').castText()})`), 'like', `%${value.toLowerCase()}%`);

But this results to the following SQL query (throwing an error):

WHERE LOWER([object Object]) like $1

-- ERROR:  syntax error at or near "["
-- LINE 6: WHERE LOWER([object Object]) like $1

Is there any way to achieve what Im looking for? I prefer not using a raw query since my type to cast is dynamic

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

0

The people maintaining Objection helped me solving this issue at github.

The correct syntax is:

const key = ref('data.nested_data').castText();
query = query.where(raw('LOWER(??)', [key]), 'like', `%${value.toLowerCase()}%`);
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