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

179
Visualizações
Why does knex.ref return `not-a-function` error?

I have a hard time to use ref in knex - because no matter what I do it returns ref is not a function.

knex.js-File

const database = knex({
    client: "pg",
    connection: connectionString,
    pool: {
        min: 2,
        max: 10,
    },
    debug: isDevelopment,
}).withSchema("appschema");

module.exports = database;

Example 1:

const database = require("../knex.js");

async function getResults() {
   const result = await database.from("table").select(database.ref("id").as("table_id"); <- ref not a function
}

Example 2:

const database = require("../knex.js");
const knex = require("knex");

async function getResults() {
   const result = await database.from("table").select(knex.ref("id").as("table_id"); <- ref not a function
}

Example 3:

const database = require("../knex.js");
const Knex = require("knex");

async function getResults() {
   const result = await database.from("table").select(Knex.ref("id").as("table_id"); <- ref not a function
}

I would expect, at least from the documentation and some examples in the web, that it should be used like the first example.

What am I doing wrong here?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

.withSchema("appschema") should not be used here, because then you don't get the knex-object. Instead you get a knex query builder.

about 4 years ago · Santiago Gelvez 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