k7-sequelize
k7 adapter for sequelize ORM
K7-Sequelize is an Adapter for using Sequelize (SQL ORM) in Hapi by K7 connector
Usage
For example:
const Hapi = ;const Server = ; Server; let options = adapter: connectionString: 'postgresql://k7:k7@localhost:5432/K7Sequelize'; Server;
This example does:
- Setting the k7-sequelize adapter
- Setting the connectionString for sequelize connect (postgre)
- Register the k7 to Hapi.js
Options
All the options available in Sequelize can be setted in connectionOptions
. You can see more about that in tests.
Models
For defining your models you will need folowing this example:
module { return sequelize;};
About Migrations
When you want to run migrations with sequelize, we strong recomend using Umzug and you can do that like this:
const Umzug = ;const K7Sequelize = ;const k7 = ;const Sequelize = k7dbSequelize; const config = username: processenvDB_USERNAME || 'postgres' password: processenvDB_PASSWORD || 'postgres' database: processenvDB_NAME || 'cart' host: processenvDB_HOST || '127.0.0.1' port: processenvDB_PORT || 5432 dialect: processenvDB_DIALECT || 'postgres'; const sequelize = configdatabase configusername configpassword config; let db = sequelize Sequelize;// Instantiate Umzuglet options = storage: 'sequelize' storageOptions: sequelize: sequelize modelName: 'MigrationSchema' tableName: 'migration_table' logging: false // TODO: Create new logger to migration function receive a message parameter. upName: 'up' downName: 'down' migrations: params: db path: 'migrations' pattern: /$/ ; const umzug = options; const type = processargv2;; { type = type === 'down' ? 'down' : 'up'; return umzugtype ;}
This is required, because when the load
function will try to require the Models the instance of Sequelize will be injected in your models.
Examples
You can see k7 and k7-sequelize in action in the repo: Cart.
Testing
For testing you just need clone this repo and run npm install && npm test
inside root folder of this project.;