ModelQuery<T extends Model> class
A type-safe query builder that returns model instances instead of raw maps.
Wraps the underlying QueryBuilder and automatically maps results to T.
final users = await ModelQuery<User>(db, User.fromRow)
.where('active', '=', true)
.orderBy('name')
.get();
Constructors
-
ModelQuery(DatabaseExecutor _executor, ModelFactory<
T> _factory, {String? tableName}) -
Creates a typed query for models of type
T.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
count(
) → Future< int> - Returns the count of matching rows.
-
create(
T model) → Future< T> -
Creates a new record from the model and returns the model with
idpopulated. -
deleteAll(
) → Future< int> - Deletes all rows matching the current query.
-
destroy(
dynamic id) → Future< void> - Deletes a model by its primary key.
-
destroyModel(
T model) → Future< void> - Deletes a model instance from the database.
-
exists(
) → Future< bool> - Checks if any rows match the current query.
-
find(
dynamic id) → Future< T?> -
Finds a model by its primary key
id. -
findOrFail(
dynamic id) → Future< T> - Finds a model by primary key or throws if not found.
-
first(
) → Future< T?> -
Returns the first matching model, or
nullif none found. -
get(
) → Future< List< T> > - Executes the query and returns all matching models.
-
groupBy(
String column) → ModelQuery< T> -
Adds a
GROUP BYclause. -
having(
String column, String operator, dynamic value) → ModelQuery< T> -
Adds a
HAVINGclause. -
join(
String table, String col1, String op, String col2) → ModelQuery< T> - Adds an INNER JOIN.
-
leftJoin(
String table, String col1, String op, String col2) → ModelQuery< T> - Adds a LEFT JOIN.
-
limit(
int value) → ModelQuery< T> -
Adds a
LIMITclause. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offset(
int value) → ModelQuery< T> -
Adds an
OFFSETclause. -
orderBy(
String column, [String direction = 'ASC']) → ModelQuery< T> -
Adds an
ORDER BYclause. -
orWhere(
String column, String operator, dynamic value) → ModelQuery< T> -
Adds an
OR WHEREclause. -
paginate(
{int page = 1, int perPage = 15}) → Future< PaginatedResult< T> > - Returns a paginated result.
-
save(
T model) → Future< T> - Updates an existing model in the database.
-
select(
List< String> columns) → ModelQuery<T> - Specifies which columns to select.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateAll(
Map< String, dynamic> data) → Future<int> - Performs a bulk update on all rows matching the current query.
-
where(
String column, String operator, dynamic value) → ModelQuery< T> -
Adds a
WHEREclause. -
whereIn(
String column, List values) → ModelQuery< T> -
Adds a
WHERE column IN (...)clause. -
whereNotNull(
String column) → ModelQuery< T> -
Adds a
WHERE column IS NOT NULLclause. -
whereNull(
String column) → ModelQuery< T> -
Adds a
WHERE column IS NULLclause.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited