FilePersistence<T> class
Null safety
Abstract persistence component that stores data in flat files and caches them 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 _items property and calling save method.
See MemoryPersistence See JsonFilePersister
Configuration parameters
path
: path to the file where data is stored
References
- *:logger:*:*:1.0 (optional) ILogger components to pass log messages
Example
class MyJsonFilePersistence extends FilePersistence<MyData> {
MyJsonFilePersistence([String path]): super(JsonPersister(path)) {
}
Future<MyData> getByName(String? correlationId, String name) async {
var item = items.firstWhere((d) => d.name == name);
return item;
});
Future<MyData> set(String correlatonId, MyData item) {
items = List.from(item.where((d) => d.name != name));
items.add(item);
await save(correlationId);
return item;
}
}
- Inheritance
-
- Object
- MemoryPersistence<
T> - FilePersistence
- Implemented types
Constructors
-
FilePersistence([JsonFilePersister<
T> ? persister]) - Creates a new instance of the persistence.
Properties
- hashCode → int
-
The hash code for this object.
read-onlyinherited
-
items
↔ List<
T> -
read / writeinherited
-
loader
↔ ILoader<
T> ? -
read / writeinherited
- logger ↔ CompositeLogger
-
read / writeinherited
- maxPageSize ↔ int
-
read / writeinherited
- opened ↔ bool
-
read / writeinherited
-
persister
↔ JsonFilePersister<
T> -
read / write
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
-
saver
↔ ISaver<
T> ? -
read / writeinherited
Methods
-
clear(
String? correlationId) → Future -
Clears component state.
inherited
-
close(
String? correlationId) → Future -
Closes component and frees used resources.
inherited
-
configure(
ConfigParams config) → void -
Configures component by passing configuration parameters.
override
-
create(
String? correlationId, T item) → Future< T?> -
Creates a data item.
inherited
-
deleteByFilterEx(
String? correlationId, Function filter) → Future -
Deletes data items that match to a given filter.
inherited
-
getCountByFilterEx(
String? correlationId, Function? filter) → Future< int> -
Gets a count of data items retrieved by a given filter.
inherited
-
getListByFilterEx(
String? correlationId, Function? filter, Function? sort, dynamic select) → Future< List< T> > -
Gets a list of data items retrieved by a given filter and sorted according to sort parameters.
inherited
-
getOneRandom(
String? correlationId, Function? filter) → Future< T?> -
Gets a random item from items that match to a given filter.
inherited
-
getPageByFilterEx(
String? correlationId, Function? filter, PagingParams? paging, Function? sort, [dynamic select]) → Future< DataPage< T> > -
Gets a page of data items retrieved by a given filter and sorted according to sort parameters.
inherited
-
isOpen(
) → bool -
Checks if the component is opened.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited
-
open(
String? correlationId) → Future -
Opens the component.
inherited
-
save(
String? correlationId) → Future -
Saves items to external data source using configured saver component.
inherited
-
setReferences(
IReferences references) → void -
Sets references to dependent components.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited