Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Created October 25, 2014 13:10
Show Gist options
  • Select an option

  • Save bendrucker/c63ebaff3c9ed5c8f56c to your computer and use it in GitHub Desktop.

Select an option

Save bendrucker/c63ebaff3c9ed5c8f56c to your computer and use it in GitHub Desktop.
Failure to reproduce knex/knex#541
'use strict';
var sqlite = {
client: 'sqlite',
connection: {
filename: ':memory:'
}
};
var mysql = {
client: 'mysql',
connection: {
database: 'knex_issue_541',
user: 'root'
}
};
var Promise = require('bluebird');
var knex = require('knex')(process.env.USE_MYSQL ? mysql : sqlite);
knex.schema
.createTable('category', function (t) {
t.increments('id');
t.text('name');
})
.createTable('books', function (t) {
t.increments('id');
})
.then(function () {
return knex.transaction(function (trx) {
return trx
.insert({
name: 'category1'
}, 'id')
.into('category')
.then(function (ids) {
return trx
.insert({item2: 'second' + ids[0] })
.into('books');
});
})
})
.then(function (inserts) {
console.log('books saved.'); // Only gets to here if both are inserted
})
.catch(function (error) {
console.error('Error', error); // If it gets here, neither are inserted
return Promise.join(knex('category').select(), knex('books').select(), function (categories, books) {
console.log('categories', categories);
console.log('books', books);
});
})
.then(function () {
// continue doing things either way
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment