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?
.withSchema("appschema") should not be used here, because then you don't get the knex-object. Instead you get a knex query builder.