Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda