Query<T extends OrmEntity> class
Fluent builder for filtering, ordering, paginating, and eager-loading
models of type T.
The Query class provides a powerful and flexible API for constructing
database queries in a fluent manner. It supports a wide range of operations
including WHERE clauses, JOINs, ORDER BY, LIMIT, OFFSET,
eager loading of relations, and various aggregation functions.
Queries are executed against a QueryContext which provides the underlying database driver and model definitions.
Example:
final users = await context.query<User>()
.where('active', equals: true)
.orderBy('name')
.get();
final activePosts = await context.query<Post>()
.joinRelation('author')
.where('author.isActive', true)
.get();
- Available extensions
- AggregateExtension
- BatchOperationsExtension
- CrudExtension
- DistinctExtension
- GroupingExtension
- IndexExtension
- JoinExtension
- JsonExtension
- LockExtension
- MapQueryExtensions
- OrderExtension
- PaginateExtension
- QueryCachingExtension
- RawQueryExtension
- RelationExtension
- ScopeExtension
- SelectExtension
- SoftDeleteExtension
- StreamingExtension
- SubqueryExtension
- UnionExtension
- UtilityExtension
- WhereExtension
Constructors
-
Query({required ModelDefinition<
T> definition, required QueryContext context, List<FilterClause> ? filters, List<OrderClause> ? orders, List<RawOrderExpression> ? rawOrders, List<CustomOrderExpression> ? customOrders, List<RelationLoad> ? relations, List<JoinDefinition> ? joins, List<IndexHint> ? indexHints, List<FullTextWhere> ? fullTextWheres, List<JsonWhereClause> ? jsonWheres, List<DateWhereClause> ? dateWheres, bool randomOrder = false, num? randomSeed, String? lockClause, int? limit, int? offset, QueryPredicate? predicate, List<String> ? selects, List<RawSelectExpression> ? rawSelects, List<CustomSelectExpression> ? customSelects, List<ProjectionOrderEntry> ? projectionOrder, List<AggregateExpression> ? aggregates, List<String> ? groupBy, List<RawGroupByExpression> ? rawGroupBy, List<CustomGroupByExpression> ? customGroupBy, QueryPredicate? having, List<RelationAggregate> ? relationAggregates, List<RelationOrder> ? relationOrders, Map<String, RelationPath> ? relationPaths, Set<String> ? ignoredScopes, bool globalScopesApplied = false, bool ignoreAllGlobalScopes = false, String? tableAlias, List<String> ? adHocScopes, Map<String, RelationJoinRequest> ? relationJoinRequests, GroupLimit? groupLimit, bool distinct = false, List<DistinctOnClause> ? distinctOn, List<QueryUnion> ? unions, Duration? cacheTtl, bool disableCache = false, bool disableAutoHydration = false, bool suppressEvents = false})
Properties
-
adHocScopes
→ List<
String> -
no setter
-
adHocScopes
→ List<
String> -
Available on Query<
Returns the list of ad-hoc scopes to apply.T> , provided by the UtilityExtension extensionno setter - context → QueryContext
-
final
-
definition
→ ModelDefinition<
T> -
final
- disableAutoHydration → bool
-
Whether auto-hydration of model columns is disabled for this query.
no setter
- globalScopesApplied → bool
-
no setter
- globalScopesApplied → bool
-
Available on Query<
Returns whether all global scopes have been applied to this query.T> , provided by the UtilityExtension extensionno setter - hashCode → int
-
The hash code for this object.
no setterinherited
- ignoreAllGlobalScopes → bool
-
no setter
- ignoreAllGlobalScopes → bool
-
Available on Query<
Returns whether all global scopes should be ignored for this query.T> , provided by the UtilityExtension extensionno setter -
ignoredGlobalScopes
→ Set<
String> -
no setter
-
ignoredGlobalScopes
→ Set<
String> -
Available on Query<
Returns the set of global scope identifiers that should be ignored.T> , provided by the UtilityExtension extensionno setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- suppressEvents → bool
-
Whether model events are suppressed for this query.
no setter
Methods
-
addSelect(
String column) → Query< T> -
Available on Query<
Adds a single column to the select projection.T> , provided by the SelectExtension extension -
applySoftDeleteFilter(
FieldDefinition field) → Query< T> -
avg(
String expression, {String? alias}) → Query< T> -
Available on Query<
Adds anT> , provided by the AggregateExtension extensionAVGaggregate to the select projection. -
avgValue(
String expression, {String? alias}) → Future< num?> -
Available on Query<
Executes anT> , provided by the AggregateExtension extensionAVGaggregate and returns the result. -
chunk(
int size, ChunkCallback< T> callback, {int startPage = 1}) → Future<void> -
Available on Query<
Iterates rows in fixed-size chunks, invokingT> , provided by the PaginateExtension extensioncallbackfor each batch. -
chunkById(
int size, ChunkCallback< T> callback, {String? column}) → Future<void> -
Available on Query<
Iterates rows ordered byT> , provided by the PaginateExtension extensioncolumn(defaults to the primary key). -
count(
{String expression = '*'}) → Future< int> -
Available on Query<
Returns the number of rows that match the current query.T> , provided by the UtilityExtension extension -
countAggregate(
{String expression = '*', String? alias}) → Query< T> -
Available on Query<
Adds aT> , provided by the AggregateExtension extensionCOUNTaggregate to the select projection. -
create(
Map< String, dynamic> attributes) → Future<T> -
Available on Query<
Creates a single record from the given attributes map. Returns the created model instance with its generated ID.T> , provided by the CrudExtension extension -
createMany(
List< Map< records) → Future<String, dynamic> >List< T> > -
Available on Query<
Creates multiple records from a list of attribute maps. Returns the created model instances with their generated IDs.T> , provided by the CrudExtension extension -
crossJoin(
Object table, [Object? constraint, Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds a CROSS JOIN clause to the query. WhenT> , provided by the JoinExtension extensionconstraintis omitted, a simpleCROSS JOIN tableis emitted. -
crossJoinSub(
Query query, String alias, [Object? constraint, Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds a CROSS JOIN against a subquery.T> , provided by the JoinExtension extension -
cursorPaginate(
{int perPage = 15, Object? cursor, String? column, bool descending = false}) → Future< CursorPageResult< T> > -
Available on Query<
Cursor-based pagination that resumes fromT> , provided by the PaginateExtension extensioncursorwhen present. -
debugPlan(
) → QueryPlan - Exposes the built plan for tests.
-
decrement(
String column, [num amount = 1]) → Future< int> -
Available on Query<
Decrements the value of a numericT> , provided by the CrudExtension extensioncolumnbyamount. -
delete(
) → Future< int> -
Available on Query<
Deletes all records matching the query conditions.T> , provided by the CrudExtension extension -
deleteReturning(
) → Future< List< T> > -
Available on Query<
Deletes matching rows and returns hydrated models when the driver supports RETURNING.T> , provided by the CrudExtension extension -
deleteWhere(
Object where) → Future< int> -
Available on Query<
Deletes records matching a flexible where input (PK, map, DTO, partial, tracked model).T> , provided by the CrudExtension extension -
deleteWhereMany(
List< Object> wheres) → Future<int> -
Available on Query<
Deletes multiple records using flexible where inputs.T> , provided by the CrudExtension extension -
deleteWhereManyReturning(
List< Object> wheres) → Future<List< T> > -
Available on Query<
Deletes multiple records using flexible where inputs and returns hydrated models.T> , provided by the CrudExtension extension -
deleteWhereReturning(
Object where) → Future< List< T> > -
Available on Query<
Deletes records using flexible where inputs and returns hydrated models.T> , provided by the CrudExtension extension -
destroy(
dynamic ids) → Future< int> -
Available on Query<
Deletes records by their primary key(s). Accepts a single ID or a list of IDs. Returns the number of deleted rows.T> , provided by the CrudExtension extension -
distinct(
[Iterable< String> columns = const []]) → Query<T> -
Available on Query<
Applies DISTINCT (and optional DISTINCT ON) semantics to the select.T> , provided by the DistinctExtension extension -
doesntExist(
) → Future< bool> -
Available on Query<
ReturnsT> , provided by the UtilityExtension extensiontrueif no rows match the current query. -
dontRemember(
) → Query< T> -
Available on Query<
Disable caching for this query (even if parent had caching).T> , provided by the QueryCachingExtension extension -
each(
Future< void> callback(T model), {int chunkSize = 100}) → Future<void> -
Available on Query<
Iterates over query results with a callback.T> , provided by the StreamingExtension extension -
eachById(
int size, RowCallback< T> callback, {String? column}) → Future<void> -
Available on Query<
Visits each row individually in ID order using chunkById under the hood.T> , provided by the PaginateExtension extension -
exists(
) → Future< bool> -
Available on Query<
ReturnsT> , provided by the UtilityExtension extensiontrueif any rows match the current query. -
find(
Object key) → Future< T?> -
Available on Query<
Finds a model by its primary key.T> , provided by the CrudExtension extension -
findMany(
Iterable< Object> keys) → Future<List< T> > -
Available on Query<
Finds multiple models by their primary keys.T> , provided by the CrudExtension extension -
findOrFail(
Object key) → Future< T> -
Available on Query<
Finds a model by primary key or throws when missing.T> , provided by the CrudExtension extension -
first(
) → Future< T?> -
Available on Query<
Returns the first model instance orT> , provided by the CrudExtension extensionnullwhen no rows exist. -
firstOrCreate(
Map< String, dynamic> attributes, [Map<String, dynamic> values = const {}]) → Future<T> -
Available on Query<
Finds the first record matching the attributes, or creates it if not found.T> , provided by the CrudExtension extension -
firstOrFail(
{Object? key}) → Future< T> -
Available on Query<
Returns the first model or throws when no records exist.T> , provided by the CrudExtension extension -
firstOrNull(
) → Future< T?> -
Available on Query<
Alias for first to match Laravel naming.T> , provided by the CrudExtension extension -
firstPartial<
P extends PartialEntity< (T> >P factory(Map< String, Object?> )) → Future<P?> -
Available on Query<
Returns the first result as a partial entity orT> , provided by the CrudExtension extensionnullif none exist. -
firstRow(
) → Future< QueryRow< T> ?> -
Available on Query<
Returns the first matching row orT> , provided by the CrudExtension extensionnullif none exist. -
forceDelete(
) → Future< int> -
Available on Query<
Permanently deletes models that match the current query constraints, bypassing soft deletes.T> , provided by the SoftDeleteExtension extension -
forceIndex(
List< String> indexes) → Query<T> -
Available on Query<
Applies a FORCE INDEX hint (MySQL/MariaDB only).T> , provided by the IndexExtension extension -
get(
) → Future< List< T> > -
Available on Query<
Returns only the models without the surrounding QueryRow metadata.T> , provided by the CrudExtension extension -
getPartial<
P extends PartialEntity< (T> >P factory(Map< String, Object?> )) → Future<List< P> > -
Available on Query<
Returns results hydrated into partial entities.T> , provided by the CrudExtension extension -
groupBy(
List< String> columns) → Query<T> -
Available on Query<
Groups rows by the providedT> , provided by the GroupingExtension extensioncolumns. -
groupByExtension(
String key, [Object? payload]) → Query< T> -
Available on Query<
Adds a custom GROUP BY expression compiled by a driver extension.T> , provided by the GroupingExtension extension -
groupByRaw(
String sql, [List< Object?> bindings = const []]) → Query<T> -
Available on Query<
Adds a raw GROUP BY expression.T> , provided by the RawQueryExtension extension -
having(
String field, PredicateOperator operator, Object? value) → Query< T> -
Available on Query<
Adds a HAVING predicate over grouped rows.T> , provided by the GroupingExtension extension -
havingBitwise(
String field, String operator, Object value) → Query< T> -
Available on Query<
Adds a HAVING clause with a bitwise operator.T> , provided by the GroupingExtension extension -
havingExtension(
String key, [Object? payload]) → Query< T> -
Available on Query<
Adds a custom HAVING predicate compiled by a driver extension.T> , provided by the GroupingExtension extension -
havingRaw(
String sql, [List< Object?> bindings = const []]) → Query<T> -
Available on Query<
Adds a raw HAVING fragment.T> , provided by the GroupingExtension extension -
ignoreIndex(
List< String> indexes) → Query<T> -
Available on Query<
Applies an IGNORE INDEX hint (MySQL/MariaDB only).T> , provided by the IndexExtension extension -
increment(
String column, [num amount = 1]) → Future< int> -
Available on Query<
Increments the value of a numericT> , provided by the CrudExtension extensioncolumnbyamount. -
insertGetIds(
List< T> records) → Future<List< int> > -
Available on Query<
Inserts multiple records and returns all generated IDs.T> , provided by the BatchOperationsExtension extension -
insertInput(
Object input, {bool ignoreConflicts = false}) → Future< T> -
Available on Query<
T> , provided by the CrudExtension extension -
insertManyInputs(
List< Object> inputs, {bool ignoreConflicts = false, bool returning = true, bool fallbackToOriginalWhenNoReturn = true}) → Future<List< T> > -
Available on Query<
Inserts flexible inputs and returns hydrated models.T> , provided by the CrudExtension extension -
insertManyInputsRaw(
List< Object> inputs, {bool ignoreConflicts = false}) → Future<MutationResult> -
Available on Query<
Inserts flexible inputs and returns the raw MutationResult.T> , provided by the CrudExtension extension -
insertOrIgnoreUsing(
Iterable< String> columns, Query source) → Future<int> -
Available on Query<
Inserts rows into this query's table using the results ofT> , provided by the UnionExtension extensionsource, ignoring duplicate key errors. -
insertUsing(
Iterable< String> columns, Query source, {bool ignoreConflicts = false}) → Future<int> -
Available on Query<
Inserts rows into this query's table using the results ofT> , provided by the UnionExtension extensionsource. Thecolumnslist must contain one entry per value selected bysource. -
join(
Object table, Object constraint, [Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds an INNER JOIN clause to the query.T> , provided by the JoinExtension extension -
joinLateral(
Query query, String alias, {JoinType type = JoinType.inner, JoinConstraintBuilder? on}) → Query< T> -
Available on Query<
Adds a (driver-gated) LATERAL JOIN clause.T> , provided by the JoinExtension extension -
joinRelation(
String relation, {JoinType type = JoinType.inner}) → Query< T> -
Available on Query<
Joins a relation path without eager loading it.T> , provided by the WhereExtension extension -
joinSub(
Query query, String alias, Object constraint, [Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds an INNER JOIN against a subquery.T> , provided by the JoinExtension extension -
joinWhere(
Object table, Object column, [Object? operator, Object? value]) → Query< T> -
Available on Query<
Adds an INNER JOIN ... WHERE clause to the query.T> , provided by the JoinExtension extension -
leftJoin(
Object table, Object constraint, [Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds a LEFT JOIN clause to the query.T> , provided by the JoinExtension extension -
leftJoinLateral(
Query query, String alias, {JoinConstraintBuilder? on}) → Query< T> -
Available on Query<
Adds a LEFT JOIN LATERAL clause.T> , provided by the JoinExtension extension -
leftJoinSub(
Query query, String alias, Object constraint, [Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds a LEFT JOIN against a subquery.T> , provided by the JoinExtension extension -
leftJoinWhere(
Object table, Object column, [Object? operator, Object? value]) → Query< T> -
Available on Query<
Adds a LEFT JOIN ... WHERE clause to the query.T> , provided by the JoinExtension extension -
limit(
int? value) → Query< T> -
Available on Query<
Limits the number of rows returned.T> , provided by the PaginateExtension extension -
limitPerGroup(
int limit, String column, {int? offset}) → Query< T> -
Available on Query<
Limits the number of rows returned per group.T> , provided by the GroupingExtension extension -
lock(
String clause) → Query< T> -
Available on Query<
Adds a custom lock clause to the query.T> , provided by the LockExtension extension -
lockForUpdate(
) → Query< T> -
Available on Query<
Adds aT> , provided by the LockExtension extensionFOR UPDATElock clause to the query. -
macro(
String name, [List< Object?> args = const []]) → Query<T> -
Available on Query<
Applies a registered query macro to the query.T> , provided by the ScopeExtension extension -
mapRows<
R extends OrmEntity> (R mapper(AdHocRow row)) → MappedAdHocQuery< R> -
Available on Query<
AdHocRow> , provided by the MapQueryExtensions extension -
markGlobalScopesApplied(
) → Query< T> -
Available on Query<
Marks this query as having global scopes applied.T> , provided by the UtilityExtension extension -
max(
String expression, {String? alias}) → Query< T> -
Available on Query<
Adds aT> , provided by the AggregateExtension extensionMAXaggregate to the select projection. -
maxValue(
String expression, {String? alias}) → Future< num?> -
Available on Query<
Executes aT> , provided by the AggregateExtension extensionMAXaggregate and returns the result. -
min(
String expression, {String? alias}) → Query< T> -
Available on Query<
Adds aT> , provided by the AggregateExtension extensionMINaggregate to the select projection. -
minValue(
String expression, {String? alias}) → Future< num?> -
Available on Query<
Executes aT> , provided by the AggregateExtension extensionMINaggregate and returns the result. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offset(
int? value) → Query< T> -
Available on Query<
SkipsT> , provided by the PaginateExtension extensionvaluerows before reading results. -
onlyTrashed(
) → Query< T> -
Available on Query<
Retrieves only soft-deleted models.T> , provided by the SoftDeleteExtension extension -
orderBy(
String field, {bool descending = false}) → Query< T> -
Available on Query<
Orders results byT> , provided by the OrderExtension extensionfield. Setdescendingto sort in reverse. -
orderByExtension(
String key, {Object? payload, bool descending = false}) → Query< T> -
Available on Query<
Orders results using a driver extension expression.T> , provided by the OrderExtension extension -
orderByRandom(
[num? seed]) → Query< T> -
Available on Query<
Orders results randomly.T> , provided by the OrderExtension extension -
orderByRaw(
String sql, [List< Object?> bindings = const []]) → Query<T> -
Available on Query<
Adds a raw ORDER BY expression.T> , provided by the RawQueryExtension extension -
orderByRelation(
String relation, {bool descending = false, RelationAggregateType aggregate = RelationAggregateType.count, PredicateCallback< OrmEntity> ? constraint, bool distinct = false}) → Query<T> -
Available on Query<
Orders results based on a relation aggregate.T> , provided by the RelationExtension extension -
orHavingBitwise(
String field, String operator, Object value) → Query< T> -
Available on Query<
Adds a HAVING clause with a bitwise operator using OR chaining.T> , provided by the GroupingExtension extension -
orHavingExtension(
String key, [Object? payload]) → Query< T> -
Available on Query<
Adds a custom HAVING predicate using OR logic.T> , provided by the GroupingExtension extension -
orHavingRaw(
String sql, [List< Object?> bindings = const []]) → Query<T> -
Available on Query<
Adds a raw HAVING fragment using OR logic.T> , provided by the GroupingExtension extension -
orWhere(
Object fieldOrCallback, [Object? value, PredicateOperator operator = PredicateOperator.equals]) → Query< T> -
Available on Query<
T> , provided by the WhereExtension extensionORvariant of where. -
orWhereBitwise(
String field, String operator, Object value) → Query< T> -
Available on Query<
Adds a bitwise predicate withT> , provided by the WhereExtension extensionORchaining. -
orWhereExists(
Query subquery) → Query< T> -
Available on Query<
Adds an OR WHERE EXISTS subquery predicate.T> , provided by the SubqueryExtension extension -
orWhereExtension(
String key, [Object? payload]) → Query< T> -
Available on Query<
Adds a custom WHERE predicate using OR logic.T> , provided by the WhereExtension extension -
orWhereHas(
String relation, [PredicateCallback< OrmEntity> ? constraint]) → Query<T> -
Available on Query<
Adds anT> , provided by the WhereExtension extensionOR WHERE HASclause for a relation. -
orWhereHasTyped<
TRelated extends OrmEntity> (String relation, [PredicateCallback< TRelated> ? constraint]) → Query<T> -
Available on Query<
Typed variant of orWhereHas that accepts a typed predicate callback.T> , provided by the WhereExtension extension -
orWhereInSubquery(
String field, Query subquery) → Query< T> -
Available on Query<
Adds an OR WHERE IN subquery predicate.T> , provided by the SubqueryExtension extension -
orWhereJsonContains(
String field, Object? value) → Query< T> -
Available on Query<
Adds an OR JSON containment predicate.T> , provided by the JsonExtension extension -
orWhereJsonContainsKey(
String field) → Query< T> -
Available on Query<
Adds an OR JSON containsKey predicate.T> , provided by the JsonExtension extension -
orWhereJsonLength(
String field, int length, {PredicateOperator operator = PredicateOperator.equals}) → Query< T> -
Available on Query<
Adds an OR JSON length predicate.T> , provided by the JsonExtension extension -
orWhereJsonOverlaps(
String field, Object value) → Query< T> -
Available on Query<
Adds an OR JSON overlaps predicate.T> , provided by the JsonExtension extension -
orWhereNotExists(
Query subquery) → Query< T> -
Available on Query<
Adds an OR WHERE NOT EXISTS subquery predicate.T> , provided by the SubqueryExtension extension -
orWhereNotInSubquery(
String field, Query subquery) → Query< T> -
Available on Query<
Adds an OR WHERE NOT IN subquery predicate.T> , provided by the SubqueryExtension extension -
orWhereTyped(
PredicateCallback< T> callback) → Query<T> -
Available on Query<
Adds a typed predicate callback withT> , provided by the WhereExtension extensionORlogic. -
paginate(
{int perPage = 15, int page = 1}) → Future< PageResult< T> > -
Available on Query<
Returns a paginated payload including totals and metadata.T> , provided by the PaginateExtension extension -
pluck<
R> (String field) → Future< List< R> > -
Available on Query<
Returns a list of values fromT> , provided by the CrudExtension extensionfield. -
previewDeleteWherePlan(
List< Object> wheres, {bool returning = false}) → MutationPlan -
Available on Query<
Builds but does not execute a delete plan for flexible inputs (useful for previews).T> , provided by the CrudExtension extension -
previewInsertPlan(
List< Object> inputs, {bool ignoreConflicts = false, bool returning = false}) → MutationPlan -
Available on Query<
Builds but does not execute an insert plan (useful for previews).T> , provided by the CrudExtension extension -
previewUpdatePlan(
List< Object> inputs, {Object? where, JsonUpdateBuilder<T> ? jsonUpdates, bool returning = false}) → MutationPlan -
Available on Query<
Builds but does not execute an update plan (useful for previews).T> , provided by the CrudExtension extension -
previewUpsertPlan(
List< Object> inputs, {List<String> ? uniqueBy, List<String> ? updateColumns, JsonUpdateBuilder<T> ? jsonUpdates, bool returning = false}) → MutationPlan -
Available on Query<
Builds but does not execute an upsert plan (useful for previews).T> , provided by the CrudExtension extension -
remember(
Duration ttl) → Query< T> -
Available on Query<
Cache query results for the specified duration.T> , provided by the QueryCachingExtension extension -
rememberForever(
) → Query< T> -
Available on Query<
Cache query results indefinitely (until manually cleared).T> , provided by the QueryCachingExtension extension -
restore(
) → Future< int> -
Available on Query<
Restores soft-deleted models that match the current query constraints.T> , provided by the SoftDeleteExtension extension -
rightJoin(
Object table, Object constraint, [Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds a RIGHT JOIN clause to the query.T> , provided by the JoinExtension extension -
rightJoinSub(
Query query, String alias, Object constraint, [Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds a RIGHT JOIN against a subquery.T> , provided by the JoinExtension extension -
rightJoinWhere(
Object table, Object column, [Object? operator, Object? value]) → Query< T> -
Available on Query<
Adds a RIGHT JOIN ... WHERE clause to the query.T> , provided by the JoinExtension extension -
rows(
) → Future< List< QueryRow< >T> > -
Available on Query<
Executes the query and returns hydrated QueryRow objects.T> , provided by the CrudExtension extension -
scope(
String name, [List< Object?> args = const []]) → Query<T> -
Available on Query<
Applies a registered local scope to the query.T> , provided by the ScopeExtension extension -
select(
List< String> columns) → Query<T> -
Available on Query<
Only the specifiedT> , provided by the SelectExtension extensioncolumnswill be retrieved from the database. -
selectExtension(
String key, {Object? payload, String? alias}) → Query< T> -
Available on Query<
Adds a custom select expression compiled by a driver extension.T> , provided by the SelectExtension extension -
selectRaw(
String sql, {String? alias, List< Object?> bindings = const []}) → Query<T> -
Available on Query<
Adds a raw select expression with optional bindings.T> , provided by the SelectExtension extension -
Available on Query<
Adds aT> , provided by the LockExtension extensionSHARED LOCKclause to the query. -
simplePaginate(
{int perPage = 15, int page = 1}) → Future< SimplePageResult< T> > -
Available on Query<
Returns a simplified pagination payload without running a count query.T> , provided by the PaginateExtension extension -
sole(
) → Future< T> -
Available on Query<
Ensures there is exactly one record and returns it.T> , provided by the CrudExtension extension -
straightJoin(
Object table, Object constraint, [Object? operator, Object? second]) → Query< T> -
Available on Query<
Adds a STRAIGHT_JOIN clause (MySQL / MariaDB only).T> , provided by the JoinExtension extension -
stream(
{int chunkSize = 100}) → Stream< T> -
Available on Query<
Returns an async stream of query results.T> , provided by the StreamingExtension extension -
streamModels(
) → Stream< T> -
Available on Query<
Streams models sequentially.T> , provided by the PaginateExtension extension -
streamRows(
{int eagerLoadBatchSize = Query._defaultStreamEagerBatchSize}) → Stream< QueryRow< T> > -
Available on Query<
Streams rows sequentially (still buffered by the underlying driver).T> , provided by the PaginateExtension extension -
sum(
String expression, {String? alias}) → Query< T> -
Available on Query<
Adds aT> , provided by the AggregateExtension extensionSUMaggregate to the select projection. -
sumValue(
String expression, {String? alias}) → Future< num?> -
Available on Query<
Executes aT> , provided by the AggregateExtension extensionSUMaggregate and returns the result. -
tap(
void callback(Query< T> query)) → Query<T> -
Available on Query<
Taps into the query chain without modifying it.T> , provided by the UtilityExtension extension -
toSql(
) → StatementPreview -
Available on Query<
Returns the SQL preview without executing the query.T> , provided by the UtilityExtension extension -
toString(
) → String -
A string representation of this object.
inherited
-
union(
Query query) → Query< T> -
Available on Query<
Adds aT> , provided by the UnionExtension extensionUNIONclause combining the current query withquery. -
unionAll(
Query query) → Query< T> -
Available on Query<
Adds aT> , provided by the UnionExtension extensionUNION ALLclause combining the current query withquery. -
unless(
Object condition, Query< T> callback(Query<T> query)) → Query<T> -
Available on Query<
Conditionally applies a callback to the query when the condition is false.T> , provided by the UtilityExtension extension -
update(
Map< String, Object?> values) → Future<int> -
Available on Query<
Updates rows that match the current query constraints.T> , provided by the CrudExtension extension -
updateBatch(
List< Map< updates, {Object uniqueBy = 'id'}) → Future<String, Object?> >int> -
Available on Query<
Updates multiple rows with different values in a single batch operation.T> , provided by the BatchOperationsExtension extension -
updateInputs(
List< Object> inputs, {Object? where, JsonUpdateBuilder<T> ? jsonUpdates}) → Future<List< T> > -
Available on Query<
Updates rows using flexible inputs.T> , provided by the CrudExtension extension -
updateInputsRaw(
List< Object> inputs, {Object? where, JsonUpdateBuilder<T> ? jsonUpdates}) → Future<MutationResult> -
Available on Query<
Updates rows using flexible inputs and returns the raw MutationResult.T> , provided by the CrudExtension extension -
updateOrCreate(
Map< String, dynamic> attributes, Map<String, dynamic> values) → Future<T> -
Available on Query<
Updates the first record matching the attributes, or creates it if not found.T> , provided by the CrudExtension extension -
updateOrInsert(
Map< String, Object?> attributes, Map<String, Object?> values) → Future<bool> -
Available on Query<
Updates existing record or inserts if it doesn't exist.T> , provided by the CrudExtension extension -
updateReturning(
Object values) → Future< List< T> > -
Available on Query<
Updates rows and returns hydrated models using driver RETURNING when available.T> , provided by the CrudExtension extension -
updateValues(
Object values) → Future< int> -
Available on Query<
Updates matching records using flexible inputs.T> , provided by the CrudExtension extension -
upsert(
Map< String, dynamic> attributes, {List<String> ? uniqueBy, List<String> ? updateColumns}) → Future<T> -
Available on Query<
Upserts (insert or update) a single record.T> , provided by the CrudExtension extension -
upsertInputs(
List< Object> inputs, {List<String> ? uniqueBy, List<String> ? updateColumns, JsonUpdateBuilder<T> ? jsonUpdates}) → Future<List< T> > -
Available on Query<
Upserts flexible inputs and returns hydrated models.T> , provided by the CrudExtension extension -
upsertMany(
List< Map< records, {List<String, dynamic> >String> ? uniqueBy, List<String> ? updateColumns}) → Future<List< T> > -
Available on Query<
Upserts (inserts or updates) multiple records.T> , provided by the CrudExtension extension -
useIndex(
List< String> indexes) → Query<T> -
Available on Query<
Applies a USE INDEX hint (MySQL/MariaDB only).T> , provided by the IndexExtension extension -
value<
R> (String field) → Future< R?> -
Available on Query<
Returns the value ofT> , provided by the SelectExtension extensionfieldfrom the first row, ornullwhen missing. -
when(
Object condition, Query< T> callback(Query<T> query)) → Query<T> -
Available on Query<
Conditionally applies a callback to the query.T> , provided by the UtilityExtension extension -
where(
Object fieldOrCallback, [Object? value, PredicateOperator operator = PredicateOperator.equals]) → Query< T> -
Available on Query<
GenericT> , provided by the WhereExtension extensionwherethat accepts either a column comparison or a grouped predicate callback. -
whereBetween(
String field, Object lower, Object upper) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extensionWHERE BETWEENpredicate. -
whereBitwise(
String field, String operator, Object value) → Query< T> -
Available on Query<
Adds a bitwise predicate.T> , provided by the WhereExtension extension -
whereColumn(
String left, String right, {PredicateOperator operator = PredicateOperator.columnEquals}) → Query< T> -
Available on Query<
Adds a predicate comparing two columns.T> , provided by the WhereExtension extension -
whereDate(
String field, Object valueOrOperator, [Object? value]) → Query< T> -
Available on Query<
Compares the DATE portion ofT> , provided by the WhereExtension extensionfield. Defaults to equality comparisons when only a single value is supplied. -
whereDay(
String field, Object valueOrOperator, [Object? value]) → Query< T> -
Available on Query<
Filters by calendar day (1-31) regardless of timezone.T> , provided by the WhereExtension extension -
whereEquals(
String field, Object? value) → Query< T> -
Available on Query<
Adds an equality comparison for the column mapped byT> , provided by the WhereExtension extensionfield. -
whereExists(
Query subquery) → Query< T> -
Available on Query<
Adds a WHERE EXISTS subquery predicate.T> , provided by the SubqueryExtension extension -
whereExtension(
String key, [Object? payload]) → Query< T> -
Available on Query<
Adds a custom WHERE predicate compiled by a driver extension.T> , provided by the WhereExtension extension -
whereFullText(
List< String> columns, Object value, {String? language, FullTextMode mode = FullTextMode.natural, bool expanded = false, String? indexName}) → Query<T> -
Available on Query<
Adds a full-text predicate.T> , provided by the WhereExtension extension -
whereGreaterThan(
String field, Object value) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extension>comparison forfield. -
whereGreaterThanOrEqual(
String field, Object value) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extension>=comparison forfield. -
whereHas(
String relation, [PredicateCallback< OrmEntity> ? constraint]) → Query<T> -
Available on Query<
Adds aT> , provided by the WhereExtension extensionWHERE HASclause for a relation. -
whereHasTyped<
TRelated extends OrmEntity> (String relation, [PredicateCallback< TRelated> ? constraint]) → Query<T> -
Available on Query<
Typed variant of whereHas that accepts a typed predicate callback.T> , provided by the WhereExtension extension -
whereILike(
String field, Object value) → Query< T> -
Available on Query<
Adds an ILIKE predicate.T> , provided by the WhereExtension extension -
whereIn(
String field, Iterable< Object?> values) → Query<T> -
Available on Query<
Adds anT> , provided by the WhereExtension extensionINcomparison forfieldusingvalues. -
whereInSubquery(
String field, Query subquery) → Query< T> -
Available on Query<
Adds a WHERE IN subquery predicate.T> , provided by the SubqueryExtension extension -
whereJsonContains(
String field, Object? value, {String? path}) → Query< T> -
Available on Query<
Adds a JSON containment predicate (dialect-aware).T> , provided by the JsonExtension extension -
whereJsonContainsKey(
String field, [String? path]) → Query< T> -
Available on Query<
Adds a JSON contains key predicate.T> , provided by the JsonExtension extension -
whereJsonLength(
String field, Object operatorOrLength, [int? length]) → Query< T> -
Available on Query<
Adds a JSON length comparison predicate.T> , provided by the JsonExtension extension -
whereJsonOverlaps(
String field, Object value, {String? path}) → Query< T> -
Available on Query<
Adds a JSON overlaps predicate (at least one shared array element).T> , provided by the JsonExtension extension -
whereLessThan(
String field, Object value) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extension<comparison forfield. -
whereLessThanOrEqual(
String field, Object value) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extension<=comparison forfield. -
whereLike(
String field, Object value, {bool caseInsensitive = false}) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extensionLIKEpredicate. -
whereMonth(
String field, Object valueOrOperator, [Object? value]) → Query< T> -
Available on Query<
Filters by calendar month (1-12).T> , provided by the WhereExtension extension -
whereNotBetween(
String field, Object lower, Object upper) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extensionWHERE NOT BETWEENpredicate. -
whereNotEquals(
String field, Object? value) → Query< T> -
Available on Query<
Adds aT> , provided by the WhereExtension extension!=comparison for the column mapped byfield. -
whereNotExists(
Query subquery) → Query< T> -
Available on Query<
Adds a WHERE NOT EXISTS subquery predicate.T> , provided by the SubqueryExtension extension -
whereNotILike(
String field, Object value) → Query< T> -
Available on Query<
Adds a NOT ILIKE predicate.T> , provided by the WhereExtension extension -
whereNotIn(
String field, Iterable< Object?> values) → Query<T> -
Available on Query<
Adds aT> , provided by the WhereExtension extensionNOT INcomparison forfieldusingvalues. -
whereNotInSubquery(
String field, Query subquery) → Query< T> -
Available on Query<
Adds a WHERE NOT IN subquery predicate.T> , provided by the SubqueryExtension extension -
whereNotLike(
String field, Object value, {bool caseInsensitive = false}) → Query< T> -
Available on Query<
Adds a NOT LIKE predicate.T> , provided by the WhereExtension extension -
whereNotNull(
String field) → Query< T> -
Available on Query<
Adds a NOT NULL predicate.T> , provided by the WhereExtension extension -
whereNull(
String field) → Query< T> -
Available on Query<
Adds a NULL predicate.T> , provided by the WhereExtension extension -
whereRaw(
String sql, [List< Object?> bindings = const []]) → Query<T> -
Available on Query<
Adds a raw predicate fragment.T> , provided by the WhereExtension extension -
whereTime(
String field, Object valueOrOperator, [Object? value]) → Query< T> -
Available on Query<
Compares the HH:mm:ss component ofT> , provided by the WhereExtension extensionfield. -
whereTyped(
PredicateCallback< T> callback) → Query<T> -
Available on Query<
Adds a typed predicate callback to the query.T> , provided by the WhereExtension extension -
whereYear(
String field, Object valueOrOperator, [Object? value]) → Query< T> -
Available on Query<
Filters by four-digit calendar year.T> , provided by the WhereExtension extension -
with_(
List< String> names) → Query<T> -
Available on Query<
Requests eager loading for multiple relations.T> , provided by the RelationExtension extension -
withAggregate(
AggregateFunction function, String expression, {String? alias}) → Query< T> -
Available on Query<
Registers an aggregate projection, e.g.T> , provided by the AggregateExtension extensioncount('*'). -
withAvg(
String relation, String column, {String? alias, PredicateCallback< OrmEntity> ? constraint}) → Query<T> -
Available on Query<
Adds aT> , provided by the RelationExtension extensionWITH AVGaggregate for a relation. -
withCount(
String relation, {String? alias, PredicateCallback< OrmEntity> ? constraint, bool distinct = false}) → Query<T> -
Available on Query<
Adds aT> , provided by the RelationExtension extensionWITH COUNTaggregate for a relation. -
withExists(
String relation, {String? alias, PredicateCallback< OrmEntity> ? constraint}) → Query<T> -
Available on Query<
Adds aT> , provided by the RelationExtension extensionWITH EXISTSaggregate for a relation. -
withMax(
String relation, String column, {String? alias, PredicateCallback< OrmEntity> ? constraint}) → Query<T> -
Available on Query<
Adds aT> , provided by the RelationExtension extensionWITH MAXaggregate for a relation. -
withMin(
String relation, String column, {String? alias, PredicateCallback< OrmEntity> ? constraint}) → Query<T> -
Available on Query<
Adds aT> , provided by the RelationExtension extensionWITH MINaggregate for a relation. -
withoutAutoHydration(
) → Query< T> - Disables auto-hydration columns for aggregate or projection-heavy queries.
-
withoutDistinct(
) → Query< T> -
Available on Query<
Removes any previously applied DISTINCT state.T> , provided by the DistinctExtension extension -
withoutEvents(
) → Query< T> - Returns a query that suppresses all model lifecycle events.
-
withoutGlobalScope(
String scope) → Query< T> -
Available on Query<
Removes a specific global scope from the query.T> , provided by the ScopeExtension extension -
withoutGlobalScopes(
[List< String> ? scopes]) → Query<T> -
Available on Query<
Removes all global scopes from the query.T> , provided by the ScopeExtension extension -
withRelation(
String name, [PredicateCallback< OrmEntity> ? constraint]) → Query<T> -
Available on Query<
Requests eager loading for the relation namedT> , provided by the RelationExtension extensionname. -
withRelationTyped<
TRelated extends OrmEntity> (String name, [PredicateCallback< TRelated> ? constraint]) → Query<T> -
Available on Query<
Typed variant of withRelation that accepts a typed predicate callback.T> , provided by the RelationExtension extension -
withSum(
String relation, String column, {String? alias, PredicateCallback< OrmEntity> ? constraint}) → Query<T> -
Available on Query<
Adds aT> , provided by the RelationExtension extensionWITH SUMaggregate for a relation. -
withTrashed(
) → Query< T> -
Available on Query<
Includes soft-deleted models in the query results.T> , provided by the SoftDeleteExtension extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited