{"id":13564161,"url":"https://github.com/d-band/koa-orm","last_synced_at":"2025-04-12T00:31:33.851Z","repository":{"id":57153368,"uuid":"52100210","full_name":"d-band/koa-orm","owner":"d-band","description":"koa orm using sequelize \u0026 sk2 (fork from knex)","archived":false,"fork":false,"pushed_at":"2020-12-04T08:17:35.000Z","size":80,"stargazers_count":62,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-28T03:17:11.690Z","etag":null,"topics":["koa-orm","koa2","koajs","orm","sequelize","sql","squel"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d-band.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-19T16:19:09.000Z","updated_at":"2021-12-22T06:18:59.000Z","dependencies_parsed_at":"2022-09-07T06:11:12.848Z","dependency_job_id":null,"html_url":"https://github.com/d-band/koa-orm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-band%2Fkoa-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-band%2Fkoa-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-band%2Fkoa-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-band%2Fkoa-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d-band","download_url":"https://codeload.github.com/d-band/koa-orm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501265,"owners_count":21114640,"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":["koa-orm","koa2","koajs","orm","sequelize","sql","squel"],"created_at":"2024-08-01T13:01:27.362Z","updated_at":"2025-04-12T00:31:33.625Z","avatar_url":"https://github.com/d-band.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","仓库"],"sub_categories":["中间件"],"readme":"# koa-orm\n\n[![NPM version](https://img.shields.io/npm/v/koa-orm.svg)](https://www.npmjs.com/package/koa-orm)\n[![NPM downloads](https://img.shields.io/npm/dm/koa-orm.svg)](https://www.npmjs.com/package/koa-orm)\n[![Dependency Status](https://david-dm.org/d-band/koa-orm.svg)](https://david-dm.org/d-band/koa-orm)\n[![Build Status](https://travis-ci.org/d-band/koa-orm.svg?branch=master)](https://travis-ci.org/d-band/koa-orm)\n[![Coverage Status](https://coveralls.io/repos/github/d-band/koa-orm/badge.svg?branch=master)](https://coveralls.io/github/d-band/koa-orm?branch=master)\n[![Greenkeeper badge](https://badges.greenkeeper.io/d-band/koa-orm.svg)](https://greenkeeper.io/)\n\n\u003e `koa-orm` using [sequelize](https://github.com/sequelize/sequelize) \u0026 [sk2](https://github.com/d-band/sk2).\n\n## Installation\n\n```bash\nnpm install koa-orm\n```\n\n## Example\n\nSingle database\n\n```js\nconst join = require('path').join;\nconst config = {\n  name: 'test',\n  modelPath: join(__dirname, 'models'),\n  database: 'orm_test',\n  username: 'root',\n  password: 'pass',\n  dialect: 'mysql',\n  host: '127.0.0.1',\n  port: 3306,\n  pool: {\n    max: 10,\n    min: 0,\n    idle: 30000\n  }\n};\n\nconst orm = require('koa-orm')(config);\n\napp.use(orm.middleware);\n\napp.use(async function (ctx) {\n  const raws = await ctx.orm().sql.select().from('table');\n  // const raws = await ctx.orm('test').sql('table').select();\n  ctx.body = raws;\n});\n```\n\nMultiple database\n\n```js\nconst join = require('path').join;\nconst configs = [{\n  name: 'user',\n  database: 'db_user',\n  username: 'root',\n  password: 'pass',\n  dialect: 'mysql',\n  host: '127.0.0.1',\n  port: 3306,\n  modelPath: join(__dirname, 'models/user')\n}, {\n  name: 'product',\n  database: 'db_product',\n  username: 'root',\n  password: 'pass',\n  dialect: 'mysql',\n  host: '127.0.0.1',\n  port: 3306,\n  modelPath: join(__dirname, 'models/product')\n}];\n\nconst orm = require('koa-orm')(configs);\n\napp.use(orm.middleware);\n\napp.use(async function (ctx) {\n  const { User } = ctx.orm('user');\n  const { Product } = ctx.orm('product');\n  const { userId } = ctx.params;\n  \n  const user = await User.findByPk(userId);\n  const products = await Product.findAll({\n    where: { userId }\n  });\n  ctx.body = { user, products };\n});\n```\n\n## API\n\n#### `orm(configs)`\n\n* `configs`: Multi database config array.\n\n## Koa 1 Support\n\nTo use `koa-orm` with koa@1, please use [koa-orm 1.x](https://github.com/d-band/koa-orm/tree/v1.x).\n\n```bash\nnpm install koa-orm@1 --save\n```\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-band%2Fkoa-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd-band%2Fkoa-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-band%2Fkoa-orm/lists"}