SQLiteQuery class abstract base

A helper base class for a typical usage scenario of a query.

This class follows the ActorBase pattern to manage the query lifecycle. Derived classes are expected to do the following:

  • collect query configuration parameters via a constructor into class properties;
  • override the prepare method to call SQLite.prepare with query configuration parameters;
  • execute a query via SQLite.query in a custom method accepting query execution parameters as arguments;
  • release query resources via the deactivate method when finished.

In the following example, the query narrows its results to rows of the specified kind and sorts them by the specified column. The run method returns at most the first limit values of the column:

base class QueryColumn extends SQLiteQuery {
  QueryColumn(super.sqlite, {required this.column, required this.limit});

  Iterable<Object> run(Kind kind) {
    checkActive();
    QueryParameters qp = {"@$columnKind": kind};
    QueryRows rows = sqlite.query(queryId, parameters: qp);
    return rows.map((var r) => r.ordered[0]);
  }

  @protected
  @override
  QueryId prepare() => sqlite.prepare(
    where: SqlI(columnKind).equal(SqlP("@$columnKind")),
    order: [queryOrdering(SqlI(column), QuerySorting.ascending)],
    limit: limit,
  );

  final String column;
  final int limit;
}

Constructors

SQLiteQuery(SQLite sqlite)
Constructs and initializes an instance of SQLiteQuery.

Properties

hashCode int
The hash code for this object.
no setterinherited
queryId int
The QueryId returned by the prepare method.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sqlite SQLite
A reference to the SQLite instance.
final

Methods

checkActive() → void
Throws an Error if the state is not set to Active.
inherited
checkDeactivated() → void
Throws an Error if the state is not set to Deactivated.
inherited
checkInitialized() → void
Throws an Error if the state is not set to either Active or Deactivated.
inherited
checkUndeactivated() → void
Throws an Error if the state is not set to either Uninitialized or Active.
inherited
checkUninitialized() → void
Throws an Error if the state is not set to Uninitialized.
inherited
deactivate() → void
A public interface for object deactivation.
inherited
dispose() → void
Called by deactivate; should contain the actual object deactivation code.
initialize() → void
A public interface for object initialization.
inherited
isActive() bool
Whether the state is set to Active.
inherited
isDeactivated() bool
Whether the state is set to Deactivated.
inherited
isInitialized() bool
Whether the state is set to either Active or Deactivated.
inherited
isUndeactivated() bool
Whether the state is set to either Uninitialized or Active.
inherited
isUninitialized() bool
Whether the state is set to Uninitialized.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prepare() int
Calls SQLite.prepare and returns the resulting QueryId.
propose() → void
Called by initialize; should contain the actual object initialization code.
raiseInactive() → void
Throws an InactiveActorException if the state is no longer set to Active.
inherited
setActive() → void
Sets the state to Active.
inherited
setDeactivated() → void
Sets the state to Deactivated.
inherited
toString() String
A string representation of this object.
inherited

Operators

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