diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index 4078522df2..e983ec1084 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -329,11 +329,11 @@ knex.transaction(function(trx) { .insert({name: 'Old Books'}, 'id') .into('catalogues') .then(function(ids) { - return Promise.map(books, function(book) { + return Promise.all(books.map(function (book: any) { book.catalogue_id = ids[0]; // Some validation could take place here. return trx.insert(info).into('books'); - }); + })); }); }) .then(function(inserts) { @@ -359,13 +359,13 @@ knex.transaction(function(trx) { .into('catalogues') .transacting(trx) .then(function(ids) { - return Promise.map(books, function(book) { + return Promise.all(books.map(function(book: any) { book.catalogue_id = ids[0]; // Some validation could take place here. return knex.insert(info).into('books').transacting(trx); - }); + })); }) .then(trx.commit) .catch(trx.rollback); @@ -495,39 +495,40 @@ query.then(function(x: any) { return x; }); -knex.select('name').from('users').limit(10).map(function(row: any) { - return row.name; -}).then(function(names) { +knex.select('name').from('users').limit(10).then(function (rows: any[]): string[] { + return rows.map(function (row: any): string { + return row.name; + }); +}).then(function(names: string[]) { console.log(names); -}).catch(function(e) { +}).catch(function(e: Error) { console.error(e); }); -knex.select('name').from('users').limit(10).reduce(function(memo: any, row: any) { - memo.names.push(row.name); - memo.count++; - return memo; -}, {count: 0, names: []}).then(function(obj) { +knex.select('name').from('users').limit(10).then(function (rows: any[]) { + return rows.reduce(function(memo: any, row: any) { + memo.names.push(row.name); + memo.count++; + return memo; + }, {count: 0, names: []}) +}).then(function(obj: any) { console.log(obj); -}).catch(function(e) { +}).catch(function(e: Error) { console.error(e); }); knex.select('name').from('users') .limit(10) - .bind(console) - .then(console.log) - .catch(console.error); + .then(console.log.bind(console)) + .catch(console.error.bind(console)); var values: any[]; -// Without return: + knex.insert(values).into('users') .then(function() { return {inserted: true}; }); -knex.insert(values).into('users').return({inserted: true}); - knex.select('name').from('users') .where('id', '>', 20) .andWhere('id', '<', 200) diff --git a/knex/knex.d.ts b/knex/knex.d.ts index 6f28a2f796..52740662c8 100644 --- a/knex/knex.d.ts +++ b/knex/knex.d.ts @@ -3,12 +3,12 @@ // Definitions by: Qubo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +// /// declare module "knex" { - import Promise = require("bluebird"); - import events = require("events"); + // import Promise = require("bluebird"); + import * as events from "events"; type Callback = Function; type Client = Function;