2018-01-14 16:32:04 +00:00
|
|
|
import * as plugins from "./smartdata.plugins";
|
|
|
|
import { Db } from "./smartdata.classes.db";
|
|
|
|
import { DbDoc } from "./smartdata.classes.dbdoc";
|
|
|
|
import { WriteResult } from "rethinkdb";
|
2017-07-15 22:11:03 +00:00
|
|
|
export interface IFindOptions {
|
|
|
|
limit?: number;
|
|
|
|
}
|
2018-01-14 16:32:04 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export interface IDocValidationFunc<T> {
|
2017-07-15 22:11:03 +00:00
|
|
|
(doc: T): boolean;
|
|
|
|
}
|
2018-01-14 16:32:04 +00:00
|
|
|
/**
|
|
|
|
* This is a decorator that will tell the decorated class what dbTable to use
|
|
|
|
* @param db
|
|
|
|
*/
|
|
|
|
export declare function Table(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
|
|
|
/**
|
2018-01-14 16:32:04 +00:00
|
|
|
* the collection that is used
|
2017-07-15 22:11:03 +00:00
|
|
|
*/
|
2018-01-07 17:10:16 +00:00
|
|
|
table: plugins.rethinkDb.Table;
|
2018-01-14 16:32:04 +00:00
|
|
|
objectValidation: IDocValidationFunc<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
|
|
|
|
*/
|
2018-01-14 16:32:04 +00:00
|
|
|
addDocValidation(funcArg: IDocValidationFunc<T>): void;
|
2017-07-15 22:11:03 +00:00
|
|
|
/**
|
|
|
|
* finds an object in the DbCollection
|
|
|
|
*/
|
2018-01-14 16:32:04 +00:00
|
|
|
find(filterObject: any): Promise<any>;
|
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
|
|
|
}
|