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 aMap<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
Methods
-
changeDB(
String? newDBName) → Future< void> -
Switches the application database to
newDBName. -
checkIfEntityTableExists<
T> () → Future< bool> -
Returns
trueif the entity tableTexists. -
checkIfTableExists(
String table) → Future< bool> -
Returns
trueif a table namedtableexists. -
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 byafterWhere. -
createTableIfNotExists(
Object entity) → Future< void> -
Creates the entity table for
entityif it does not exist yet. -
deleteObjet<
T> ([String? afterWhere]) → Future< bool> -
Deletes rows of
TmatchingafterWhere. WhenafterWhereis 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
TmatchingwhereColumns/whereArgs. -
dropDB(
String dbPath) → Future< void> -
Deletes the database file located at
dbPath. -
dropTable<
T> () → Future< void> -
Drops the entity table
Tif it exists. -
get<
T> (Object tableEntityInstance, String afterWhere) → Future< T?> -
Returns a single entity of type
Tmatching theafterWhereclause, ornullwhen no row matches. -
getAColumnFrom<
C, T> (String columnName, {String? afterWhere}) → Future< List< C> > -
Returns every value of column
columnName(typed asC) from the entity tableT, optionally filtered byafterWhere. -
getAColumnFromWithTableName<
T> (String columnName, String table, {String? afterWhere}) → Future< List< T> > -
Like getAColumnFrom but accepts an arbitrary
tablename (or a join expression). Useful for querying non-entity tables such assqlite_masteror to run joined queries with table aliases. -
getAll<
T> (Object tableEntityInstance) → Future< List< T> ?> -
Returns every object of type
Tcurrently stored, ornullwhen the table is empty. -
getAllSorted<
T> (Object tableEntityInstance, String afterWhere) → Future< List< T> ?> -
Returns every object of type
TmatchingafterWhere, ornullwhen no row matches. -
getEntityColumnsName<
T> () → Future< List< String> > -
Returns the list of column names of the entity table
Tas 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=identifierValueandpasswordColumnName=passwordValueagainst the entity tableT. -
getSomeColumnsFrom<
T> (String listDesColonne, {String? afterWhere}) → Future< List< Map< >String, Object?> > -
Returns raw rows (as
List<Map<String, Object?>>) for the columnslistDesColonneof the entity tableT. -
getSommeColumnsWithTableName(
String listDesColonne, String table, {String? afterWhere}) → Future< List< Map< >String, Object?> > -
Like getSomeColumnsFrom but takes an arbitrary
tablename (or a join expression). Useful for non-entity tables or join queries. -
insertObjet(
Object? object) → Future< bool> -
Inserts
objectinto 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
dbPathand returns it. -
showCreateTable(
Object entity) → String -
Returns the
CREATE TABLEstatement generated forentitybased on the getters (pKeyAuto,notNulls,uniques,checks,defaults,fKeys) and the types declared intoMap(). -
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