tedb
Version:
TypeScript Embedded Database
61 lines (60 loc) • 1.44 kB
TypeScript
/**
* Created by tsturzl on 4/11/17.
*/
import Datastore from "./datastore";
export interface ICursor {
sort(sort: any): this;
skip(skip: number): this;
limit(limit: number): this;
exec(): Promise<any[] | number>;
}
/**
* Simply used for $anding default inputs.
*/
export interface I$and {
$and: any[];
}
export interface Ioptions {
sort?: any;
skip?: number;
limit?: number;
}
/**
* Database Cursor
*/
export default class Cursor implements ICursor {
/** Reference to Datastore object */
private datastore;
/** Query passed from `Datastore.find` or `count` */
private query;
/** Options for `exec` */
private options;
/** Is this a count operation? */
private count;
/**
* Constructor
* @param datastore - Datastore reference
* @param query - query for search
* @param count - is this a count operation? Default: false
*/
constructor(datastore: Datastore, query?: any, count?: boolean);
/**
* Sort order for fields
* @param sort - sort object `{fieldName: 1 | -1}`
*/
sort(sort: any): this;
/**
* Set how many results to skip
* @param skip - how many results to skip
*/
skip(skip: number): this;
/**
* Limit result size
* @param limit - how many results
*/
limit(limit: number): this;
/**
* Execute the Cursor
*/
exec(): Promise<any[] | number>;
}