Model<T extends Model<T>> class abstract

Available extensions

Constructors

Model(T _factory())

Properties

conceal List<String>
Concealed fields that should not appear in toMap()
no setter
createdAt DateTime?
no setter
hashCode int
The hash code for this object.
no setterinherited
id → dynamic
no setter
primaryKey String
Primary key column
no setter
qb QueryBuilder
Get or create query builder
no setter
relations Map<String, RelationDefinition<Model>>
Relations definition
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
table Table
Table schema definition
no setter
updatedAt DateTime?
no setter

Methods

all() Future<List<T>>

Available on Model<T>, provided by the ModelCrud extension

Get all records
asMap() Map<String, dynamic>
avg(String column) Future<double?>

Available on Model<T>, provided by the ModelQuery extension

Get average value
countAll() Future<int>

Available on Model<T>, provided by the ModelCrud extension

Count all records
countWhere(String field, dynamic value) Future<int>

Available on Model<T>, provided by the ModelCrud extension

Count records with condition
create([Map<String, dynamic>? data]) Future<T?>

Available on Model<T>, provided by the ModelCrud extension

Insert new record (works for both PostgreSQL and MySQL)
delete([dynamic id]) Future<bool>

Available on Model<T>, provided by the ModelCrud extension

Delete this model
find(dynamic id) Future<T?>
first() Future<T?>
firstWhere(String key, dynamic value) Future<T?>
fromJson(String json) → T
fromMap(Map map) → T
Convert DB map into a model instance
get() Future<List<T>>
getAttribute<R>(String key) → R?
Read raw attribute
getRelation<R>(String name) → R?

Available on Model<T>, provided by the ModelRelations extension

Type-safe relation accessor
getRelation<R>(String name) → R?
Get loaded relation
getRelationOrLoad<R>(String name) Future<R>
Get relation or load it if not loaded
getWhere(String key, dynamic value) Future<List<T>>
groupBy(String field) → T

Available on Model<T>, provided by the ModelQuery extension

GROUP BY clause - chainable
hasRelation(String name) bool
Check if relation is loaded
limit(int value) → T

Available on Model<T>, provided by the ModelQuery extension

LIMIT clause - chainable
load(String relation, {List<String>? columns}) Future<T>
Load a relation for this single model
loadMany(List<String> relations) Future<T>

Available on Model<T>, provided by the ModelRelations extension

Load a relation for this single model Load multiple relations
loadMany(List<String> relations) Future<T>
Load multiple relations for this single model
max(String column) Future

Available on Model<T>, provided by the ModelQuery extension

Get max value
min(String column) Future

Available on Model<T>, provided by the ModelQuery extension

Get min value
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offset(int value) → T

Available on Model<T>, provided by the ModelQuery extension

OFFSET clause - chainable
orderBy(String field, {bool? asc, bool? descending}) → T

Available on Model<T>, provided by the ModelQuery extension

ORDER BY clause - chainable Chainable orderBy with both asc and descending options
orWhere(String field, dynamic value) → T

Available on Model<T>, provided by the ModelQuery extension

OR WHERE clause - chainable
orWhereContains(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

orWhereEndsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

orWhereLike(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

orWhereStartsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

paginate(int page, [int perPage = 15]) Future<Map<String, dynamic>>

Available on Model<T>, provided by the ModelQuery extension

Paginate results
query() QueryBuilder

Available on Model<T>, provided by the ModelQuery extension

Internal query builder instance for chaining Execute the query and get results - FIXED Get first result - FIXED Custom query builder - starts a new chain
refresh([dynamic id]) Future<T?>

Available on Model<T>, provided by the ModelCrud extension

Refresh the model from DB
resetQuery() → T
Reset query builder
runExecute(String sql, {List? positionalParams, Map<String, dynamic>? namedParams}) Future<void>
Internal: execute command (transaction-aware)
runQuery(String sql, {List? positionalParams, Map<String, dynamic>? namedParams}) Future<List<Map<String, dynamic>>>
Internal: execute query (transaction-aware)
save() Future<T?>

Available on Model<T>, provided by the ModelCrud extension

Save model (create or update)
select(List<String> fields) → T

Available on Model<T>, provided by the ModelQuery extension

SELECT specific fields - chainable
setAttribute(String key, dynamic value) → void
Set raw attribute
sum(String column) Future<double?>

Available on Model<T>, provided by the ModelQuery extension

Get sum value
toJson() String
toMap() Map<String, dynamic>
Returns the safe map including concealed filter and timestamps
toString() String
A string representation of this object.
inherited
truncate() Future<void>

Available on Model<T>, provided by the ModelCrud extension

Truncate table
update([dynamic id, Map<String, dynamic>? data]) Future<T?>

Available on Model<T>, provided by the ModelCrud extension

Update existing record using the helper method
upsert({required Map<String, dynamic> where, required Map<String, dynamic> data}) Future<T?>

Available on Model<T>, provided by the ModelCrud extension

upsertMany({required List<Map<String, dynamic>> records, required List<String> uniqueBy}) Future<List<T?>>

Available on Model<T>, provided by the ModelCrud extension

useTransaction(DBTransaction trx) → T
where(String field, dynamic value) → T

Available on Model<T>, provided by the ModelQuery extension

WHERE clause - chainable
whereBetween(String field, dynamic start, dynamic end) → T

Available on Model<T>, provided by the ModelQuery extension

whereContains(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

whereEndsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

whereIn(String field, List values) → T

Available on Model<T>, provided by the ModelQuery extension

WHERE IN clause - chainable
whereInSimple(String field, List values) Future<List<T>>

Available on Model<T>, provided by the ModelCrud extension

Simple where IN clause (non-chainable)
whereLike(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

whereNotBetween(String field, dynamic start, dynamic end) → T

Available on Model<T>, provided by the ModelQuery extension

whereNotIn(String field, List values) → T

Available on Model<T>, provided by the ModelQuery extension

WHERE NOT IN clause - chainable
whereNotLike(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

whereNotNull(String field) → T

Available on Model<T>, provided by the ModelQuery extension

WHERE NOT NULL clause - chainable
whereNull(String field) → T

Available on Model<T>, provided by the ModelQuery extension

WHERE NULL clause - chainable
whereOperator(String field, String operator, dynamic value) → T

Available on Model<T>, provided by the ModelQuery extension

WHERE with custom operator - chainable
whereSimple(String field, dynamic value) Future<List<T>>

Available on Model<T>, provided by the ModelCrud extension

Simple where clause (non-chainable)
whereStartsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T

Available on Model<T>, provided by the ModelQuery extension

withRelation(String name, {List<String>? columns}) → T

Available on Model<T>, provided by the ModelRelations extension

Add relation to eager load
withRelation(String name, {List<String>? columns}) → T
Chainable withRelation
withRelations(List<String> names) → T
Chainable withRelations for multiple

Operators

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

Static Methods

looksLikeDateTime(String value) bool