knex: added declarations for with(), withRaw() and withWrapped() (#15966)

Add an optional extended description…
This commit is contained in:
Martynas Kunigėlis
2017-04-26 14:57:43 -07:00
committed by Sheetal Nandi
parent fac0ab9e37
commit 86d6ae08ba
2 changed files with 40 additions and 0 deletions
+17
View File
@@ -64,6 +64,11 @@ declare namespace Knex {
fullOuterJoin: Join;
crossJoin: Join;
// Withs
with: With;
withRaw: WithRaw;
withWrapped: WithWrapped;
// Wheres
where: Where;
andWhere: Where;
@@ -203,6 +208,18 @@ declare namespace Knex {
(tableName: string, binding?: Value): QueryBuilder;
}
interface With extends WithRaw, WithWrapped {
}
interface WithRaw {
(alias: string, raw: Raw): QueryBuilder;
(alias: string, sql: string, bindings?: Value[] | Object): QueryBuilder;
}
interface WithWrapped {
(alias: string, callback: (queryBuilder: QueryBuilder) => any): QueryBuilder;
}
interface Where extends WhereRaw, WhereWrapped, WhereNull {
(raw: Raw): QueryBuilder;
(callback: (queryBuilder: QueryBuilder) => any): QueryBuilder;
+23
View File
@@ -315,6 +315,29 @@ knex('accounts').where('activated', false).delete();
knex('accounts').where('activated', false).delete('id');
knex('accounts').where('activated', false).delete(['id', 'title']);
knex.with('old_books', function(qb) {
qb.select('*').from('books').where('published_date', '<', 1970);
}).select('*').from('old_books');
knex.with('new_books', knex.raw('select * from books where published_date >= 2016'))
.select('*').from('new_books');
knex.with('new_books', 'select * from books where published_date >= :year', { year: 2016 })
.select('*').from('new_books');
knex.with('new_books', 'select * from books where published_date >= ?', [2016])
.select('*').from('new_books');
knex.withRaw('recent_books', 'select * from books where published_date >= :year', { year: 2013 })
.select('*').from('recent_books');
knex.withRaw('recent_books', knex.raw('select * from books where published_date >= ?', [2013]))
.select('*').from('recent_books');
knex.withWrapped("antique_books", function (qb) {
qb.select('*').from('books').where('published_date', '<', 1899);
}).select('*').from('antique_books');
var someExternalMethod: Function;
knex.transaction(function(trx) {