knex-schema
v2.2.1
Published
Knex schema utility.
Downloads
305
Readme
knex-schema
Knex sync utility.
Install
npm install knex-schema
Usage
var database = require('knex').initialize({ client: 'pg' });
var Manager = require('knex-schema');
var manager = new Manager(database);
var articles = {
tableName: 'articles',
build: function (table) {
table.increments('id').primary();
table.string('title');
},
populate: function (database) {
return db.knex('articles').insert([
{ title: 'First article' }
]);
}
};
manager.sync([articles]); // Create / Update tables articles.
manager.populate([articles]); // Populate table articles.
manager.reset([articles]); // Remove all data from articles.
manager.drop([articles]); // Drop table articles.
knexSchema(database)
Create a new manager.
var manager = require('knex-schema')(database);
manager.sync(schemas)
Create and update tables specified in schemas.
manager.sync([articles]);
manager.populate(schemas)
Populate tables specified in schemas.
manager.populate([articles]);
manager.reset(schemas)
Remove all rows in tables specified in schemas.
manager.reset([articles]);
manager.drop(schemas)
Drop tables specified in schemas.
manager.drop([articles]);
License
MIT