Prototype of Data Access Layer using sequelizejs (with Hapi.js plugins)
Install PostgreSQL server. All raw queries are hardcoded into source code and all *.sql files in postgres
dialect.
$ npm install
Edit file dsn.json
and provide of details for successfully connecting to your database.
This DAL implementation contains script that synchronizes all sql files in dal/sql/tables
directory.
The idea is that in this directory you keep all your tables definitions in actual state.
When running syncdb
task, all sql statements in these files are executed against the database defined in dsn.json
.
Since sequelize migrations doesn't provide us with mechanism for faking migrations the final part of syncdb
process is faking the application of all the migrations. The reason why we do that is that we don't
want to apply any migrations in a pristine up-to-date database in new project installations.
$ npm run syncdb
We run migrations only on project instances that got updated or redeployed. Migrations are introducing progressive structural enhancements on your schema or migrate data in your tables. You usually want to run migrations before your projects backend starts.
$ npm run migrate
In order to be sure your project is running on up-to-date schema, run migrations before your server starts.
$ npm run migrate && node index.js
All examples of using this DAL are provided in index.js
file located at the root of this repository.
Feel free to prototype your own examples and use-cases in this file and if you feel like it, provide a pull request.
You can run this file by two commands:
$ node index.js
or
$ npm run test
Credits to @kkristal for finalizing this dal design.