pip_services3_data.persistence.MemoryPersistence module¶
pip_services3_data.persistence.MemoryPersistence¶
Memory persistence implementation
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
-
class
pip_services3_data.persistence.MemoryPersistence.
MemoryPersistence
(loader: pip_services3_data.ILoader.ILoader = None, saver: pip_services3_data.ISaver.ISaver = None)¶ Bases:
pip_services3_commons.config.IConfigurable.IConfigurable
,pip_services3_commons.refer.IReferenceable.IReferenceable
,pip_services3_commons.run.IOpenable.IOpenable
,pip_services3_commons.run.ICleanable.ICleanable
Abstract persistence component that stores data in memory.
This is the most basic persistence component that is only able to store data items of any type. Specific CRUD operations over the data items must be implemented in child classes by accessing
self._items()
property and callingsave()
method.The component supports loading and saving items from another data source. That allows to use it as a base class for file and other types of persistence components that cache all data in memory.
- ### Configuration parameters ###
- options:
max_page_size: Maximum number of items returned in a single page (default: 100)
- ### References ###
*:logger:*:*:1.0 (optional) ILogger components to pass log messages
Example:
class MyMemoryPersistence(MemoryPersistence): def get_by_name(self, correlationId, name): item = self.find(name) ... return item persistence = MyMemoryPersistence() persistence.set("123", MyData("ABC")) print str(persistence.get_by_name("123", "ABC")))
-
clear
(correlation_id: Optional[str])¶ Clears component state.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
-
close
(correlation_id: Optional[str])¶ Closes component and frees used resources.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
-
configure
(config: pip_services3_commons.config.ConfigParams.ConfigParams)¶ Configures component by passing configuration parameters.
- Parameters
config – configuration parameters to be set.
-
create
(correlation_id: Optional[str], item: T) → T¶ Creates a data item.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
item – an item to be created.
- Returns
a created item
-
delete_by_filter
(correlation_id: Optional[str], filter: Any)¶ Deletes data items that match to a given filter.
This method shall be called by a public
delete_by_filter()
method from child class that receivesFilterParams
and converts them into a filter function.- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
filter – (optional) a filter function to filter items.
-
get_count_by_filter
(correlation_id: Optional[str], filter: Any) → int¶ Gets a number of items retrieved by a given filter.
This method shall be called by a public get_count_by_filter method from child class that receives FilterParams and converts them into a filter function.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
filter – (optional) a filter function to filter items
- Returns
a number of data items that satisfy the filter.
-
get_list_by_filter
(correlation_id: Optional[str], filter: Any, sort: Any = None, select: Any = None) → List[T]¶ Gets a list of data items retrieved by a given filter and sorted according to sort parameters.
This method shall be called by a public
get_list_by_filter()
method from child class that receivesFilterParams
and converts them into a filter function.- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
filter – (optional) a filter function to filter items
sort – (optional) sorting parameters
select – (optional) projection parameters (not used yet)
- Returns
a data list of results by filter.
-
get_one_random
(correlation_id: Optional[str]) → T¶ Gets a random item from items that match to a given filter.
This method shall be called by a public
get_one_random()
method from child class that receivesFilterParams
and converts them into a filter function.- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
- Returns
a random item.
-
get_page_by_filter
(correlation_id: Optional[str], filter: Any, paging: pip_services3_commons.data.PagingParams.PagingParams, sort: Any = None, select: Any = None) → pip_services3_commons.data.DataPage.DataPage¶ Gets a page of data items retrieved by a given filter and sorted according to sort parameters.
This method shall be called by a public
get_page_by_filter()
method from child class that receivesFilterParams
and converts them into a filter function.- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
filter – (optional) a filter function to filter items
paging – (optional) paging parameters
sort – (optional) sorting parameters
select – (optional) projection parameters (not used yet)
- Returns
a data page of result by filter.
-
is_open
() → bool¶ Checks if the component is opened.
- Returns
Anyrue if the component has been opened and false otherwise.
-
open
(correlation_id: Optional[str])¶ Opens the component.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
-
save
(correlation_id: Optional[str])¶ Saves items to external data source using configured saver component.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
-
set_references
(references: pip_services3_commons.refer.IReferences.IReferences)¶ Sets references to dependent components.
- Parameters
references – references to locate the component dependencies.