Storage<T extends Entity> class
abstract
Abstract interface for entity storage backends.
This interface defines the contract that all storage implementations
must fulfill. It provides CRUD operations for entities with generic
type safety through the Entity bound.
Implementations
FileStorage: File-per-entity storage (development/small datasets)- PagedStorage: Page-based storage using the engine module (production)
- MemoryStorage: In-memory storage (testing)
Usage
// Storage is typically accessed through Collection<T>
final storage = await FileStorage<Product>.open(
directory: './data/products',
fromMap: Product.fromMap,
);
await storage.insert('prod-1', {'name': 'Widget', 'price': 29.99});
final data = await storage.get('prod-1');
Transaction Support
Storage implementations may support transactions through the TransactionalStorage mixin. Use supportsTransactions to check.
- Implementers
- Available extensions
Constructors
- Storage()
Properties
-
count
→ Future<
int> -
Returns the number of entities in storage.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isOpen → bool
-
Whether this storage backend is currently open.
no setter
- name → String
-
Unique name identifying this storage instance.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- supportsTransactions → bool
-
Whether this storage backend supports transactions.
no setter
Methods
-
beginTransaction(
{IsolationLevel isolationLevel = IsolationLevel.readCommitted}) → Future< Transaction< T> > -
Available on Storage<
Creates and starts a new transaction for this storage.T> , provided by the TransactionExtension extension -
close(
) → Future< void> - Closes the storage backend and releases resources.
-
delete(
String id) → Future< bool> - Deletes an entity by its identifier.
-
deleteAll(
) → Future< int> - Deletes all entities from storage.
-
deleteMany(
Iterable< String> ids) → Future<int> - Deletes multiple entities by their identifiers.
-
exists(
String id) → Future< bool> - Checks if an entity with the given ID exists.
-
flush(
) → Future< void> - Flushes any buffered writes to persistent storage.
-
get(
String id) → Future< Map< String, dynamic> ?> - Retrieves an entity by its unique identifier.
-
getAll(
) → Future< Map< String, Map< >String, dynamic> > - Retrieves all entities from storage.
-
getMany(
Iterable< String> ids) → Future<Map< String, Map< >String, dynamic> > - Retrieves multiple entities by their identifiers.
-
insert(
String id, Map< String, dynamic> data) → Future<void> - Inserts a new entity into storage.
-
insertMany(
Map< String, Map< entities) → Future<String, dynamic> >void> - Inserts multiple entities in a single operation.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
) → Future< void> - Initializes the storage backend.
-
stream(
) → Stream< StorageRecord> - Streams all entities from storage.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
String id, Map< String, dynamic> data) → Future<void> - Updates an existing entity in storage.
-
upsert(
String id, Map< String, dynamic> data) → Future<void> - Inserts or updates an entity.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited