Tengo dificultades para usar ref en knex, porque no importa lo que haga, devuelve ref is not a function .
Archivo knex.js
const database = knex({ client: "pg", connection: connectionString, pool: { min: 2, max: 10, }, debug: isDevelopment, }).withSchema("appschema"); module.exports = database;Ejemplo 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 }Ejemplo 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 }Ejemplo 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 }Esperaría, al menos de la documentación y algunos ejemplos en la web, que debería usarse como el primer ejemplo.
¿Qué estoy haciendo mal aquí?
.withSchema("appschema") no debe usarse aquí, porque entonces no obtiene el objeto knex. En su lugar, obtiene un generador de consultas knex.