SqliteLocalRepository<T extends CloudSyncable> class
abstract
A repository for storing and managing CloudSyncable entities in a local SQLite database.
This class provides methods for creating, reading, updating, deleting,
and syncing entities
between the local database and a remote cloud storage.
It uses the Database
to manage the database connection and table creation.
- Implemented types
Constructors
-
SqliteLocalRepository.new({required Database database, required T fromJson(Map<
String, dynamic> ), required String tableName}) - Creates a SqliteLocalRepository instance.
Properties
- createDatabaseTableSQL → String
-
Returns the SQL statement to create the entire table,
including entity-specific fields.
no setter
- database → Database
-
The helper class for managing the database connection.
final
-
fromJson
→ T Function(Map<
String, dynamic> ) -
A function to convert a JSON map into a
T
object.final - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tableName → String
-
The name of the table in the SQLite database
where the entities are stored.
final
Methods
-
addOrUpdate(
List< T> items, {bool fromCloud = false}) → Future<void> -
Adds or updates the given
items
in the local database. IffromCloud
is true, it indicates that the items are being synced from the cloud.override -
clearAll(
) → Future< void> -
Clears all CloudSyncable entities of type
T
from the local repository.override -
create(
T item) → Future< T> -
Creates a new
item
in the local database. Returns the created item with its generated ID.override -
createTable(
Database db) → Future< void> - Creates the table in the database if it doesn't already exist.
-
delete(
String id) → Future< void> -
Marks the item with the given
id
as deleted in the local database.override -
getAll(
{dynamic filter}) → Future< List< T> > -
Retrieves all items from the local database,
optionally filtered by
filter
. Thefilter
can be any type of object that your repository implementation can use for filtering (e.g., aMap<String, dynamic>
or a custom filter class).override -
getById(
String id) → Future< T?> -
Retrieves the item with the given
id
from the local database. Returns null if the item is not found.override -
getLastSyncServerTime(
) → Future< DateTime?> -
Retrieves the server timestamp of the last successful sync.
override
-
getOtherFieldsInSQL(
) → String - This method should be implemented by subclasses to provide the SQL for creating entity-specific fields in the table.
-
getUnsyncedItems(
{int? limit}) → Future< List< T> > -
Retrieves a list of unsynced items from the local database,
optionally limiting
the number of items to
limit
.override -
markAllUnsynced(
) → Future< void> -
Marks all CloudSyncable entities of type
T
as unsynced in the local repository.override -
markSynced(
List< String> ids, DateTime serverTimeSyncedAt) → Future<void> -
Marks the items with the given
ids
as synced at the givenserverTimeSyncedAt
time.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
T item) → Future< T> -
Updates an existing
item
in the local database. Returns the updated item.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getDatabaseCreationSQLForSyncable(
) → String -
Returns the SQL statement to create the table
for CloudSyncable entities.
This includes common fields like
id
,created_at
,updated_at
, etc.