{"id":13609296,"url":"https://github.com/danecando/hapi-sequelize","last_synced_at":"2025-04-12T20:31:40.701Z","repository":{"id":20028980,"uuid":"23296976","full_name":"danecando/hapi-sequelize","owner":"danecando","description":"Hapi plugin for the Sequelize ORM","archived":true,"fork":false,"pushed_at":"2018-07-24T05:32:06.000Z","size":94,"stargazers_count":111,"open_issues_count":6,"forks_count":35,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T13:13:52.901Z","etag":null,"topics":["hapi-plugin","hapi-sequelize","javascript","sequelize-orm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danecando.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-25T00:26:53.000Z","updated_at":"2024-06-21T21:10:55.000Z","dependencies_parsed_at":"2022-07-23T14:32:22.274Z","dependency_job_id":null,"html_url":"https://github.com/danecando/hapi-sequelize","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danecando%2Fhapi-sequelize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danecando%2Fhapi-sequelize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danecando%2Fhapi-sequelize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danecando%2Fhapi-sequelize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danecando","download_url":"https://codeload.github.com/danecando/hapi-sequelize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248629609,"owners_count":21136281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hapi-plugin","hapi-sequelize","javascript","sequelize-orm"],"created_at":"2024-08-01T19:01:33.923Z","updated_at":"2025-04-12T20:31:40.418Z","avatar_url":"https://github.com/danecando.png","language":"JavaScript","readme":"## hapi-sequelize - a hapi plugin for the sequelize orm\n\n[![Build Status](https://travis-ci.org/danecando/hapi-sequelize.svg?branch=master)](https://travis-ci.org/danecando/hapi-sequelize)\n[![npm](https://img.shields.io/npm/dm/localeval.svg)](https://www.npmjs.com/package/hapi-sequelize)\n\n\n### Warning :warning:\n\nThis project is no longer actively maintained. The current version has been tested for versions of Hapi up to 13.x \u0026\nSequelize 3.x. It is known to be incompatible with versions of Hapi 17+ \u0026 Sequelize 4+. \n\nThere is a great fork of this project that has been in active development located at: https://github.com/valtlfelipe/hapi-sequelizejs\n \n### Installation\n\n`npm install --save hapi-sequelize`\n\n### Configuration\n\nSimply pass in your sequelize instance and a few basic options and voila. Options accepts a single object\n or an array for multiple dbs.\n\n```javascript\nserver.register([\n  {\n      register: require('hapi-sequelize'),\n      options: [ \n        {\n          name: 'dbname', // identifier\n          models: ['./server/models/**/*.js'],  // paths/globs to model files\n          sequelize: new Sequelize(config, opts), // sequelize instance\n          sync: true, // sync models - default false\n          forceSync: false, // force sync (drops tables) - default false\n          onConnect: function (database) { // Optional\n            // migrations, seeders, etc.\n          }\n        }\n      ]\n  }\n]);\n```\n\n### Database Instances\n\nEach registration adds a DB instance to the `server.plugins['hapi-sequelize']` object with the\nname option as the key.\n\n```javascript\nfunction DB(sequelize, models) {\n  this.sequelize = sequelize;\n  this.models = models;\n} \n\n// smth like this\nserver.plugins['hapi-sequelize'][opts.name] = new DB(opts.sequelize, models);\n```\n\n### Usage with Glue\n\nIf you use [Glue](https://github.com/hapijs/glue) to compose your server, you'll need to load ``hapi-sequelize`` like this;\n\n```javascript\nvar manifest = require('./config/manifest');\n\nmanifest.registrations.push({\n  \"plugin\": {\n    \"register\": \"hapi-sequelize\",\n    \"options\": {\n      \"name\": \"name\",\n      \"models\": 'models/models/*.js',\n      \"sequelize\": new Sequelize(config, opts),\n      \"sync\": true,\n      \"forceSync\": false // force sync (drops tables) - default false\n    }\n  }\n})\n\n// Load the manifest and start the server\n```\n\n### API\n\n#### `getDb(name)`\n\nThe request object gets decorated with the method `getDb`. This allows you to easily grab a\nDB instance in a route handler. If you have multiple registrations pass the name of the one\nyou would like returned or else the single or first registration will be returned.\n\n```javascript\nhandler(request, reply) {\n  const db1 = request.getDb('db1');\n  console.log(db1.sequelize);\n  console.log(db1.models);\n}\n```\n\n#### `db.getModel('User')`\n\nReturns single model that matches the passed argument or null if the model doesn't exist.\n\n#### `db.getModels()`\n\nReturns all models on the db instance\n\n### Contributing \n If you have any ideas for useful additions to the API or any other improvements to the plugin\n please open an issue or a PR. \n \n Also feel free to tackle any of the outstanding todo's in the issues. These are mostly currently\n for testing, documentation. I hope to at least provide a reliable, developer friendly plugin.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanecando%2Fhapi-sequelize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanecando%2Fhapi-sequelize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanecando%2Fhapi-sequelize/lists"}