Socket
Socket
Sign inDemoInstall

orm-ts

Package Overview
Dependencies
8
Maintainers
3
Versions
132
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    orm-ts

orm


Version published
Weekly downloads
37
increased by94.74%
Maintainers
3
Install size
1.19 MB
Created
Weekly downloads
 

Readme

Source

orm-ts

CI Coverage Version License

Install

npm i orm-ts --save

Example

a simple example

service:

@register()
export class ActivityService {
  @lazyInject()
  private acitvityDomain: ActivityDomain;

  async getById(id: number) {
    return this.acitvityDomain.getById(id);
  }
}

domain:

@register()
export class ActivityDomain extends BaseDomain {
  @lazyInject()
  repository: ActivityRepository;

  async getById(id: number) {
    return this.repository.getById(id);
  }
}

repository:

@repository(ActivityModel)
export class ActivityRepository extends BaseRepository<ActivityModel> {
}

@repository(UserModel)
export class UserRepository extends BaseRepository<UserModel> {

  @cachePut((username: string) => `user_${username}`, { expiredTime: 30 * 60 })
  @bindSql(`select * from #table# where username = #username#`, { page: false })
  async getByUsername(username: string) {
    // SQL
    return new UserModel(this.queryOne(`
        xxxxxxxx
    `, arguments));
  }

  async add(model: UserModel) { }

  @cacheEvict((username: string) => `user_${username}`)
  async updateByUsername(username: string, model: UserModel) { }

  @cacheEvict((username: string) => `user_${username}`)
  async deleteByUsername(username: string) { }
}

domain:

export class ActivityModel extends BaseModel {
  id: number;

  @manyToOne('owner', UserModel, 'getByUsername')
  user: Promise<UserModel>;

  @manyToOne('teamId', TeamModel)
  team: Promise<TeamModel>;
}

export class UserModel extends BaseModel {
  id: number;

  @valid([
    { minLength: 10 },
    { custom: (str: string) => true, errorMsg: 'xxx' }
  ])
  username: string;
}
See the full example.

Keywords

FAQs

Last updated on 01 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc