DataStore
Extends:
DataStore class.
Example:
API:
->constructor()
// DATA ADAPTERS MANAGEMENT
->add_adapter(arg_adapter):boolean
->remove_adapter(arg_adapter):boolean
->suspend_adapter(arg_adapter):boolean
->resume_adapter(arg_adapter):boolean
// DATA COLLECTIONS MANAGEMENT
->get_collection(arg_model_name):DataCollection - get a data collection for a model.
->add_collection(arg_collection):boolean - add a data collection.
->remove_collection(arg_collection):boolean - remove a data collection.
// WRAPPERS FOR DATA COLLECTIONS OPERATIONS
->create_record(arg_collection_name, arg_record_id, arg_record_datas):Promise(DataRecord) - create a new data record.
->delete_record(arg_collection_name, arg_record_id):Promise(boolean) - delete an existing data record.
->update_record(arg_collection_name, arg_record_id, arg_record_datas):Promise(DataRecord) - update an existing data record.
->has_record(arg_collection_name, arg_record_id):Promise(boolean) - test if a data record exists with an id.
->find_one_record(arg_collection_name, arg_record_id):Promise(DataRecord) - find an existing data record with an id.
->find_records(arg_collection_name, arg_query):Promise(DataRecordArray) - find existing data records with a query.
->find_all_records(arg_collection_name):Promise(DataRecordArray) - find all xisting data records.
USAGE ON BROWSER:
var memory_cache = new CacheAdapterNodeCache( {ttl:5000, check_period:2000} )
var cache_manager = new CacheManager([memory_cache])
var rest_settings = {...}
var models_settings = {...}
var rest_adapter = new DataAdapterRest(rest_settings, models_settings)
var ds = new DataStore(cache_manager, [rest_adapter])
ds.set_tenant('my tenant')
ds.set_credentials('*', app.get_credentials())
ds.set_credentials('cars', {token:'...'} )
var cars = ds.get_collection('cars')
var car_12 = cars.find_one_record('12')
or
var car_13 = ds.find_one_record('cars', '13')
var car_14 = ds.create_record('cars', '14', { engine:'gazol', color:'red' } )
Each application on the browser has credentials for one tenant.
Constructor Summary
Public Constructor | ||
public |
constructor(arg_cache_manager: CacheManager, arg_data_adapters: array): nothing Data store class is the main interface between datas consumers (views) and producers (adapters). |
Member Summary
Public Members | ||
public |
Class type flag. |
Private Members | ||
private |
_adapters: array Datas adapters array. |
|
private |
CacheManager instance. |
|
private |
Adapter collections map. |
Method Summary
Public Methods | ||
public |
add_adapter(arg_adapter: DataAdapter): boolean Add a data adapter. |
|
public |
add_collection(arg_collection: DataCollection): boolean Add a data collection. |
|
public |
create_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise Create a data collection record. |
|
public |
delete_record(arg_collection_name: string, arg_record_id: string): Promise Delete a data collection record. |
|
public |
find_all_records(arg_collection_name: string): Promise Find all existing data records. |
|
public |
find_one_record(arg_collection_name: string, arg_record_id: string): Promise Find an existing data record with an id. |
|
public |
find_records(arg_collection_name: string, arg_query: DataQuery): Promise Find existing data records with a query. |
|
public |
get_collection(arg_model_name: string): DataCollection | undefined Get a data collection for a model. |
|
public |
has_record(arg_collection_name: string, arg_record_id: string): Promise Update a data collection record. |
|
public |
remove_adapter(arg_adapter: DataAdapter): boolean Remove a data adapter. |
|
public |
remove_collection(arg_collection: DataCollection): boolean Remove a data collection. |
|
public |
resume_adapter(arg_adapter: DataAdapter): boolean Resume a data adapter. |
|
public |
suspend_adapter(arg_adapter: DataAdapter): boolean Suspend a data adapter. |
|
public |
update_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise Update a data collection record. |
Private Methods | ||
private |
Emit on event. |
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_adapters: array): nothing source
Data store class is the main interface between datas consumers (views) and producers (adapters).
Override:
Loggable#constructorParams:
Name | Type | Attribute | Description |
arg_cache_manager | CacheManager | cache manager instance. |
|
arg_data_adapters | array | data adapters array. |
Return:
nothing |
Public Members
Private Members
Public Methods
public add_adapter(arg_adapter: DataAdapter): boolean source
Add a data adapter.
Params:
Name | Type | Attribute | Description |
arg_adapter | DataAdapter | data adapter. |
public add_collection(arg_collection: DataCollection): boolean source
Add a data collection.
Params:
Name | Type | Attribute | Description |
arg_collection | DataCollection | data collection. |
public create_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise source
Create a data collection record.
public delete_record(arg_collection_name: string, arg_record_id: string): Promise source
Delete a data collection record.
public find_all_records(arg_collection_name: string): Promise source
Find all existing data records.
Params:
Name | Type | Attribute | Description |
arg_collection_name | string | data collection name. |
public find_one_record(arg_collection_name: string, arg_record_id: string): Promise source
Find an existing data record with an id.
public find_records(arg_collection_name: string, arg_query: DataQuery): Promise source
Find existing data records with a query.
public get_collection(arg_model_name: string): DataCollection | undefined source
Get a data collection for a model.
Params:
Name | Type | Attribute | Description |
arg_model_name | string | data collection model name. |
public has_record(arg_collection_name: string, arg_record_id: string): Promise source
Update a data collection record.
public remove_adapter(arg_adapter: DataAdapter): boolean source
Remove a data adapter.
Params:
Name | Type | Attribute | Description |
arg_adapter | DataAdapter | data adapter. |
public remove_collection(arg_collection: DataCollection): boolean source
Remove a data collection.
Params:
Name | Type | Attribute | Description |
arg_collection | DataCollection | data collection. |
public resume_adapter(arg_adapter: DataAdapter): boolean source
Resume a data adapter.
Params:
Name | Type | Attribute | Description |
arg_adapter | DataAdapter | data adapter. |
public suspend_adapter(arg_adapter: DataAdapter): boolean source
Suspend a data adapter.
Params:
Name | Type | Attribute | Description |
arg_adapter | DataAdapter | data adapter. |
public update_record(arg_collection_name: string, arg_record_id: string, arg_record_datas: object): Promise source
Update a data collection record.