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. Defaults to the column with isPrimaryKey: true in _schemaColumns, or 'id' if not specified.
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
tableName → String
Table name for this model.
no setter
updatedAt → DateTime?
no setter

Methods

all() → Future<List<T>>
Get all records.
asMap() → Map<String, dynamic>
avg(String column) → Future<double?>
Get average value.
boolean(String name, {bool isNullable = false, bool? defaultValue, String? comment, String? after}) → Column
Adds a boolean column (e.g. BOOLEAN / TINYINT(1)) to the model's schema.
column(Column col) → Column
Appends a raw or custom Column definition to the model's schema.
convertDatabaseTypes(Map map) → Map<String, dynamic>
Convert database-specific types to Dart types safely, respecting the model's schema definition.
count([String column = '*']) → Future<int>
Count matching rows without loading the whole result set.
countAll() → Future<int>
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>
Count records with condition.
create([Map<String, dynamic>? data]) → Future<T?>
Insert new record (works for both PostgreSQL and MySQL).
datetime(String name, {bool isNullable = false, DateTime? defaultValue, String? comment, String? after}) → Column
Adds a datetime column to the model's schema.
delete([dynamic id]) → Future<bool>
Delete this model.
enumeration(String name, {required List<String> options, bool isNullable = false, String? defaultValue, String? comment, String? after}) → Column
Adds an enumeration column to the model's schema.
find(dynamic id) → Future<T?>
first() → Future<T?>
firstOrCreate({required Map<String, dynamic> where, required Map<String, dynamic> values}) → Future<T?>
firstWhere(String key, dynamic value) → Future<T?>
float(String name, {bool isNullable = false, double? defaultValue, String? comment, String? after}) → Column
Adds a double/float column to the model's schema.
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
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
integer(String name, {bool isNullable = false, bool isUnique = false, int? defaultValue, bool isPrimaryKey = false, bool isAutoIncrement = false, String? comment, String? after}) → Column
Adds an integer column (e.g. INT) to the model's schema.
jsonCol(String name, {bool isNullable = false, dynamic defaultValue, String? comment, String? after}) → Column
Adds a JSON column to the model's schema.
jsonField(String name, {bool isNullable = false, dynamic defaultValue, String? comment, String? after}) → Column
Alias for jsonCol.
limit(int value) → T
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
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.
longText(String name, {bool isNullable = false, String? defaultValue, String? comment, String? after}) → Column
Adds a long text column (e.g. LONGTEXT) to the model's schema.
max(String column) → Future
Get max value.
mediumText(String name, {bool isNullable = false, String? defaultValue, String? comment, String? after}) → Column
Adds a medium text column (e.g. MEDIUMTEXT) to the model's schema.
min(String column) → Future
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
OFFSET clause - chainable.
orderBy(String field, {bool? asc, bool? desc}) → T
ORDER BY clause - chainable with asc or desc options.
orWhere(String field, dynamic value) → T
OR WHERE clause - chainable.
orWhereContains(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
orWhereEndsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
orWhereLike(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
orWhereOperator(String field, String operator, dynamic value) → T
OR WHERE with custom operator - chainable.
orWhereStartsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
paginate(int page, [int perPage = 15]) → Future<Map<String, dynamic>>
Paginate results.
query() → QueryBuilder
Custom query builder - starts or continues a query chain.
refresh([dynamic id]) → Future<T?>
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?>
Save model (create or update).
schema() → void
Override this method to fluently define the model's database schema.
select(List<String> fields) → T
SELECT specific fields - chainable.
setAttribute(String key, dynamic value) → void
Set raw attribute
setAttributes(Map<String, dynamic> attrs) → void
Set multiple attributes at once
string(String name, {int length = 255, bool isNullable = false, bool isUnique = false, String? defaultValue, bool isPrimaryKey = false, String? comment, String? after}) → Column
Adds a string column (e.g. VARCHAR) to the model's schema.
sum(String column) → Future<double?>
Get sum value.
text(String name, {bool isNullable = false, String? defaultValue, String? comment, String? after}) → Column
Adds a text column (e.g. TEXT) to the model's schema.
textCol(String name, {bool isNullable = false, String? defaultValue, String? comment, String? after}) → Column
Alias for text to avoid naming collisions when UI packages are imported.
timestamp(String name, {bool isNullable = false, DateTime? defaultValue, String? comment, String? after}) → Column
Adds a timestamp column to the model's schema.
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>
Truncate table.
update({dynamic id, Map<String, dynamic>? data}) → Future<T?>
Update existing record.
updateLegacy([dynamic id, Map<String, dynamic>? data]) → Future<T?>
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?>
Universal upsert for Flint Dart.
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?>>
useTransaction(DBTransaction trx) → T
where(String field, dynamic value) → T
WHERE clause (field = value) - chainable.
whereBetween(String field, dynamic start, dynamic end) → T
whereContains(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
whereEndsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
whereIn(String field, List values) → T
WHERE IN clause - chainable.
whereInSimple(String field, List values) → Future<List<T>>
Simple where IN clause (non-chainable).
whereLike(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
whereNotBetween(String field, dynamic start, dynamic end) → T
whereNotIn(String field, List values) → T
WHERE NOT IN clause - chainable.
whereNotLike(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
whereNotNull(String field) → T
WHERE NOT NULL clause - chainable.
whereNull(String field) → T
WHERE NULL clause - chainable.
whereOperator(String field, String operator, dynamic value) → T
WHERE with custom operator - chainable.
whereSimple(String field, dynamic value) → Future<List<T>>
Simple where clause (non-chainable).
whereStartsWith(String field, String value, {bool caseSensitive = false, bool escape = true}) → T
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