DatumPersistence class abstract

Abstract interface for persistent storage of Datum sync metadata and configuration.

This interface provides a unified way to store and retrieve sync-related data across different storage backends (Hive, SharedPreferences, SQLite, etc.). It supports both synchronous and asynchronous operations, as well as streaming for real-time updates.

Usage

By default, Datum uses an in-memory persistence layer. To use persistent storage, implement this interface and pass it to Datum.initialize:

// Custom implementation (e.g., Hive, SharedPreferences, SQLite)
class MyPersistence implements DatumPersistence {
  // Implement all required methods...
}

await Datum.initialize(
  config: DatumConfig(...),
  connectivityChecker: MyConnectivityChecker(),
  persistence: MyPersistence(), // Use custom persistence
  registrations: [...],
);

Built-in Implementations

  • InMemoryDatumPersistence: Default in-memory storage (data lost on restart)
  • HiveDatumPersistence: Hive-based persistent storage (in example app)

Implementations should handle serialization/deserialization of complex objects and provide thread-safe operations where necessary.

Implementers

Constructors

DatumPersistence()

Properties

hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
Checks if the persistence layer is ready for operations.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearAllData() Future<void>
Clears all stored data.
clearUserData(String userId) Future<void>
Clears all data for a specific user.
deleteConfig(String key) Future<void>
Deletes configuration data.
deleteData(String key) Future<void>
Deletes arbitrary data by key.
deleteSyncMetadata(String userId) Future<void>
Deletes sync metadata for a specific user.
dispose() Future<void>
Closes the persistence layer and releases any resources.
getAllUserIds() Future<Set<String>>
Gets all user IDs that have stored data.
getConfig(String key) Future
Retrieves configuration data.
getData(String key) Future
Retrieves arbitrary data by key.
getStorageStats() Future<Map<String, dynamic>?>
Gets storage statistics (optional implementation).
getSyncMetadata(String userId) Future<DatumSyncMetadata?>
Retrieves sync metadata for a specific user.
initialize() Future<void>
Initializes the persistence layer.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
saveConfig(String key, dynamic value) Future<void>
Stores configuration data.
saveData(String key, dynamic value) Future<void>
Stores arbitrary data with a key.
saveSyncMetadata(String userId, DatumSyncMetadata metadata) Future<void>
Stores sync metadata for a specific user.
toString() String
A string representation of this object.
inherited
watchConfig(String key) Stream
Returns a stream of configuration changes for a specific key.
watchData(String key) Stream
Returns a stream of data changes for a specific key.
watchSyncMetadata(String userId) Stream<DatumSyncMetadata?>
Returns a stream of sync metadata changes for a specific user.

Operators

operator ==(Object other) bool
The equality operator.
inherited