knex / knex

A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
https://knexjs.org/
MIT License
18.96k stars 2.1k forks source link

Improve the documentation on the `--knexpath` flag #5884

Open CodyEakins opened 4 years ago

CodyEakins commented 4 years ago

The docs do not offer enough information on the --knexpath flag...

It should cover at least two key concerns: (1) What does the --knexpath flag do? (2) And how does a developer properly use the --knexpath flag (by example)?

But currently, this is all we're left with:

--knexpath [path]: Specify the path to the knex instance

This definition is too broad.

In my mind, I should be able to use this flag to pass a pre-configured knex instance to the CLI for use in operations like migrate:latest.

However, when I run: knex migrate:latest --knexpath ./services/knex.js

Note: I purposely do not use the --knexfile flag here to pass a knexfile.js to the CLI because passing in a pre-configured knex instance with --knexpath should be sufficient. Config should be inferred from the instance.

I get an error: Error: No default configuration file [...] found and no commandline connection parameters passed

This could be just a bug, or an issue with how I am using --knexpath (without a knexfile.js)...

But I can't know for sure, because the docs do not cover this.

paolog22 commented 3 years ago

Still looking for this in 2021 hahaha

Va1 commented 2 years ago

it appears that if the file you specify with --knexfile exports an initialized knex instance, it will suffice. i think --knexpath was basically merged into --knexfile and dropped as a separate command.

tamlyn commented 1 year ago

it appears that if the file you specify with --knexfile exports an initialized knex instance, it will suffice.

Does that work for you? When I do that I get a different error about SELECT * with no tables specified is not valid the source of which is identified in this comment to be exporting a knex instance from knexfile rather than a config object.

Looking at the code it seems that knexpath is currently unused, but that it is/was intended to point to the knex cli file, not a knex instance.

https://github.com/knex/knex/blob/939d8a219c432a7d7dcb1ed1a79d1e5a4686eafd/bin/cli.js#L94-L98

kauemurakami commented 4 months ago

When using knex migrate:latest --knexfile ./app/core/configs/knex/knex.js I get the same errors

Working directory changed to C:\projetos\x-api\app\core\configs\knex
calling knex without a tableName is deprecated. Use knex.queryBuilder() instead.
select * - SELECT * with no tables specified is not valid
error: select * - SELECT * with no tables specified is not valid

Has anyone found a solution? I get the same when using up. my knex.js

const env = process.env.NODE_ENV || 'development';
const config = require('./config')[env];
const knex = require('knex')(config);

module.exports = knex;

my configs

const development = {
    client: 'pg',
    connection: {
        host: 'xxxx.x.x',
        user: 'postgres',
        password: 'pass',
        database: 'dbname,
        port: xxxx,

    },
    migrations: {
        migrations: {
            tableName: 'knex_migrations',
            directory: './app/core/configs/knex/db/migrations'
        },
    }
}; ....