typescript
) and created the 2 decorators below:
export function Column(options?: ColumnDecoratorDescriptor) {
return (target: Object, key: string) => {
let _val = this[key];
if (delete this[key])
Object.defineProperty(target, key, {
get: () => _val,
set: (n: any) => _val = n,
enumerable: true,
configurable: true,
__: options
} as any);
}
}
export function Table(options: TableDecoratorDescription) {
return <T extends { new(...args: any[]): {} }>(constructor: T) => {
return class extends constructor {
__: TableDecoratorDescription = options;
}
}
}
The idea is that I can create class models like this:
@Table({ name:'Person', schema: 'dbo'})
class PersonModel {
@Column({type: 'int'})
id: number
}
I just do not know how to capture the properties I passed in these decorators in other classes eg:
class PersonRepository {
get(ref?:number | object) {
let temp: new Person();
let tableName:string = /* como pego s dados do decorator Table ?*/
}
find(filters:object) { ... }
add(...person[]: Person) { ... }
update(ref: number | object, fields:object) { ... }
delete(ref:number | object) { ... }
}