UNPKG

blow-data-service

Version:

Observable data service for Blow.

53 lines (40 loc) 1.26 kB
'use strict'; import {Observable} from 'rxjs'; import {Query} from 'blow-query'; import {DataConnector} from './connectors/DataConnector'; import {Entity} from './Entity'; export class Collection<T extends Entity> { protected _name: string; protected _connection: DataConnector; constructor(name: string, connection: DataConnector) { this._name = name; this._connection = connection; } get name(): string { return this._name; } get connection(): DataConnector { return this._connection; } count(query?: Query): Observable<number> { return this._connection.count(this._name, query); } delete(query?: Query): Observable<number> { return this._connection.delete(this._name, query); } deleteById(id: any): Observable<boolean> { return this._connection.deleteById(this._name, id); } find(query?: Query): Observable<T> { return this._connection.find<T>(this._name, query); } get(id: any): Observable<T> { return this._connection.get<T>(this._name, id); } save(doc: Entity): Observable<T> { return this._connection.save<T>(this._name, doc); } updateAttributes(id: any, doc: Entity): Observable<T> { return this._connection.updateAttributes<T>(this._name, id, doc); } }