fix(core): update
This commit is contained in:
parent
5c78f83a28
commit
941d2f0902
@ -13,13 +13,23 @@ export interface IDocValidationFunc<T> {
|
|||||||
(doc: T): boolean;
|
(doc: T): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TDelayedDbCreation = () => SmartdataDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a decorator that will tell the decorated class what dbTable to use
|
* This is a decorator that will tell the decorated class what dbTable to use
|
||||||
* @param db
|
* @param dbArg
|
||||||
*/
|
*/
|
||||||
export function Collection(db: SmartdataDb) {
|
export function Collection(dbArg: SmartdataDb | TDelayedDbCreation) {
|
||||||
return function(constructor) {
|
return function(constructor) {
|
||||||
constructor['smartdataCollection'] = new SmartdataCollection(constructor, db);
|
if (dbArg instanceof SmartdataDb) {
|
||||||
|
// tslint:disable-next-line: no-string-literal
|
||||||
|
constructor['smartdataCollection'] = new SmartdataCollection(constructor, dbArg);
|
||||||
|
} else {
|
||||||
|
constructor['smartdataDelayedDatabase'] = () => {
|
||||||
|
return new SmartdataCollection(constructor, dbArg());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,16 @@ export class SmartDataDbDoc<T> {
|
|||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.name = this.constructor['name'];
|
this.name = this.constructor['name'];
|
||||||
|
if(this.constructor['smartdataCollection']) {
|
||||||
|
// tslint:disable-next-line: no-string-literal
|
||||||
this.collection = this.constructor['smartdataCollection'];
|
this.collection = this.constructor['smartdataCollection'];
|
||||||
|
// tslint:disable-next-line: no-string-literal
|
||||||
|
} else if (typeof this.constructor['smartdataDelayedDatabase'] === 'function') {
|
||||||
|
// tslint:disable-next-line: no-string-literal
|
||||||
|
this.collection = this.constructor['smartdataDelayedDatabase']();
|
||||||
|
} else {
|
||||||
|
console.error('Could not determine collection for DbDoc');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getInstances<T>(filterArg): Promise<T[]> {
|
static async getInstances<T>(filterArg): Promise<T[]> {
|
||||||
@ -109,6 +118,7 @@ export class SmartDataDbDoc<T> {
|
|||||||
* may lead to data inconsistencies, but is faster
|
* may lead to data inconsistencies, but is faster
|
||||||
*/
|
*/
|
||||||
async save() {
|
async save() {
|
||||||
|
// tslint:disable-next-line: no-this-assignment
|
||||||
let self: any = this;
|
let self: any = this;
|
||||||
switch (this.creationStatus) {
|
switch (this.creationStatus) {
|
||||||
case 'db':
|
case 'db':
|
||||||
|
Loading…
Reference in New Issue
Block a user