Repository<T, ID> class abstract

A generic repository interface providing basic query and type information for entities of type T identified by ID.

This abstract class is meant to be extended by concrete repositories, such as CrudRepository, to provide additional query methods and persistence operations. Queries are delegated to an optional RepositoryExecutor, which can be used to implement database- or memory-backed operations.

Features

  • Delegates query execution to a RepositoryExecutor.
  • Supports multiple query result types: single entity, Iterable, List, Set.
  • Provides type metadata for T and ID.

Usage Example

@Repository()
class UserRepository extends Repository<User, String> {
  Future<User?> getByUsername(String username) async => query();
  Future<List<User>> getAllActive() async => queryList();
}

final repo = UserRepository();
final user = await repo.query<User>();
final users = await repo.queryList<User>();

Design Notes

  • This class itself does not implement persistence; it relies on an optional RepositoryExecutor to perform operations.
  • All query methods are asynchronous and return Futures.
  • Supports Iterable, List, and Set conversions for flexible usage.

See Also

Implementers
Annotations
  • @Generic.new(Repository)

Constructors

Repository()

Properties

executor RepositoryExecutor?
Optional executor used to perform repository operations.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getDartType() → Class<T>
Returns the Class representing the entity type T.
getId() Type
Returns the Dart runtime Type of the entity identifier ID.
getIdType() → Class<ID>
Returns the Class representing the ID type ID.
getType() Type
Returns the Dart runtime Type of the entity T.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
query<U>() Future<U?>
Executes a query returning a single result of type U.
queryIterable<U>() Future<Iterable<U>>
Executes a query returning multiple results as an Iterable of U.
queryList<U>() Future<List<U>>
Executes a query returning results as a List of U.
querySet<U>() Future<Set<U>>
Executes a query returning results as a Set of U.
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

CLASS → Class<Repository>
The reflective Class handle representing the base Repository interface.
final