DataAccess class

High-level API for persisting Dart objects into a local SQLite database.

DataAccess is a singleton: always access it through DataAccess.instance. It abstracts the differences between mobile platforms (Android, iOS, macOS), which use the native sqflite plugin, and desktop platforms (Linux, Windows), which use sqflite_common_ffi.

Entities exposed to this API are plain Dart classes that declare:

  • A toMap() method returning a Map<String, dynamic>.
  • A named constructor fromMap(Map<String, Object?>).
  • An instance method fromMap(Map<String, Object?>) used by generic getters.
  • Optional getters: pKeyAuto, notNulls, uniques, checks, defaults, fKeys.

See the package README for a complete usage example.

Properties

db → Future<Database>
Opens (or returns the already opened) application database.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

changeDB(String? newDBName) → Future<void>
Switches the application database to newDBName.
checkIfEntityTableExists<T>() → Future<bool>
Returns true if the entity table T exists.
checkIfTableExists(String table) → Future<bool>
Returns true if a table named table exists.
cleanAllTablesData() → Future<void>
Removes every row from every user-defined table of the database. The tables themselves are kept.
closeDB() → Future<void>
Closes the current application database (if any).
countElementsOf<T>({String expression = '*', String? afterWhere}) → Future<int>
Counts rows of T, optionally filtered by afterWhere.
createTableIfNotExists(Object entity) → Future<void>
Creates the entity table for entity if it does not exist yet.
deleteObjet<T>([String? afterWhere]) → Future<bool>
Deletes rows of T matching afterWhere. When afterWhere is null every row of the table is removed (the table itself is preserved).
delObjet<T>(List<String> whereColumns, List<Object> whereArgs, {String whereMcop = 'AND'}) → Future<bool>
Deletes every row of T matching whereColumns / whereArgs.
dropDB(String dbPath) → Future<void>
Deletes the database file located at dbPath.
dropTable<T>() → Future<void>
Drops the entity table T if it exists.
get<T>(Object tableEntityInstance, String afterWhere) → Future<T?>
Returns a single entity of type T matching the afterWhere clause, or null when no row matches.
getAColumnFrom<C, T>(String columnName, {String? afterWhere}) → Future<List<C>>
Returns every value of column columnName (typed as C) from the entity table T, optionally filtered by afterWhere.
getAColumnFromWithTableName<T>(String columnName, String table, {String? afterWhere}) → Future<List<T>>
Like getAColumnFrom but accepts an arbitrary table name (or a join expression). Useful for querying non-entity tables such as sqlite_master or to run joined queries with table aliases.
getAll<T>(Object tableEntityInstance) → Future<List<T>?>
Returns every object of type T currently stored, or null when the table is empty.
getAllSorted<T>(Object tableEntityInstance, String afterWhere) → Future<List<T>?>
Returns every object of type T matching afterWhere, or null when no row matches.
getEntityColumnsName<T>() → Future<List<String>>
Returns the list of column names of the entity table T as currently stored in SQLite. Useful to detect schema drift (columns added or removed on the Dart side).
getLogin<T>(Object tableEntityInstance, String identifierColumnName, String identifierValue, String passwordColumnName, String passwordValue) → Future<T?>
Authenticates a user by matching identifierColumnName=identifierValue and passwordColumnName=passwordValue against the entity table T.
getSomeColumnsFrom<T>(String listDesColonne, {String? afterWhere}) → Future<List<Map<String, Object?>>>
Returns raw rows (as List<Map<String, Object?>>) for the columns listDesColonne of the entity table T.
getSommeColumnsWithTableName(String listDesColonne, String table, {String? afterWhere}) → Future<List<Map<String, Object?>>>
Like getSomeColumnsFrom but takes an arbitrary table name (or a join expression). Useful for non-entity tables or join queries.
insertObjet(Object? object) → Future<bool>
Inserts object into its corresponding table.
insertObjetList(List<Object?>? objectlist) → Future<bool>
Inserts a list of entity objects into their corresponding table.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openDB(String dbPath) → Future<Database>
Opens a database located at dbPath and returns it.
showCreateTable(Object entity) → String
Returns the CREATE TABLE statement generated for entity based on the getters (pKeyAuto, notNulls, uniques, checks, defaults, fKeys) and the types declared in toMap().
toString() → String
A string representation of this object.
inherited
updateSomeColumnsOf<T>(List<String> columnsToUpadate, List<String> whereColumns, List<Object> values, {String whereMcop = 'AND'}) → Future<bool>
Updates one or more columns of the entity T.
updateWholeObject(Object newObject, List<String> whereColumns, List<Object> values, {String whereMcop = 'AND'}) → Future<bool>
Updates every column of an entity instance except the primary key.

Operators

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

Static Properties

instance → DataAccess
Global singleton instance.
final