ts-db-helper
Version:
Simple ORM based on TypeScript
87 lines (86 loc) • 2.76 kB
TypeScript
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 'rxjs/add/observable/combineLatest';
import 'rxjs/add/operator/map';
/**
* @public
* @class QueryInsert
*
* @description
* For design reasons this class should not be used directly. Use this class with {@link Insert} function.
* Prefer use of save() method instead of Insert for a single entry.
* Insert optimize multiple entry insertion with bulk mecanisme for example.
*
* @param T @extends DbHelperModel a model declared with table and column annotations
*
* @example
* ```typescript
* // Create new model instance
* const todo = new Todo();
* // manipulates todo instance and then insert it
* Insert(todo).exec().subscribe((qr: QueryResult<any>) => {
* // do something after insertion
* }, (err) => {
* // manage error
* });
*
* // it is simplier to use the save methode for a single entry
* todo.save()
*
* // Insertion should be used for multiple model insertion
* const todos = <Todo[]>[];
* // provide and edi.subscribe((qr: QueryResult<any>) => {
* // do something after insertion
* }, (err) => {
* // manage error
* });t new entries
* Insert(todos).exec().subscribe((qr: QueryResult<any>) => {
* // do something after insertion
* }, (err) => {
* // manage error
* });
* ```
*
* @author Olivier Margarit
* @since 0.1
*/
export declare class QueryInsert<T extends DbHelperModel> {
private model;
/**
* @private
* @static
* @constant {number} SQLITE_PRAMS_LIMIT is a standard SQLite driver limit
* this parameter will probably be customizable in a futrue
* release
*/
private static readonly SQLITE_PRAMS_LIMIT;
/**
* @private
* @constant {string} type statement type
*/
private readonly type;
/**
* @public
* @constructor should not be use directly, see class header
*
* @param {T | Array<T>} model DbHelper model or list of models
*/
constructor(model: T | 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<QueryResult<any>>} observable to subscribe and manage results
*/
exec(): Observable<QueryResult<any>>;
}