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

178
Views
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 answers
Answer question

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 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!