Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 6th, 2018 53 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. var assert = require('assert');
  2. var knex = require('knex')({
  3.     client: 'sqlite3',
  4.     connection: {filename: ':memory:'}
  5. });
  6. var bookshelf = require('bookshelf')(knex);
  7. var User = bookshelf.Model.extend({
  8.     tableName: 'users',
  9.     initialize: function () {
  10.         this.on('updated', function (user) {
  11.             console.log('prev attrs on updated', user.previousAttributes());
  12.         });
  13.     }
  14. });
  15.  
  16. var Users = bookshelf.Collection.extend({
  17.     model: User
  18. });
  19.  
  20. return knex.schema.createTable('users', function (table) {
  21.     table.increments();
  22.     table.text('status').notNullable();
  23.     table.text('name').notNullable();
  24. }).then(function () {
  25.     return knex('users').insert({status: 'active', name: 'ralf'});
  26. }).then(function () {
  27.     return new User({id: 1}).fetch();
  28. }).then(function (user) {
  29.     assert.strictEqual(user.get('status'), 'active');
  30.     user.set('status', 'active');
  31.     return user.save();
  32. }).then(function () {
  33.     console.log('all done model');
  34.  
  35.     return Users.forge({id: 1}).fetch();
  36. }).then(function (users) {
  37.     console.log('prev attrs on collection fetch', users.models[0].previousAttributes());
  38. }).catch(function (err) {
  39.     console.log(err);
  40.     console.log(err.stack);
  41. }).finally(function () {
  42.     process.exit();
  43. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top