[knex] Allow Identifier Syntax in table Query Builder (#27644)

This commit is contained in:
Scott Trinh
2018-07-27 15:57:11 -07:00
committed by Andy
parent b7d70d6879
commit e4dc373d16
2 changed files with 23 additions and 2 deletions
+3 -2
View File
@@ -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;
}
+20
View File
@@ -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'
});