Model<T extends Model<T> > class
abstract
- Implementers
- Available extensions
Constructors
- Model(T _factory())
Properties
-
cachedRelations
→ Map<
String, RelationDefinition< Model> > -
Cached relations definitions for this model type
no setter
-
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: truein_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.
-
filter(
String field, {dynamic equals, dynamic notEquals, dynamic greaterThan, dynamic gt, dynamic greaterThanOrEqual, dynamic gte, dynamic lessThan, dynamic lt, dynamic lessThanOrEqual, dynamic lte, dynamic contains, dynamic startsWith, dynamic endsWith, bool? isNull, bool? isNotNull}) → T - Filter with named operator arguments (no raw SQL operator strings):
-
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<
Type-safe relation accessor.T> , provided by the ModelRelations extension -
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 (supports nested dot notation like
user.profile) -
load(
String relation, {List< String> ? columns}) → Future<T> -
Available on Model<
Load a relation for this single model instance.T> , provided by the ModelRelations extension -
loadMany(
List< String> relations) → Future<T> - Load multiple relations for this single model
-
loadMany(
List< String> relations) → Future<T> -
Available on Model<
Load multiple relations for this single model instance.T> , provided by the ModelRelations extension -
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
ascordescoptions. -
orFilter(
String field, {dynamic equals, dynamic notEquals, dynamic greaterThan, dynamic gt, dynamic greaterThanOrEqual, dynamic gte, dynamic lessThan, dynamic lt, dynamic lessThanOrEqual, dynamic lte, dynamic contains}) → T - OR filter with named operator arguments
-
orWhere(
String field, dynamic operatorOrValue, [dynamic value = _modelWhereSentinel]) → T -
OR WHERE clause supporting both 2-arg (
field, value) and 3-arg (field, operator, value) - 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 -
orWhereEqual(
String field, dynamic value) → T -
OR equality condition:
orWhereEqual('status', 'active') -
orWhereFalse(
String field) → T -
OR boolean false condition:
orWhereFalse('is_blocked') -
orWhereLike(
String field, String value, {bool caseSensitive = false, bool escape = true}) → T -
orWhereNotEqual(
String field, dynamic value) → T -
OR inequality condition:
orWhereNotEqual('status', 'archived') -
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 -
orWhereTrue(
String field) → T -
OR boolean true condition:
orWhereTrue('is_admin') -
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< records, required List<String, dynamic> >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 operatorOrValue, [dynamic value = _modelWhereSentinel]) → T -
WHERE clause supporting both 2-arg (
field, value) and 3-arg (field, operator, 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 -
whereEqual(
String field, dynamic value) → T -
Equality condition without SQL operators:
whereEqual('status', 'active') -
whereFalse(
String field) → T -
Boolean false condition:
whereFalse('is_deleted') -
whereGreaterThan(
String field, dynamic value) → T -
Greater-than condition:
whereGreaterThan('age', 18) -
whereGreaterThanOrEqual(
String field, dynamic value) → T -
Greater-than-or-equal condition:
whereGreaterThanOrEqual('age', 18) -
whereGt(
String field, dynamic value) → T -
whereGte(
String field, dynamic value) → 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).
-
whereLessThan(
String field, dynamic value) → T -
Less-than condition:
whereLessThan('price', 100) -
whereLessThanOrEqual(
String field, dynamic value) → T -
Less-than-or-equal condition:
whereLessThanOrEqual('price', 100) -
whereLike(
String field, String value, {bool caseSensitive = false, bool escape = true}) → T -
whereLt(
String field, dynamic value) → T -
whereLte(
String field, dynamic value) → T -
whereNotBetween(
String field, dynamic start, dynamic end) → T -
whereNotEqual(
String field, dynamic value) → T -
Inequality condition without SQL operators:
whereNotEqual('status', 'archived') -
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 -
whereTrue(
String field) → T -
Boolean true condition:
whereTrue('is_active') -
withRelation(
String name, {List< String> ? columns}) → T - Chainable withRelation
-
withRelation(
String name, {List< String> ? columns}) → T -
Available on Model<
Add relation to eager load.T> , provided by the ModelRelations extension -
withRelations(
List< String> names) → T -
Available on Model<
Add multiple relations to eager load.T> , provided by the ModelRelations extension -
withRelations(
List< String> names) → T - Chainable withRelations for multiple
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
looksLikeDateTime(
String value) → bool