{"id":17227033,"url":"https://github.com/paranoidjk/orm-ts","last_synced_at":"2025-07-06T00:35:24.359Z","repository":{"id":82690059,"uuid":"126292611","full_name":"paranoidjk/orm-ts","owner":"paranoidjk","description":null,"archived":false,"fork":false,"pushed_at":"2018-03-22T06:55:14.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T17:51:15.758Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"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/paranoidjk.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-22T06:54:39.000Z","updated_at":"2023-03-04T06:04:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"1adefd82-679e-406d-9249-5a0b7ca0f964","html_url":"https://github.com/paranoidjk/orm-ts","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/paranoidjk/orm-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paranoidjk%2Form-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paranoidjk%2Form-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paranoidjk%2Form-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paranoidjk%2Form-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paranoidjk","download_url":"https://codeload.github.com/paranoidjk/orm-ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paranoidjk%2Form-ts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263832178,"owners_count":23517347,"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":[],"created_at":"2024-10-15T04:17:55.987Z","updated_at":"2025-07-06T00:35:24.295Z","avatar_url":"https://github.com/paranoidjk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# orm-ts\n\n[![CI](https://img.shields.io/travis/zhang740/orm-ts.svg?style=flat-square)](https://travis-ci.org/zhang740/orm-ts)\n[![Coverage](https://img.shields.io/coveralls/zhang740/orm-ts.svg?style=flat-square)](https://coveralls.io/github/zhang740/orm-ts)\n[![Version](https://img.shields.io/npm/v/orm-ts.svg?style=flat-square)](https://www.npmjs.com/package/orm-ts)\n[![License](https://img.shields.io/npm/l/orm-ts.svg?style=flat-square)](https://github.com/zhang740/orm-ts/blob/master/LICENSE)\n\n\n## Install\n```shell\nnpm i orm-ts --save\n```\n\n## Example\n\n### a simple example\nservice:\n```ts\n@register()\nexport class ActivityService {\n  @lazyInject()\n  private acitvityDomain: ActivityDomain;\n\n  async getById(id: number) {\n    return await this.acitvityDomain.getById(id);\n  }\n}\n```\n\ndomain:\n```ts\n@register()\nexport class ActivityDomain extends BaseDomain {\n  @lazyInject()\n  repository: ActivityRepository;\n\n  async getById(id: number) {\n    return await this.repository.getById(id);\n  }\n}\n```\n\nrepository:\n```ts\n@repository(ActivityModel)\nexport class ActivityRepository extends BaseRepository\u003cActivityModel\u003e {\n}\n\n@repository(UserModel)\nexport class UserRepository extends BaseRepository\u003cUserModel\u003e {\n\n  @cachePut((username: string) =\u003e `user_${username}`, { expiredTime: 30 * 60 })\n  @bindSql(`select * from #table# where username = #username#`, { page: false })\n  async getByUsername(username: string) {\n    // SQL\n    return new UserModel(this.queryOne(`\n        xxxxxxxx\n    `, arguments));\n  }\n\n  async add(model: UserModel) { }\n\n  @cacheEvict((username: string) =\u003e `user_${username}`)\n  async updateByUsername(username: string, model: UserModel) { }\n\n  @cacheEvict((username: string) =\u003e `user_${username}`)\n  async deleteByUsername(username: string) { }\n}\n```\n\ndomain:\n```ts\nexport class ActivityModel extends BaseModel {\n  id: number;\n\n  @manyToOne('owner', UserModel, 'getByUsername')\n  user: Promise\u003cUserModel\u003e;\n\n  @manyToOne('teamId', TeamModel)\n  team: Promise\u003cTeamModel\u003e;\n}\n\nexport class UserModel extends BaseModel {\n  id: number;\n\n  @valid([\n    { minLength: 10 },\n    { custom: (str: string) =\u003e true, errorMsg: 'xxx' }\n  ])\n  username: string;\n}\n```\n\n\n#### [See the full example.](https://github.com/zhang740/orm-ts/tree/master/example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparanoidjk%2Form-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparanoidjk%2Form-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparanoidjk%2Form-ts/lists"}