Skip to content

Basic Example

Branden Horiuchi edited this page Jul 6, 2015 · 1 revision

Basic Example


var schemer = require('knex-schemer')(knex);
var c       = schemer.constants;

// schema definition
var schema = {
  user: {
    id: {type: c.type.integer, primary: true, increments: true},
    name: {type: c.type.string, size: 255},
    username: {type: c.type.string, size: 100},
    email: {type: c.type.string, size: 200}
  },
  credential: {
    id: {type: c.type.integer, primary: true, increments: true},
    name: {type: c.type.string, size: 255},
    username: {type: c.type.string, size: 100},
    encryptedKey: {type: c.type.string, size: 255}
  }
};


// drop all tables
schemer.drop(schema).then(function() {
    // post drop actions
});

// create or update all tables
schemer.sync(schema).then(function() {
    // post sync actions
});