BaseComputedField<SqlType extends Object, $Table extends Table> class sealed

The base class for all computed fields

An computed field is an regular drift expression with the additional ability to create the necessary joins automatically.

Typically, when using drift expression you would have to manually create the joins for the tables that you want to use. However, with computed fields, drift will automatically create the necessary joins for you.

Computed fields can be used in filters, orderings and in the select statement. Computed fields should not be constructed directly. Instead, use the .computed field method on a table manager to create an computed field.

Example:

/// Filter users who are in an admin group
final inAdminGroup = db.managers.users.computed field((a) => a.group.isAdmin);
final users = db.managers.users.withComputedFields([inAdminGroup]).filter(inAdminGroup.filter(true)).get();

/// Aggregate the number of users in each group
final userCount = db.managers.group.computed field((a) => a.users((a) => a.id.count()));
final groups = db.managers.group.withComputedFields([userCount]).get();
for (final (group, refs) in groups) {
  final count = userCount.read(refs);
}

In this example:

  • The inAdminGroup computed field filters users directly in the database, ensuring that only users in the admin group are retrieved.
  • The userCount computed field aggregates the number of users in each group within the database, providing the count directly without needing to load all user data into your application.

See also:

Implementers

Properties

hashCode int
The hash code for this object.
no setterinherited
order ColumnOrderings<Object>
Create an order by clause for this computed field
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited