ts-db-helper
Version:
Simple ORM based on TypeScript
206 lines (205 loc) • 6.39 kB
TypeScript
import { CompositeClause } from './composite-clause.model';
import { IQueryHelper } from '../interfaces/i-query-helper.interface';
import { IJoin } from '../interfaces/i-join.interface';
import { DbHelperModel } from '../db-helper-model.model';
import { DbTable } from '../structure/db-table.model';
import { QueryResult } from '../../interfaces/query-result.interface';
import { Observable } from 'rxjs/Observable';
import { DbQuery } from '../db-query.model';
import { ClauseGroup } from './clause-group.model';
import { Clause } from './clause.model';
/**
* @public
* @class QuerySelect
*
* @description
* For design reasons this class should not be used directly. Use this class with {@link Select} function.
*
* @param T @extends DbHelperModel a model declared with table and column annotations
*
* @example
* ```typescript
* // select todos
* Select(Todo).where({isDone: false}}).exec().subscribe((qr: QueryResult<Todo>) => {
* // do something with the result...
* }, (err) => {
* // do something with the error...
* });
* ```
*
* @author Olivier Margarit
* @since 0.1
*/
export declare class QuerySelect<T extends DbHelperModel> implements IQueryHelper {
private model;
/**
* @private
* @constant {string} type query type
*/
private readonly type;
/**
* @private
* @property {Array<IJoin>} joins list of join for the query
*/
private joins;
/**
* @private
* @property {ClauseGroup} whereClauses clause group instance containing where clauses
*/
private whereClauses;
/**
* @private
* @property {Array<string>} proj is the query projection
*/
private proj;
/**
* @private
* @property {string} grpBy is the group by condition of the query
*/
private grpBy;
/**
* @private
* @property {string} ordrBy order by condition for the query
*/
private ordrBy;
/**
* @private
* @property size, the number of element returned by the select query
*/
private size;
/**
* @private
* @property {number} page the paginated number of the query select
*/
private page;
/**
* @private
* @property {string} alias the query alias to prevent column collision
*/
alias: string;
/**
* @public
* @constructor should not be use directly, see class header
*
* @param {{new(): T}} model extention
*/
constructor(model: {
new (): T;
});
/**
* @public
* @method copy method to copy QuerySelect
*
* @return {QuerySelect<T>} the query select copy
*
* @since 0.2
*/
copy(): QuerySelect<T>;
/**
* @public
* @method projection customize the select column of the QueryResult
* for performance optimization if needed.
*
* @param {Array<string>} proj the projection
*
* @return {QuerySelect<T>} this instance to chain query instructions
*/
projection(proj: string[]): QuerySelect<T>;
/**
* @public
* @method join add query join to query select
*
* @param {IJoin|Array<IJoin>} joinQuery join query or list of join queries
*
* @return {QuerySelect<T>} the instance itself to chain operation
*/
join(joinQuery: IJoin | IJoin[]): QuerySelect<T>;
/**
* @public
* @method where is the method to add clauses to the where statement of the query
* see {@link Clause} or {@link ClauseGroup} or {@link CompositeClause}
*
* @param {Clause|Clause[]|CompositeClause|ClauseGroup|{[index: string]: any}} clauses where clauses
*
* @return {QuerySelect<T>} this instance to chain query instructions
*/
where(clauses: Clause | Clause[] | CompositeClause | ClauseGroup | {
[index: string]: any;
}): QuerySelect<T>;
/**
* @public
* @method groupBy add group by instructions to the query
*
* @param {string} group string whith the column to group by
*
* @return {QuerySelect<T>} this instance to chain query instructions
*/
groupBy(group: string): QuerySelect<T>;
/**
* @public
* @method orderBy add order by instructions to the query
*
* @param {string} order string whith the column to order by
*
* @return {QuerySelect<T>} this instance to chain query instructions
*/
orderBy(order: string): QuerySelect<T>;
/**
* @public
* @method setPage set the page result for pagination
*
* @param {number} page page number of the result
*
* @return {QuerySelect<T>} this instance to chain query instructions
*/
setPage(page: number): QuerySelect<T>;
/**
* @public
* @method setSize set the size of the page result for pagination
*
* @param {number} size page size number of the result
*
* @return {QuerySelect<T>} this instance to chain query instructions
*/
setSize(size: number): QuerySelect<T>;
getSize(): number;
getPage(): number;
/**
* @public
* @method getProjectedTable get virtual table representing the result table expected
*
* @return {DbTable} the virtual table
*/
getProjectedTable(): DbTable;
/**
* @private
* @method getJoinProjection get the projection of join query
*
* @return {string} the projection
*/
private getJoinProjection();
/**
* @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<QueryResult<T>>} observable to subscribe and retrieve typed result
*/
exec(): Observable<QueryResult<T>>;
/**
* @public
* @method exec to execute the query and asynchronously retreive result.
*
* @return {Observable<QueryResult<any>>} observable to subscribe and retrieve result
*
* @since 0.2
*/
execRaw(): Observable<QueryResult<any>>;
}