2016-09-11 16:01:46 +00:00
|
|
|
import * as plugins from './smartdata.plugins';
|
2016-09-12 21:50:25 +00:00
|
|
|
import { Db } from './smartdata.classes.db';
|
2017-06-18 17:52:54 +00:00
|
|
|
import { DbDoc } from './smartdata.classes.dbDoc';
|
2016-09-13 20:53:21 +00:00
|
|
|
export interface IFindOptions {
|
|
|
|
limit?: number;
|
|
|
|
}
|
2016-11-17 21:36:12 +00:00
|
|
|
export interface IDocValidation<T> {
|
|
|
|
(doc: T): boolean;
|
|
|
|
}
|
2016-09-13 23:02:11 +00:00
|
|
|
export declare function Collection(db: Db): (constructor: any) => void;
|
2016-09-11 16:01:46 +00:00
|
|
|
export declare class DbCollection<T> {
|
2016-11-17 11:20:52 +00:00
|
|
|
/**
|
2016-11-17 21:36:12 +00:00
|
|
|
* the collection that is used, defaults to mongodb collection,
|
|
|
|
* can be nedb datastore (sub api of mongodb)
|
2016-11-17 11:20:52 +00:00
|
|
|
*/
|
2016-09-11 16:01:46 +00:00
|
|
|
collection: plugins.mongodb.Collection;
|
2017-06-18 17:52:54 +00:00
|
|
|
collectedClass: T & DbDoc<T>;
|
|
|
|
objectValidation: IDocValidation<T>;
|
2016-09-13 20:53:21 +00:00
|
|
|
name: string;
|
2016-11-17 21:36:12 +00:00
|
|
|
db: Db;
|
2017-06-18 17:52:54 +00:00
|
|
|
constructor(collectedClassArg: T & DbDoc<T>, dbArg: Db);
|
2016-09-11 16:01:46 +00:00
|
|
|
/**
|
|
|
|
* adds a validation function that all newly inserted and updated objects have to pass
|
|
|
|
*/
|
2016-11-17 21:36:12 +00:00
|
|
|
addDocValidation(funcArg: IDocValidation<T>): void;
|
2016-09-11 16:01:46 +00:00
|
|
|
/**
|
2016-09-12 15:31:23 +00:00
|
|
|
* finds an object in the DbCollection
|
2016-09-11 16:01:46 +00:00
|
|
|
*/
|
2017-06-18 17:52:54 +00:00
|
|
|
find(docMatchArg: T | any, optionsArg?: IFindOptions): Promise<T[]>;
|
2016-09-12 15:31:23 +00:00
|
|
|
/**
|
2016-11-17 21:36:12 +00:00
|
|
|
* inserts object into the DbCollection
|
2016-09-12 15:31:23 +00:00
|
|
|
*/
|
2017-06-18 17:52:54 +00:00
|
|
|
insertOne(docArg: T): Promise<void>;
|
2016-09-11 16:01:46 +00:00
|
|
|
/**
|
|
|
|
* inserts many objects at once into the DbCollection
|
|
|
|
*/
|
2017-06-18 17:52:54 +00:00
|
|
|
insertMany(docArrayArg: T[]): Promise<void>;
|
2016-11-17 21:36:12 +00:00
|
|
|
/**
|
|
|
|
* checks a Doc for constraints
|
|
|
|
*/
|
|
|
|
private checkDoc(docArg);
|
2016-09-11 16:01:46 +00:00
|
|
|
}
|