smartdata/dist/smartdata.classes.dbtable.d.ts

52 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

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;
}
/**
*
*/
export interface IDocValidationFunc<T> {
2017-07-15 22:11:03 +00:00
(doc: T): boolean;
}
/**
* 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;
export declare class DbTable<T> {
2017-07-15 22:11:03 +00:00
/**
* the collection that is used
2017-07-15 22:11:03 +00:00
*/
table: plugins.rethinkDb.Table;
objectValidation: IDocValidationFunc<T>;
tableName: string;
2017-07-15 22:11:03 +00:00
db: Db;
constructor(collectedClassArg: T & DbDoc<T>, dbArg: Db);
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: IDocValidationFunc<T>): void;
2017-07-15 22:11:03 +00:00
/**
* finds an object in the DbCollection
*/
find(filterObject: any): Promise<any>;
2017-07-15 22:11:03 +00:00
/**
* create an object in the database
2017-07-15 22:11:03 +00:00
*/
insert(dbDocArg: T & DbDoc<T>): Promise<WriteResult>;
2017-07-15 22:11:03 +00:00
/**
* inserts object into the DbCollection
2017-07-15 22:11:03 +00:00
*/
update(dbDocArg: T & DbDoc<T>): Promise<WriteResult>;
2017-07-15 22:11:03 +00:00
/**
* checks a Doc for constraints
* if this.objectValidation is not set it passes.
2017-07-15 22:11:03 +00:00
*/
private checkDoc(docArg);
extractKey(writeResult: WriteResult): void;
2017-07-15 22:11:03 +00:00
}