Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tswayne/hapi-water
Hapi waterline plugin
https://github.com/tswayne/hapi-water
Last synced: about 1 month ago
JSON representation
Hapi waterline plugin
- Host: GitHub
- URL: https://github.com/tswayne/hapi-water
- Owner: tswayne
- Created: 2018-01-21T20:19:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-10T23:13:24.000Z (over 3 years ago)
- Last Synced: 2024-09-14T11:05:01.876Z (2 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[![npm](https://img.shields.io/npm/v/hapi-water.svg)](https://www.npmjs.com/package/hapi-water)
# Hapi Water
A hapi plugin for [waterline](https://github.com/balderdashy/waterline). This plugin replicates waterline usage in sails by:
* Allowing you to define waterline models exactly as in sails
* Use any sails waterline adapter
* Gives you access to your models anywhere in the request cycle through the request toolkit (`h.modelName._`)## Usage
```
// Setup
const hapiWater = require('hapi-water')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 } },
},
}
}await server.register({ plugin: hapiWater, options }, { once: true })
// Usage in handler
const pets = await h.models.pet.find()
```#### Model definition
```
// ./model/Pet.js
module.exports = {
identity: 'pet',
attributes: {
name: { type: 'string' },
}
}
```## Options
* adapter: Any of sail's [available adapters](https://next.sailsjs.com/documentation/concepts/extending-sails/adapters/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](https://sailsjs.com/documentation/concepts/models-and-orm/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!