{"id":19020239,"url":"https://github.com/trailsjs/trailpack-knex","last_synced_at":"2025-04-23T05:27:07.543Z","repository":{"id":57378891,"uuid":"50170051","full_name":"trailsjs/trailpack-knex","owner":"trailsjs","description":":package: Knex.js Trailpack","archived":false,"fork":false,"pushed_at":"2017-11-20T21:50:26.000Z","size":59,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-24T21:20:47.761Z","etag":null,"topics":["knex","knexjs","orm","trailpack","trails"],"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/trailsjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-01-22T09:02:25.000Z","updated_at":"2023-11-03T17:12:10.000Z","dependencies_parsed_at":"2022-09-26T16:41:32.939Z","dependency_job_id":null,"html_url":"https://github.com/trailsjs/trailpack-knex","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-knex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-knex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-knex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-knex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailsjs","download_url":"https://codeload.github.com/trailsjs/trailpack-knex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223746909,"owners_count":17195810,"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":["knex","knexjs","orm","trailpack","trails"],"created_at":"2024-11-08T20:16:14.904Z","updated_at":"2024-11-08T20:16:15.590Z","avatar_url":"https://github.com/trailsjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trailpack-knex\n\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\nProvides support for database queries and schema migrations via [knex.js](http://knexjs.org/).\n\n## Install\n\n```sh\n$ npm install --save trailpack-knex\n```\n\n## Configure\n\n#### `main.js`\n\n```js\n// config/main.js\nmodule.exports = {\n  packs: [\n    // ... other trailpacks\n    require('trailpack-knex')\n  ]\n}\n```\n\n#### `database.js`\n\n```js\n// config/database.js\nmodule.exports = {\n  stores: {\n    knexPostgres: {\n      client: 'pg',\n\n      /**\n       * knex connection object\n       * see: http://knexjs.org/#Installation-client\n       */\n      connection: {\n        host: 'localhost',\n        user: 'admin',\n        password: '1234',\n        database: 'mydb'\n      }\n    }\n  },\n\n  /**\n   * Supported Migrate Settings:\n   * - drop\n   * - create\n   */\n  migrate: 'create',\n  defaultStore: 'knexPostgres'\n}\n```\n\n## Usage\n\n### Models\n\n```js\n// api/models/User.js\nclass User extends Model {\n  static schema (table) {\n    table.increments('id').primary()\n    table.string('username')\n    table.string('firstName')\n    table.string('lastName')\n  }\n}\n\n// api/models/Role.js\nclass Role extends Model {\n  static schema (table) {\n    table.increments('id').primary()\n    table.string('name')\n    table.integer('user_id').references('user.id')\n  }\n}\n```\n\n### Services\n\n#### `SchemaMigrationService`\n\n##### `create`\nCreate the schema using knex\n\n##### `drop`\nDrop the schema using knex\n\n##### `alter`\nNot currently supported.\n\n## Contributing\nWe love contributions! Please check out our [Contributor's Guide](https://github.com/trailsjs/trails/blob/master/.github/CONTRIBUTING.md) for more\ninformation on how our projects are organized and how to get started.\n\n## License\n[MIT](https://github.com/trailsjs/trails/blob/master/LICENSE)\n\n\u003cimg src=\"http://i.imgur.com/dCjNisP.png\"\u003e\n\n[npm-image]: https://img.shields.io/npm/v/trailpack-knex.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/trailpack-knex\n[ci-image]: https://img.shields.io/travis/trailsjs/trailpack-knex/master.svg?style=flat-square\n[ci-url]: https://travis-ci.org/trailsjs/trailpack-knex\n[daviddm-image]: http://img.shields.io/david/trailsjs/trailpack-knex.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/trailsjs/trailpack-knex\n[codeclimate-image]: https://img.shields.io/codeclimate/github/trailsjs/trailpack-knex.svg?style=flat-square\n[codeclimate-url]: https://codeclimate.com/github/trailsjs/trailpack-knex\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrailpack-knex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailsjs%2Ftrailpack-knex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrailpack-knex/lists"}