ts-db-helper
Version:
Simple ORM based on TypeScript
115 lines (114 loc) • 3.76 kB
TypeScript
import { CompositeClause } from './composite-clause.model';
import { DbHelperModel } from '../db-helper-model.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 QueryUpdate
*
* @description
* For design reasons this class should not be used directly. Use this class with {@link Update} function.
*
* @param T @extends DbHelperModel a model declared with table and column annotations
*
* @example
* ```typescript
* // update todo object
* Update(todo).exec().subscribe((qr: QueryResult<any>) => {
* // do something with the result...
* }, (err) => {
* // do something with the error...
* });
* ```
*
* @author Olivier Margarit
* @since 0.1
*/
export declare class QueryUpdate<T extends DbHelperModel> {
private model;
/**
* @private
* @constant {string} type the type of statement, should not be modified
*/
private readonly type;
/**
* @private
* @property {ClauseGroup} whereClauses clause group instance containing
* where clauses
*/
private whereClauses;
/**
* @private
* @property {{[index: string]: any}} valueSet set of values where key are column name and value,
* the value to update.
*/
private valueSet;
/**
* @public
* @constructor should not be use directly, see class header
*
* @param {T | {new (): T}} model model instance or model
*/
constructor(model: T | {
new (): T;
});
/**
* @public
* @method where is the method to add clauses to the where statement of the query
* see {@link Clause} or {@link ClauseGroup}
*
* @param {Clause|Clause[]|CompositeClause|ClauseGroup|{[index: string]: any}} clauses where clauses
*
* @return {QueryUpdate<T>} this instance to chain query instructions
*/
where(clauses: Clause | Clause[] | CompositeClause | ClauseGroup | {
[index: string]: any;
}): QueryUpdate<T>;
/**
* @public
* @method where is the method to add clauses to the where statement of the query
* see {@link Clause} or {@link ClauseGroup}
*
* @throws {@link QueryError} on set on single model update. set method is for updating
* many entries of a specific table target from its class.
*
* @param {{[index: string]: any}} dict map of column and values to update.
*
* @return {QueryUpdate<T>} this instance to chain query instructions
*/
set(dict: {
[index: string]: any;
}): QueryUpdate<T>;
/**
* @private
* @method getValuesFromModel build values part of the query from the model.
*
* @return {QueryPart} the values query part of update statement
*/
private getValuesFromModel();
/**
* @private
* @method getValuesFromSet build values part of the query from the set dict.
*
* @return {QueryPart} the values query part of update statement
*/
private getValuesFromSet();
/**
* @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<any>>} observable to subscribe
*/
exec(): Observable<QueryResult<any>>;
}