Created
December 23, 2015 17:53
-
-
Save FraGoTe/e66ebdd7296a9b84840b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var knex = require('./lib/index')({ | |
dialect: 'firebird', | |
connection: { | |
host : '127.0.0.1', | |
user : 'SYSDBA', | |
password : 'masterkey', | |
database : 'D:/data/lnag/SIE.FDB' | |
} | |
}); | |
/** | |
* | |
options.host = '127.0.0.1'; | |
options.port = 3050; | |
options.database = 'database.fdb'; | |
options.user = 'SYSDBA'; | |
options.password = 'masterkey'; | |
*/ | |
// Create a table | |
knex.schema | |
.dropTableIfExists('accounts') | |
.dropTableIfExists('users') | |
.createTable('users', function(table) { | |
table.increments('id'); | |
table.string('user_name'); | |
}) | |
// ...and another | |
.createTable('accounts', function(table) { | |
table.increments('id'); | |
table.string('account_name'); | |
table.integer('user_id').references('users.id'); | |
}) | |
// Then query the table... | |
.then(function() { | |
return knex.insert({user_name: 'Tim', id: 1}).into('users'); | |
}) | |
// ...and using the insert id, insert into the other table. | |
.then(function(rows) { | |
return knex.table('accounts').insert({account_name: 'knex', user_id: rows[0], id: 1}); | |
}) | |
// Query both of the rows. | |
.then(function() { | |
return knex('users') | |
.join('accounts', 'users.id', 'accounts.user_id') | |
.select('users.user_name as users', 'accounts.account_name as account'); | |
}) | |
// .map over the results | |
.map(function(row) { | |
console.log('MAPP'); | |
console.log(row); | |
}) | |
// Finally, add a .catch handler for the promise chain | |
.catch(function(e) { | |
console.log('ERRORRRR'); | |
console.error(e); | |
}); | |
console.log('knex finishhh'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment