core-repository
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Repository Pattern for Type Script

Change Log

  1. Allow define decorator by yourself
  2. Callback change to function

  1. Declare Decorator
import "reflect-metadata"
 
export const MetadataKey = "Sql:repository";
export function Sql(sql: string) {
    return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
        Reflect.defineMetadata(MetadataKey, sql, target.__proto__, descriptor.value.name);
    };
}
 
let sqlCallback: CallbackFunc = function(metadata: any, ...params:any[]):any {
    // Will be executed when "Decorator" function called
    return 1;
}
// Regist to Repository Manager
RepoManager.regist(MetadataKey, sqlCallback);
 

  1. Declare Repository with @Sql
 
export class SampleRepository{
    @Sql('select * from "order" where "id" = ?')
    public async findById(id:Number):Promise<any> {return null};
}
  1. Use repository
    var repository = RepositoryFactory.repoConstructor(null, SampleRepository);
    var result = await repository.findById(1); // return 1
  1. Inversify integreation
 
@(fluentProvide(SampleRepository).inSingletonScope().onActivation(repoConstructor).done())
export class SampleRepository{
    @Sql('select * from "order" where "id" = ?')
    public async findById(id:Number):Promise<any> {return null};
}

Readme

Keywords

none

Package Sidebar

Install

npm i core-repository

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

18.8 kB

Total Files

30

Last publish

Collaborators

  • sunxufei