1.2.0 • Published 2 years ago

waterline-standalone-core v1.2.0

Weekly downloads
3
License
ISC
Repository
github
Last release
2 years ago

npm

Waterline Standalone Core

A waterline plugin for standalone usage. This plugin replicates waterline usage in sails by:

  • Allowing you to define waterline models exactly as in sails
  • Use any sails waterline adapter
  • Returns model collection that you can attach to your favorite framework

Usage

// Setup
const waterlineCore = require('waterline-standalone-core')

const options = {
 adapter: require('sails-mysql'),
 adapterType: 'mysql',
 database: {
   name: 'myDb',
   user: 'user',
   password: 'password',
   host: 'localhost'
 },
 modelPath: path.join(__dirname, './models'),
 modelDefaults: {
   datastore: 'default',
   fetchRecordsOnCreate: true,
   fetchRecordsOnUpdate: true,
   primaryKey: 'id',
   attributes: {
     createdAt: { type: 'string', autoCreatedAt: true, },
     updatedAt: { type: 'string', autoUpdatedAt: true, },
     id: { type: 'number', autoMigrations: { autoIncrement: true } },
   },
 }
}

const models = waterlineCore(options)

// Usage in handler
const pets = await models.pet.find()

Model definition

// ./model/Pet.js
module.exports = {
  identity: 'pet',
  attributes: {
    name: { type: 'string' },  
  }
}

Options

  • adapter: Any of sail's available adapters
  • adapterType: The name of adapter, example: 'mysql', 'sails-disk', etc
  • database:
    • name: The database name
    • user: The database user
    • password: The database password (optional)
    • host: The database host
    • port: The database port (optional)
  • modelPath: Path to the directory where your models are defined.
  • modelDefaults: Object. Any model settings that will apply to all models.
    • Great for setting default primaryKey, datastore, fetchRecordsOnUpdate, fetchRecordsOnCreate
    • Will be overridden by specific model settings

Contributing

Pull requests or issues welcome!

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

5 years ago

1.1.0-2

5 years ago

1.1.0-1

5 years ago

1.0.0

5 years ago

1.0.0-3

6 years ago

1.0.0-2

6 years ago

1.0.0-1

6 years ago