smartdata/dist/smartdata.classes.dbcollection.d.ts

46 lines
1.4 KiB
TypeScript
Raw Normal View History

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';
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;
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)
*/
table: plugins.rethinkDb.Table;
2017-07-15 22:11:03 +00:00
objectValidation: IDocValidation<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: IDocValidation<T>): void;
/**
* finds an object in the DbCollection
*/
find(): Promise<Cursor>;
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
}