Merge pull request #8777 from ryansmith94/patch-1

Fixes Knex for ES6.
This commit is contained in:
Horiuchi_H 2016-04-01 16:44:43 +09:00
commit 9c96b335e7
2 changed files with 24 additions and 23 deletions

View File

@ -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)

6
knex/knex.d.ts vendored
View File

@ -3,12 +3,12 @@
// Definitions by: Qubo <https://github.com/tkQubo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../bluebird/bluebird.d.ts" />
// <reference path="../bluebird/bluebird.d.ts" />
/// <reference path="../node/node.d.ts" />
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;