Model class abstract

Base model class for SQLite Handler

This class provides the foundation for all data models in your application. Extend this class to create your own models.

Example:

class User extends Model {
  User({required super.table});
  
  @override
  Map<String, Object?> toMap() => {
    'id': id,
    'name': name,
    'email': email,
  };
  
  @override
  Model fromMap(Map<dynamic, dynamic> map) => User(
    table: tableName,
  )..id = map['id'] as int? ?? 0
    ..name = map['name'] as String? ?? ''
    ..email = map['email'] as String? ?? '';
}
Inheritance

Constructors

Model.new({required String table})

Properties

database Future<Database>
Get the database instance
no setterinherited
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
finalinherited
tableName String
Get the table name for this model
no setter

Methods

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

Operators

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