UNPKG

ts-db-helper

Version:
77 lines (76 loc) 2.2 kB
import { QuerySelect } from './query-select.model'; import { DbHelperModel } from '../db-helper-model.model'; import { Observable } from 'rxjs/Observable'; import { DbQuery } from '../db-query.model'; /** * @public * @class QueryCount * * @description * For design reasons this class should not be used directly. * Prefer use {@link Count} function. * * @param T @extends DbHelperModel a model declared with table and column annotations * * @example * ```typescript * // count todos * Count(Select(Todo).where({isDone: false}})).exec().subscribe((cout: number) => { * // do something with the result... * }, (err) => { * // do something with the error... * }); * ``` * * @author Olivier Margarit * @since 0.2 */ export declare class QueryCount<T extends DbHelperModel> { private querySelect; /** * @public * @constructor create instance of QueryCount * @param querySelect the query to count the result */ constructor(querySelect: QuerySelect<T>); /** * @public * @method build should be removed to be a part of the private API * * @return {DbQuery} of the query with the string part and * clauses params. */ build(): DbQuery; /** * @public * @method exec to execute the query and asynchronously retreive result. * * @return {Observable<number>} observable to subscribe and returning a count number as result */ exec(): Observable<number>; } /** * @public * @function Count * * @description * function helper to count element that a query could return * * @param T @extends DbHelperModel a model declared with table and column annotations * * @example * ```typescript * // count todos * Count(Select(Todo).where({isDone: false}})).exec().subscribe(count: number) => { * // do something with the result... * }, (err) => { * // do something with the error... * }); * ``` * * @return {QueryCount<T>} instance * * @author Olivier Margarit * @since 0.2 */ export declare function Count<T extends DbHelperModel>(select: QuerySelect<T>): QueryCount<T>;