Skip to content

mickelindahl/waterline-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Waterline table

Library for creating and dropping tables using sails and waterline. I created this library because when using waterline 0.13.1-9 together with sails-postgresql the tables were not automatically created at orm initialization. The library takes care of converting the model into a database definition that can be used to create a table. That includes making sure autoMigrations is put onto definition, primaryKey is set and columnType is defined if not included in autoMigrations. Hopefully future releases of waterline will take care of this.

Install

npm install --save waterline-table

Usage

    const wt = require('waterline-table');
    const Waterline=require('waterline');

    const orm = new Waterline();

    let model = {
        identity: 'test',
        attributes: {
            id: {type: 'number', autoMigrations: {autoIncrement: true, columnType: 'INTEGER'}},
            expired_at: {type: 'ref', autoMigrations: {columnType: 'TIMESTAMP'}},
            text: {type: 'string'},
        },
        primaryKey: 'id'
    };
    
    orm.registerModel(Waterline.Collection.extend(model));

    const datastores = {
            default: {
                adapter: 'myAdapter',
            }
        };
    
    const adapters = {
        myAdapter: require('sails-disk')
    };
    
    let config = {
        adapters: adapters,
        datastores: datastores
    };
    
    orm.initialize(config, function (err, data) {
            if (err) throw err;

            let options = result.data;
            options.table = 'test';

            wt.create(options)

        })

API

waterline-table

waterline-table~create()

Create a table in db

  • options {object}
    • collections {object} Waterline collections
    • datastore {object} Waterline datastores
    • table {string} Name of table to create

returns {Promise}

Kind: inner method of waterline-table

waterline-table~createAll()

Create all tables in db

  • options {object}
    • collections {object} Waterline collections
    • datastore {object} Waterline datastores

returns {Promise}

Kind: inner method of waterline-table

waterline-table~drop()

Drop a table in db

  • options {object}
    • collections {object} Waterline collections
    • datastore {object} Waterline datastores
    • table {string} Name of table to drop

returns {Promise}

Kind: inner method of waterline-table

waterline-table~dropAll()

Drop all tables in db

  • options {object}
    • collections {object} Waterline collections
    • datastore {object} Waterline datastores

returns {Promise}

Kind: inner method of waterline-table

Tests

npm test

Contributing

Feel free to submit issues and pull request on bugs or feature request.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

About

Library for creating and dropping tables using sails and waterline

Resources

Stars

Watchers

Forks

Packages

No packages published