Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. var connect = require('connect');
  2. var serveStatic = require('serve-static');
  3. connect().use(serveStatic(__dirname)).listen(3030);
  4.  
  5. var knex = require('./lib/index')({
  6. dialect: 'firebird',
  7. connection: {
  8. host : '127.0.0.1',
  9. user : 'SYSDBA',
  10. password : 'masterkey',
  11. database : 'D:/data/lnag/SIE.FDB'
  12. }
  13. });
  14. /**
  15. *
  16. options.host = '127.0.0.1';
  17. options.port = 3050;
  18. options.database = 'database.fdb';
  19. options.user = 'SYSDBA';
  20. options.password = 'masterkey';
  21. */
  22.  
  23. // Create a table
  24. knex.schema
  25. .dropTableIfExists('accounts')
  26. .dropTableIfExists('users')
  27. .createTable('users', function(table) {
  28. table.increments('id');
  29. table.string('user_name');
  30. })
  31.  
  32. // ...and another
  33. .createTable('accounts', function(table) {
  34. table.increments('id');
  35. table.string('account_name');
  36. table.integer('user_id').references('users.id');
  37. })
  38.  
  39. // Then query the table...
  40. .then(function() {
  41. return knex.insert({user_name: 'Tim', id: 1}).into('users');
  42. })
  43.  
  44. // ...and using the insert id, insert into the other table.
  45. .then(function(rows) {
  46. return knex.table('accounts').insert({account_name: 'knex', user_id: rows[0]});
  47. })
  48.  
  49. // Query both of the rows.
  50. .then(function() {
  51. return knex('users')
  52. .join('accounts', 'users.id', 'accounts.user_id')
  53. .select('users.user_name as user', 'accounts.account_name as account');
  54. })
  55.  
  56. // .map over the results
  57. .map(function(row) {
  58. console.log(row);
  59. })
  60.  
  61. // Finally, add a .catch handler for the promise chain
  62. .catch(function(e) {
  63. console.error(e);
  64. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement