{"id":19020282,"url":"https://github.com/trailsjs/trailpack-sequelize","last_synced_at":"2025-04-23T05:45:36.705Z","repository":{"id":8372517,"uuid":"55338700","full_name":"trailsjs/trailpack-sequelize","owner":"trailsjs","description":":package: Sequelize.js Trailpack http://sequelizejs.com","archived":false,"fork":false,"pushed_at":"2022-08-30T22:50:06.000Z","size":342,"stargazers_count":5,"open_issues_count":21,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-23T05:45:30.129Z","etag":null,"topics":["sequelize","trailpack","trails"],"latest_commit_sha":null,"homepage":null,"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/trailsjs.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":"2016-04-03T09:20:34.000Z","updated_at":"2022-03-28T19:10:41.000Z","dependencies_parsed_at":"2022-08-07T04:16:25.479Z","dependency_job_id":null,"html_url":"https://github.com/trailsjs/trailpack-sequelize","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-sequelize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-sequelize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-sequelize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-sequelize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailsjs","download_url":"https://codeload.github.com/trailsjs/trailpack-sequelize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250379784,"owners_count":21420841,"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":["sequelize","trailpack","trails"],"created_at":"2024-11-08T20:16:27.260Z","updated_at":"2025-04-23T05:45:36.683Z","avatar_url":"https://github.com/trailsjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trailpack-sequelize\n:package: Sequelize.js Trailpack http://sequelizejs.com\n\n[![Gitter][gitter-image]][gitter-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![NPM version][npm-image]][npm-url]\n[![Build status][ci-image]][ci-url]\n[![Dependency Status][daviddm-image]][daviddm-url]\n[![Code Climate][codeclimate-image]][codeclimate-url]\n\n\nLoads Application Models (in `api/models`) into the Sequelize ORM; Integrates with [trailpack-router](https://github.com/trailsjs/trailpack-router) to\ngenerate Footprints for routes.\n\n## Usage\n\n### Configure\n\n```js\n// config/main.js\nmodule.exports = {\n  // ...\n  packs: [\n    require('trailpack-sequelize')\n  ]\n}\n```\n\nA basic `config/database.js` can be found here : https://github.com/trailsjs/trailpack-sequelize/blob/master/archetype/config/database.js\n\n### Models\n\n```js\nmodule.exports = class User extends Model {\n  //More about supported schema here : http://docs.sequelizejs.com/en/latest/docs/models-definition/\n  static schema (app, Sequelize) {\n    return {\n       name: { type: Sequelize.STRING, allowNull: false },\n       password: Sequelize.STRING,\n       displayName: Sequelize.STRING\n     }\n  }\n\n  static config (app, Sequelize) {\n    return {\n       migrate: 'drop', //override default models configurations if needed\n       store: 'sqlite', //override default models configurations if needed\n       //More informations about supported models options here : http://docs.sequelizejs.com/en/latest/docs/models-definition/#configuration\n       options: {\n         classMethods: {\n           //If you need associations, put them here\n           associate: (models) =\u003e {\n             //More information about associations here : http://docs.sequelizejs.com/en/latest/docs/associations/\n             models.User.hasMany(models.Role, {\n               as: 'roles',\n               onDelete: 'CASCADE',\n               foreignKey: {\n                 allowNull: true\n               }\n             })\n           }\n         }\n       }\n     }\n  }\n}\n```\n\n### Query\n\n```js\n// api/services/UserService.js\nmodule.exports = class UserService extends Service {\n  /**\n   * Finds people with the given email.\n   * @return Promise\n   * @example {\n   *    name: 'Ludwig Beethoven',\n   *    email: 'someemail@email.com',\n   *    favoriteColors: [\n   *      { name: 'yellow', hex: 'ffff00' },\n   *      { name: 'black', hex: '000000' }\n   *     ]\n   * }\n   */\n  findUser (email) {\n    //More info about queries here : http://docs.sequelizejs.com/en/latest/docs/models-usage/\n    return this.app.orm.User.find({ where: {email: email} })\n  }\n}\n```\nFor more informations about sequelize queries, please look at [the official documentation](http://docs.sequelizejs.com/en/latest/docs/querying/)\n\n## Footprints query options\nSome options can be provide as query param for the `find` method, example `GET /api/v1/user`.\n\n### Populate \nYou can add `/api/v1/user?populate=all` to populate all associations or use `/api/v1/user?populate=field1,field2` to populate only some association.\n\n### Pagination\nBy settings `offset` and `limit` you can do some pagination, example `/api/v1/user?offset=10\u0026limit=10` will return only 10 items started from 10 (id 10 to 20). \n\n## Contributing\nWe love contributions! Please check out our [Contributor's Guide](https://github.com/trailsjs/trails/blob/master/CONTRIBUTING.md) for more\ninformation on how our projects are organized and how to get started.\n\n\n## License\n[MIT](https://github.com/trailsjs/trailpack-sequelize/blob/master/LICENSE)\n\n## Changelog\n[Changelog](https://github.com/trailsjs/trailpack-sequelize/blob/master/CHANGELOG.md)\n\n[snyk-image]: https://snyk.io/test/github/trailsjs/trailpack-sequelize/badge.svg\n[snyk-url]: https://snyk.io/test/github/trailsjs/trailpack-sequelize\n[npm-image]: https://img.shields.io/npm/v/trailpack-sequelize.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/trailpack-sequelize\n[ci-image]: https://img.shields.io/travis/trailsjs/trailpack-sequelize/master.svg?style=flat-square\n[ci-url]: https://travis-ci.org/trailsjs/trailpack-sequelize\n[daviddm-image]: http://img.shields.io/david/trailsjs/trailpack-sequelize.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/trailsjs/trailpack-sequelize\n[codeclimate-image]: https://img.shields.io/codeclimate/github/trailsjs/trailpack-sequelize.svg?style=flat-square\n[codeclimate-url]: https://codeclimate.com/github/trailsjs/trailpack-sequelize\n[gitter-image]: http://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square\n[gitter-url]: https://gitter.im/trailsjs/trails\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrailpack-sequelize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailsjs%2Ftrailpack-sequelize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrailpack-sequelize/lists"}