{"id":13487550,"url":"https://github.com/eggjs/egg-orm","last_synced_at":"2025-10-14T14:17:24.981Z","repository":{"id":42154970,"uuid":"233802796","full_name":"eggjs/egg-orm","owner":"eggjs","description":"Object relational mapping for Egg framework","archived":false,"fork":false,"pushed_at":"2024-04-15T06:18:29.000Z","size":83,"stargazers_count":49,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-21T19:29:42.816Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://leoric.js.org/setup/egg","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/eggjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-14T09:19:23.000Z","updated_at":"2024-03-09T09:20:17.000Z","dependencies_parsed_at":"2023-12-21T13:35:01.806Z","dependency_job_id":"84792f43-0489-46cc-a7f2-6671a93c2009","html_url":"https://github.com/eggjs/egg-orm","commit_stats":{"total_commits":51,"total_committers":10,"mean_commits":5.1,"dds":0.4509803921568627,"last_synced_commit":"32c4f87a5fe6cbaa2dc509dab6652949d4ad700d"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-orm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-orm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-orm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018762,"owners_count":26086576,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-07-31T18:01:00.534Z","updated_at":"2025-10-14T14:17:24.949Z","avatar_url":"https://github.com/eggjs.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["插件"],"readme":"# egg-orm\n\n[中文介绍](Readme.zh-CN.md)\n\nYet another object-relational mapping plugin for Egg, which is based on [Leoric](https://leoric.js.org).\n\n## Install\n\n```bash\n$ npm i --save egg-orm\n$ npm install --save mysql    # MySQL or compatible dialects\n\n# Or use other database backend.\n$ npm install --save pg       # PostgreSQL\n$ npm install --save sqlite3  # SQLite\n```\n\n## Usage\n\nWith egg-orm you can define models in `app/model` in JavaScript:\n\n```js\n// app/model/user.js\nmodule.exports = function(app) {\n  const { Bone, DataTypes: { STRING } } = app.model;\n\n  return class User extends Bone {\n    static table = 'users'\n\n    static attributes = {\n      name: STRING,\n      password: STRING,\n      avatar: STRING(2048),\n    }\n  });\n}\n```\n\nor in TypeScript:\n\n```ts\n// app/model/post.ts\nimport { Column, Bone, BelongsTo, DataTypes } from 'egg-orm';\nimport User from './user';\n\nexport default class Post extends Bone {\n  @Column({ primaryKey: true })\n  id: bigint;\n\n  @Column(DataTypes.TEXT)\n  content: string;\n\n  @Column()\n  description: string;\n\n  @Column()\n  userId: bigint;\n\n  @BelongsTo()\n  user: User;\n}\n\n// app/model/user.ts\nimport { Column, Bone, HasMany } from 'egg-orm';\nimport Post from './post';\n\nexport default class User extends Bone {\n  @Column({ allowNull: false })\n  nickname: string;\n\n  @Column()\n  email: string;\n\n  @Column()\n  createdAt: Date;\n\n  @HasMany()\n  posts: Post[];\n}\n\n```\n\nand use them like below:\n\n```js\n// app/controller/home.js\nconst { Controller } = require('egg');\nmodule.exports = class HomeController extends Controller {\n  async index() {\n    const users = await ctx.model.User.find({\n      corpId: ctx.model.Corp.findOne({ name: 'tyrael' }),\n    });\n    ctx.body = users;\n  }\n};\n```\n\n## Configuration\n\nFirstly, enable egg-orm plugin:\n\n```js\n// config/plugin.js\nexports.orm = {\n  enable: true,\n  package: 'egg-orm',\n};\n```\n\nSecondly, configure the plugin accordingly:\n\n```js\n// config/config.default.js\nexports.orm = {\n  client: 'mysql',\n  database: 'temp',\n  host: 'localhost',\n  baseDir: 'model',\n};\n```\n\nIn this example above, we're accessing the `temp` database of MySQL via `localhost` with the models defined in directory `app/model`. For more information, please refer to [Setup Leoric in Egg](https://leoric.js.org/setup/egg).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-orm/lists"}