added Decorator support for easy connection between classes and collections

This commit is contained in:
2016-09-14 01:02:11 +02:00
parent f7f7852b7f
commit 6683c05c22
12 changed files with 53 additions and 23 deletions

View File

@ -58,4 +58,8 @@ export class Db {
}
return done.promise
};
addCollection(dbCollectionArg: DbCollection<any>) {
this.collections.add(dbCollectionArg)
}
}

View File

@ -5,6 +5,12 @@ export interface IFindOptions {
limit?: number
}
export function Collection(db: Db) {
return function(constructor){
constructor['dbCollection'] = new DbCollection(constructor.name, db)
}
}
export class DbCollection<T> {
collection: plugins.mongodb.Collection
name: string

View File

@ -5,16 +5,17 @@ import { DbCollection } from './smartdata.classes.dbcollection'
export type TDocCreation = 'db' | 'data' | 'mixed'
export class DbDoc<T> {
collection: DbCollection<T>
creationType: TDocCreation
constructor(collectionNameArg: string, dbArg: Db ) {
this.collection = new DbCollection<T>(collectionNameArg, dbArg)
constructor() {
this.collection = this.constructor['dbCollection']
}
save() {
}
saveDeep() {
}
}