added Decorator support for easy connection between classes and collections
This commit is contained in:
@ -58,4 +58,8 @@ export class Db {
|
||||
}
|
||||
return done.promise
|
||||
};
|
||||
|
||||
addCollection(dbCollectionArg: DbCollection<any>) {
|
||||
this.collections.add(dbCollectionArg)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user