Make connection optional for knex Config

It is possible to use knex as a pure query builder without any database
connection. This is specified in the knex documentation.
This commit is contained in:
Alexander Hense
2016-03-18 13:53:53 +01:00
parent cc3d223a94
commit bae73a583a
2 changed files with 11 additions and 1 deletions

View File

@@ -55,6 +55,16 @@ var knex = Knex({
}
});
// Pure Query Builder without a connection
var knex = Knex({});
// Pure Query Builder without a connection, using a specific flavour of SQL
var knex = Knex({
client: 'pg'
});
knex('books').insert({title: 'Test'}).returning('*').toString();
// Migrations
var knex = Knex({
client: 'mysql',

2
knex/knex.d.ts vendored
View File

@@ -409,7 +409,7 @@ declare module "knex" {
debug?: boolean;
client?: string;
dialect?: string;
connection: string|ConnectionConfig|MariaSqlConnectionConfig|
connection?: string|ConnectionConfig|MariaSqlConnectionConfig|
Sqlite3ConnectionConfig|SocketConnectionConfig;
pool?: PoolConfig;
migrations?: MigrationConfig;