Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

databaseManagerFactory doesn't work when the Knex config uses a database URL as the connection property #76

Open
JReinhold opened this issue Jan 10, 2020 · 6 comments

Comments

@JReinhold
Copy link

The problem

In Knex, it is possible to define the connection as a single database URL, like:

{
  client: 'pg',
  connection: 'postgres://user:password@localhost:5432/database',
};

This is not supported by the databaseManagerFactory, it requires that the connection property is on the object form, like:

{
    client: 'pg',
    connection: {
      host: 'localhost',
      port: 5432,
      user: 'user,
      password: 'password',
      database: 'database',
    }
}

This makes it inconsistent with Knex. If it is too hard to pull in Knex' way of reading the config, an alternative would be to just document this shortcoming.

Workaround

For what it's worth, I get the values by running RegExp on the database URL, and it works:

const [
  ,
  user,
  password,
  host,
  port,
  database
] = /:\/\/(.*?):(.*?)@(.*?):(.*?)\/(.*)/u.exec(knexConnection);

const databaseManager = databaseManagerFactory({
  knex: {
    client: 'pg',
    connection: {
      host,
      port,
      user,
      password,
      database,
    },
  },
  dbManager: {
    ...
  },
});
@elhigu
Copy link

elhigu commented Jan 10, 2020

Currently knex-db-manager does not support

connection: 'postgres://user:password@localhost:5432/database',

connections, but connection object is always needed. There is plans to support this, but I'm not sure yet if I'm going to implement it to knex side or here.

There is feature (universal connection string format that is parsed to connection object) being planned in knex side, which would help implementing also this.

@JReinhold
Copy link
Author

There is feature (universal connection string format that is parsed to connection object) being planned in knex side, which would help implementing also this.

It makes sense, it should probably be parked then, until it has been built.

@nabilfreeman

This comment has been minimized.

@elhigu

This comment has been minimized.

@nabilfreeman

This comment has been minimized.

@elhigu

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants