Model<T extends Model<T>> class abstract

Implementers
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
resource → FlintDbResource

Available on T, provided by the FlintDbModelInstanceResourceExtension extension

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
count([String column = '*']) → Future<int>

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

Count matching rows without loading the whole result set.
countAll() → Future<int>

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

Count all records
countRelation(String name, {void constrain(QueryBuilder query)?, String column = '*'}) → Future<int>
Count related records without loading the relation.
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?>
firstOrCreate({required Map<String, dynamic> where, required Map<String, dynamic> values}) → Future<T?>

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

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
hasRelated(String name, {void constrain(QueryBuilder query)?}) → Future<bool>
Check whether at least one related record exists.
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>
Load multiple relations 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
loadRelationCount(String name, {String? as, void constrain(QueryBuilder query)?, String column = '*'}) → Future<T>
Count related records and store the count as an attribute on this 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
newInstance() → T
Creates a fresh instance of this model's concrete type.
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? desc}) → 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

orWhereOperator(String field, String operator, dynamic value) → T

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

OR WHERE with custom operator (full method)
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
relationCounts(String name, Map<String, void Function(QueryBuilder query)?> groups, {String column = '*'}) → Future<Map<String, int>>
Count the same relation multiple ways without repeating relation metadata.
relationQuery(String name, {void constrain(QueryBuilder query)?}) → QueryBuilder
Build a query for a relation using this model's relation definition.
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
setAttributes(Map<String, dynamic> attrs) → void
Set multiple attributes at once
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. Included null values clear columns; omitted attributes remain unchanged.
updateLegacy([dynamic id, Map<String, dynamic>? data]) → Future<T?>

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

upsert({Map<String, dynamic>? where, List<String>? uniqueBy, Map<String, dynamic>? data, Map<String, dynamic>? createData, Map<String, dynamic>? updateData, List<String>? excludeUpdatedData}) → Future<T?>

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

Universal upsert for Flint Dart Either uniqueBy or where must be provided.
upsertMany({required List<Map<String, dynamic>> records, required List<String> uniqueBy, List<String>? excludeUpdatedData, Map<String, dynamic> createDataBuilder(Map<String, dynamic> record)?, Map<String, dynamic> updateDataBuilder(Map<String, dynamic> record)?}) → 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