DatabaseManager class

The Database Manager.

This singleton service manages the active database connection. It reads configuration from the app config and uses the appropriate connection factory based on the platform.

Initialization

The database is automatically initialized during Magic.init(). You can also initialize it manually:

await DatabaseManager().init();

Accessing the Connection

final db = DatabaseManager().connection;
final result = db.select('SELECT * FROM users');

Schema Cache

The manager caches table column information for schema-aware operations:

final columns = await DatabaseManager().getColumns('users');
// ['id', 'name', 'email', 'created_at', 'updated_at']

Constructors

DatabaseManager()
Factory constructor returns the singleton.
factory

Properties

connection → CommonDatabase
Get the active database connection.
no setter
hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
Whether the database has been initialized.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearSchemaCache([String? table]) → void
Clear the schema cache for a specific table or all tables.
dispose() → void
Close the database connection.
getColumns(String table) Future<List<String>>
Get the column names for a table.
hasColumn(String table, String column) Future<bool>
Check if a table has a specific column.
init() Future<void>
Initialize the database connection.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setConnection(CommonDatabase connection) → void
Inject a mock connection for testing.
toString() String
A string representation of this object.
inherited

Operators

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