mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
knex: added declarations for with(), withRaw() and withWrapped() (#15966)
Add an optional extended description…
This commit is contained in:
committed by
Sheetal Nandi
parent
fac0ab9e37
commit
86d6ae08ba
Vendored
+17
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user