2017-07-15 22:11:03 +00:00
|
|
|
import * as plugins from './smartdata.plugins';
|
|
|
|
import { Db } from './smartdata.classes.db';
|
|
|
|
import { DbDoc } from './smartdata.classes.dbdoc';
|
2018-01-12 00:22:58 +00:00
|
|
|
import { WriteResult, Cursor } from 'rethinkdb';
|
2017-07-15 22:11:03 +00:00
|
|
|
export interface IFindOptions {
|
|
|
|
limit?: number;
|
|
|
|
}
|
|
|
|
export interface IDocValidation<T> {
|
|
|
|
(doc: T): boolean;
|
|
|
|
}
|
|
|
|
export declare function Collection(db: Db): (constructor: any) => void;
|
2018-01-07 17:10:16 +00:00
|
|
|
export declare class DbTable<T> {
|
2017-07-15 22:11:03 +00:00
|
|
|
/**
|
|
|
|
* the collection that is used, defaults to mongodb collection,
|
|
|
|
* can be nedb datastore (sub api of mongodb)
|
|
|
|
*/
|
2018-01-07 17:10:16 +00:00
|
|
|
table: plugins.rethinkDb.Table;
|
2017-07-15 22:11:03 +00:00
|
|
|
objectValidation: IDocValidation<T>;
|
2018-01-12 00:22:58 +00:00
|
|
|
tableName: string;
|
2017-07-15 22:11:03 +00:00
|
|
|
db: Db;
|
|
|
|
constructor(collectedClassArg: T & DbDoc<T>, dbArg: Db);
|
2018-01-12 00:22:58 +00:00
|
|
|
init(): Promise<void>;
|
2017-07-15 22:11:03 +00:00
|
|
|
/**
|
|
|
|
* adds a validation function that all newly inserted and updated objects have to pass
|
|
|
|
*/
|
|
|
|
addDocValidation(funcArg: IDocValidation<T>): void;
|
|
|
|
/**
|
|
|
|
* finds an object in the DbCollection
|
|
|
|
*/
|
2018-01-12 00:22:58 +00:00
|
|
|
find(): Promise<Cursor>;
|
2017-07-15 22:11:03 +00:00
|
|
|
/**
|
2018-01-12 00:22:58 +00:00
|
|
|
* create an object in the database
|
2017-07-15 22:11:03 +00:00
|
|
|
*/
|
2018-01-12 00:22:58 +00:00
|
|
|
insert(dbDocArg: T & DbDoc<T>): Promise<WriteResult>;
|
2017-07-15 22:11:03 +00:00
|
|
|
/**
|
2018-01-12 00:22:58 +00:00
|
|
|
* inserts object into the DbCollection
|
2017-07-15 22:11:03 +00:00
|
|
|
*/
|
2018-01-12 00:22:58 +00:00
|
|
|
update(dbDocArg: T & DbDoc<T>): Promise<WriteResult>;
|
2017-07-15 22:11:03 +00:00
|
|
|
/**
|
|
|
|
* checks a Doc for constraints
|
2018-01-12 00:22:58 +00:00
|
|
|
* if this.objectValidation is not set it passes.
|
2017-07-15 22:11:03 +00:00
|
|
|
*/
|
|
|
|
private checkDoc(docArg);
|
2018-01-12 00:22:58 +00:00
|
|
|
extractKey(writeResult: WriteResult): void;
|
2017-07-15 22:11:03 +00:00
|
|
|
}
|