DBHelper class abstract

Enhanced database helper with better error handling and modern features

Implementers

Constructors

DBHelper(String table)

Properties

database → Future<Database>
Get the database instance
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
table → String
final

Methods

all({int? paginate}) → Future<List<Model>?>
Get all records with optional pagination
avg(String columnName) → Future<double?>
Get average value of a column
belongsTo(String relatedTable, String relatedColumn) → DBHelper
Add a belongsTo relationship
belongsToMany(String relatedTable, String pivotTable, {required String tableId, required String relatedId}) → DBHelper
Add a belongsToMany relationship
count() → Future<int>
Count records
delete(int id) → Future<int>
Delete a record by ID
distinct() → DBHelper
Set DISTINCT
erase() → Future<void>
Delete all records from the table
find(int id) → Future<Model?>
Find a record by ID
first({int? paginate}) → Future<Model?>
Get the first record
fromMap(Map map) → Model
getBool(int value) → bool
Get boolean from integer
getDateTime(String dateTime) → DateTime
Get DateTime from string
groupBy(String column) → DBHelper
Add GROUP BY clause
hasMany(String relatedTable, String relatedColumn) → DBHelper
Add a hasMany relationship
hasOne() → DBHelper
Add a hasOne relationship
having(String condition, [List? arguments]) → DBHelper
Add HAVING clause
insert() → Future<Model?>
Insert a new record
last({int? paginate}) → Future<Model?>
Get the last record
limit(int count, [int offset = 0]) → DBHelper
Set LIMIT and OFFSET
max(String columnName) → Future
Get maximum value of a column
min(String columnName) → Future
Get minimum value of a column
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
orderBy({String? column = "created_at", DatabaseOrder? order = DatabaseOrder.ascending}) → DBHelper
Add ORDER BY clause
orWhere(String column, {dynamic value, String operator = "="}) → DBHelper
Add an OR WHERE condition
pluck(dynamic column) → Future
Extract specific column values
rawQuery(String query, [List? arguments]) → Future<DBHelper>
Execute a raw SQL query
reset() → void
Reset the query builder state
select(dynamic columns) → DBHelper
Select specific columns
sum(String columnName) → Future<num?>
Get sum of a column
toMap() → Map<String, Object?>
Abstract methods that must be implemented
toString() → String
A string representation of this object.
inherited
transaction<T>(Future<T> action(Transaction txn)) → Future<T>
Execute a transaction
update(int id) → Future<int>
Update an existing record
where(String column, {dynamic value, String operator = "="}) → DBHelper
Add a WHERE condition
whereBetween(String column, dynamic start, dynamic end) → DBHelper
Add a WHERE BETWEEN condition
whereIn(String column, List values) → DBHelper
Add a WHERE IN condition
whereLike(String column, String pattern) → DBHelper
Add a WHERE LIKE condition
whereNotIn(String column, List values) → DBHelper
Add a WHERE NOT IN condition
whereNotNull(String column) → DBHelper
Add a WHERE NOT NULL condition
whereNull(String column) → DBHelper
Add a WHERE NULL condition

Operators

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