Advertisement
Guest User

Example

a guest
Nov 15th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Knex = require('knex');
  2. const Bookshelf = require('bookshelf');
  3.  
  4. const knex = Knex({
  5.     client: 'postgresql',
  6.     connection: {
  7.         host: 'localhost',
  8.         port: '5436',
  9.         user: 'test',
  10.         password: 'test',
  11.         database: 'test',
  12.         charset: 'utf8'
  13.     },
  14. });
  15.  
  16. const bookshelf = Bookshelf(knex);
  17. const Test = bookshelf.Model.extend({
  18.     tableName: 'test',
  19.     hasTimestamps: true
  20. });
  21.  
  22. knex.schema.createTableIfNotExists('test', (table) => {
  23.     table.increments('id').primary();
  24.     table.float('amount');
  25.     table.timestamps();
  26. }).then(() => {
  27.     new Test({amount: 1234567})
  28.         .save()
  29.         .then((model) => model.fetchAll()
  30.             .then((result) => console.log(result.toJSON())));
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement