DataCollection
Extends:
DataCollection class.
Example:
API:
->constructor(arg_cache_manager,arg_data_adapter,arg_model_schema)
->get_name():string - get tenant to use inside this datastore.
->get_cache_manager():CacheManager - get cache manager instance.
->get_adapter():DataAdapter - get data adapter instance.
->get_model():DataModel - get collection model instance.
->validate_record(arg_record):Promise(boolean) - test if given datas are valid for collection model.
->new_record(arg_record_datas, arg_record_id) - create a new record instance.
->create_record(arg_record):Promise(DataRecord) - create an existing unsaved data record.
->delete_record(arg_record):Promise(boolean) - delete an existing data record.
->update_record(arg_record):Promise(DataRecord) - update an existing data record.
->reload_record(arg_record):Promise(DataRecord) - reload an existing data record.
->has_record(arg_record_id):Promise(boolean) - test if a data record exists with an id.
->find_one_record(arg_record_id):Promise(DataRecord) - find an existing data record with an id.
->find_records(arg_query):Promise(DataRecordArray) - find existing data records with a query.
->find_all_records():Promise(DataRecordArray) - find all xisting data records.
PRIVATE:
->_emit(arg_event, arg_datas=undefined):nothing
->_trigger(arg_event, arg_datas):nothing
->_has_cached_record_by_id(arg_id):Promise(boolean)
->_get_cached_record_by_id(arg_id):Promise(DataRecord)
->_set_cached_record_by_id(arg_record):Promise(boolean)
->_remove_cached_record_by_id(arg_id):Promise(boolean)
USAGE ON BROWSER:
// ds is a DataStore instance
var cars = ds.get_collection('cars')
var car_12 = cars.find_one_record('12')
Constructor Summary
Public Constructor | ||
public |
constructor(arg_cache_manager: CacheManager, arg_data_adapter: DataAdapter, arg_model_schema: array): nothing DataCollection class is responsible to manage one model records from one adapter: all records operations, cached records, model logic (field value validation, triggers). |
Member Summary
Public Members | ||
public |
Class type flag. |
Private Members | ||
private |
Datas adapter instance. |
|
private |
CacheManager instance. |
|
private |
Datas collection prefix. |
|
private |
Datas collection name. |
|
private |
_schema: array Topology model schema instance. |
Method Summary
Public Methods | ||
public |
create_record(arg_record: DataRecord): Promise Create a data collection record. |
|
public |
delete_record(arg_record: DataRecord): Promise Delete a data collection record. |
|
public |
Find all existing data records from adapter. |
|
public |
find_one_record(arg_record_id: string): Promise Find an existing data record with an id. |
|
public |
find_records(arg_query: DataQuery): Promise Find existing data records with a query. |
|
public |
Get data adapter. |
|
public |
Get cache manager. |
|
public |
Get data model. |
|
public |
Get collection name. |
|
public |
Get data model. |
|
public |
has_record(arg_record_id: string): Promise Update a data collection record. |
|
public |
new_record(arg_record_datas: object, arg_record_id: string): Promise Create a new data record instance, not saved. |
|
public |
update_record(arg_record: DataRecord): Promise Update a data collection record. |
|
public |
validate_record(arg_record: DataRecord): Promise Validate data record values. |
Private Methods | ||
private |
Emit on event. |
|
private |
_get_cached_record_by_id(arg_id: string): Promise Get a cached record. |
|
private |
_get_cached_record_by_query(arg_query: DataQuery): Promise Get a cached record array. |
|
private |
_has_cached_record_by_id(arg_id: string): Promise Test if a record is cached. |
|
private |
_has_cached_record_by_query(arg_query: DataQuery): Promise Test if a record array is cached. |
|
private |
_remove_cached_record_by_id(arg_id: string): Promise Remove a cached record. |
|
private |
_set_cached_record_by_id(arg_record: DataRecord): Promise Add a record to cache. |
|
private |
_set_cached_record_by_query(arg_query: DataQuery, arg_record_array: DataRecordArray): Promise Add a record array to cache. |
|
private |
Call event triggers. |
Inherited Summary
From class Loggable | ||
public |
Log context. |
|
public |
Class type flag. |
|
public |
Trace is enabled for this flag. |
|
private |
Logger manager instance (default undefined) |
|
public |
Trace DEBUG formatted message. |
|
public |
disable_trace(): nothing Disable traces. |
|
public |
enable_trace(): nothing Enable traces. |
|
public |
enter_group(arg_group: string): nothing Trace INFO message on "enter trace group". |
|
public |
Trace ERROR formatted message. |
|
public |
Define get class name method for non Instance classes. |
|
public |
Get instance context. |
|
public |
Get logger manager. |
|
public |
Define get instance name method for non Instance classes. |
|
public |
Get trace flag. |
|
public |
Trace INFO formatted message. |
|
public |
leave_group(arg_group: string): nothing Trace INFO message on "leave trace group". |
|
public |
separate_level_1(): nothing Trace INFO trace level 1 separator. |
|
public |
separate_level_2(): nothing Trace INFO trace level 2 separator. |
|
public |
separate_level_3(): nothing Trace INFO trace level 3 separator. |
|
public |
Set trace flag. |
|
public |
should_trace(arg_traces_cfg: object): boolean Calculate should trace flag. |
|
public |
should_trace_class(arg_traces_cfg: object): boolean Calculate should trace flag for classes. |
|
public |
should_trace_collection_item(arg_traces_cfg: object, arg_collection_name: string, arg_this_item_accessor: string): boolean Calculate should trace flag for given collection of names or patterns. |
|
public |
should_trace_module(arg_traces_cfg: object): boolean Calculate should trace flag for modules. |
|
public |
should_trace_name(arg_traces_cfg: object): boolean Calculate should trace flag for instances names. |
|
public |
Toggle trace flag. |
|
public |
update_trace_enabled(): nothing Update trace enabled flag. |
|
public |
Trace WARN formatted message. |
Public Constructors
public constructor(arg_cache_manager: CacheManager, arg_data_adapter: DataAdapter, arg_model_schema: array): nothing source
DataCollection class is responsible to manage one model records from one adapter: all records operations, cached records, model logic (field value validation, triggers). DataCollection instances are managed by a DataStore instance.
Override:
Loggable#constructorParams:
Name | Type | Attribute | Description |
arg_cache_manager | CacheManager | cache manager instance. |
|
arg_data_adapter | DataAdapter | collection data adapter. |
|
arg_model_schema | array | topology model schema. |
Return:
nothing |
Public Members
Private Members
Public Methods
public create_record(arg_record: DataRecord): Promise source
Create a data collection record. 1-Call 'before_create' triggers. 2-Check existing record id within cached records. 3-Validate record datas: reject on failure 4-Create a DataRecord instance with adapter.new_record. 5-Add record to cache. 6-Call record.save() 7-Call 'after_create' triggers.
Params:
Name | Type | Attribute | Description |
arg_record | DataRecord | data record instance. |
public delete_record(arg_record: DataRecord): Promise source
Delete a data collection record. 1-Call 'before_delete' triggers. 2-Remove cached record. 3-Call record.delete() 4-Call 'after_delete' triggers.
Params:
Name | Type | Attribute | Description |
arg_record | DataRecord | data record instance. |
public find_one_record(arg_record_id: string): Promise source
Find an existing data record with an id. 1-Search record into cache 2-Search record into adapter 3-Save record into cache
Params:
Name | Type | Attribute | Description |
arg_record_id | string | data record id. |
public find_records(arg_query: DataQuery): Promise source
Find existing data records with a query. 1-Search records into cache 2-Search records into adapter 3-Save records into cache
Params:
Name | Type | Attribute | Description |
arg_query | DataQuery | data query. |
public has_record(arg_record_id: string): Promise source
Update a data collection record. 1-Search record into cache 2-Search record into adapter
Params:
Name | Type | Attribute | Description |
arg_record_id | string | data record id. |
public new_record(arg_record_datas: object, arg_record_id: string): Promise source
Create a new data record instance, not saved.
public update_record(arg_record: DataRecord): Promise source
Update a data collection record. 1-Call 'before_update' triggers. 2-Update cached record. 3-Call record.update() 4-Call 'after_update' triggers.
Params:
Name | Type | Attribute | Description |
arg_record | DataRecord | data record instance. |
public validate_record(arg_record: DataRecord): Promise source
Validate data record values. 1-Call 'before_validate' triggers. 2-Check all fields values. 3-Call 'after_validate_ok' triggers on success. Call 'after_validate_ko' triggers on failure. 4-Return success (true) or failure (false)
Params:
Name | Type | Attribute | Description |
arg_record | DataRecord | data record instance. |
Private Methods
private _emit(arg_event: string, arg_datas: any): nothing source
Emit on event.
Params:
Name | Type | Attribute | Description |
arg_event | string | event name. |
|
arg_datas | any | event datas (optional, default:undefined). |
Return:
nothing |
private _get_cached_record_by_id(arg_id: string): Promise source
Get a cached record.
Params:
Name | Type | Attribute | Description |
arg_id | string | record id. |
private _get_cached_record_by_query(arg_query: DataQuery): Promise source
Get a cached record array.
Params:
Name | Type | Attribute | Description |
arg_query | DataQuery | data query. |
private _has_cached_record_by_id(arg_id: string): Promise source
Test if a record is cached.
Params:
Name | Type | Attribute | Description |
arg_id | string | record id. |
private _has_cached_record_by_query(arg_query: DataQuery): Promise source
Test if a record array is cached.
Params:
Name | Type | Attribute | Description |
arg_query | DataQuery | data query. |
private _remove_cached_record_by_id(arg_id: string): Promise source
Remove a cached record.
Params:
Name | Type | Attribute | Description |
arg_id | string | record id. |
private _set_cached_record_by_id(arg_record: DataRecord): Promise source
Add a record to cache.
Params:
Name | Type | Attribute | Description |
arg_record | DataRecord | record |