mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
[knex] Allow Identifier Syntax in table Query Builder (#27644)
This commit is contained in:
Vendored
+3
-2
@@ -21,9 +21,10 @@ type Value = string | number | boolean | Date | Array<string> | Array<number> |
|
||||
type ValueMap = { [key: string]: Value | Knex.QueryBuilder };
|
||||
type ColumnName = string | Knex.Raw | Knex.QueryBuilder | {[key: string]: string };
|
||||
type TableName = string | Knex.Raw | Knex.QueryBuilder;
|
||||
type Identifier = { [alias: string]: string };
|
||||
|
||||
interface Knex extends Knex.QueryInterface {
|
||||
(tableName?: TableName): Knex.QueryBuilder;
|
||||
(tableName?: TableName | Identifier): Knex.QueryBuilder;
|
||||
VERSION: string;
|
||||
__knex__: string;
|
||||
|
||||
@@ -179,7 +180,7 @@ declare namespace Knex {
|
||||
}
|
||||
|
||||
interface Table {
|
||||
(tableName: TableName): QueryBuilder;
|
||||
(tableName: TableName | Identifier): QueryBuilder;
|
||||
(callback: Function): QueryBuilder;
|
||||
(raw: Raw): QueryBuilder;
|
||||
}
|
||||
|
||||
@@ -1103,3 +1103,23 @@ knex.schema
|
||||
table.decimal('dec', null);
|
||||
})
|
||||
.dropTable('testTable');
|
||||
|
||||
// allow specifying an alias for a table name
|
||||
knex.schema
|
||||
.dropTableIfExists('foo')
|
||||
.dropTableIfExists('bar')
|
||||
.createTable('foo', function (table) {
|
||||
table.uuid('id').primary();
|
||||
})
|
||||
.createTable('bar', function (table) {
|
||||
table.uuid('id').primary();
|
||||
});
|
||||
|
||||
knex({
|
||||
table1: 'foo',
|
||||
table2: 'bar'
|
||||
})
|
||||
.select({
|
||||
table1Id: 'table1.id',
|
||||
table2Id: 'table2.id'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user