SQLite class base

A class for creating, opening, querying, and updating databases.

This class is a primary subset of the library API; it uses the ActorBase pattern and implements the following functionality:

The example below creates or opens a database at the filepath with the required scheme, inserts two key-value pairs into the mapping table within a single transaction, and closes the database regardless of whether an exception was thrown in the finalize block during the insertion step:

var sqlite = SQLite(filepath, scheme);
sqlite.initialize();
finalize(() {
  var tx = Transaction();
  tx.insert(KeyId("MAT-TI-6AL-4V-001"), [
    "Material",
    {
      "common_name": "Titanium Grade 5 (Ti-6Al-4V)",
      "density_g_cm3": 4.43,
      "yield_strength_mpa": 880,
      "thermal_conductivity_w_m_k": 6.7,
      "coefficient_of_thermal_expansion_um_m_c": 8.6,
    },
  ]);
  tx.insert(KeyId("MAT-AL-6061-T6-002"), [
    "Material",
    {
      "common_name": "Aluminum 6061-T6",
      "density_g_cm3": 2.70,
      "yield_strength_mpa": 276,
      "thermal_conductivity_w_m_k": 167.0,
      "coefficient_of_thermal_expansion_um_m_c": 23.6,
    },
  ]);
  sqlite.apply(tx);
}, finale: sqlite.deactivate);

Constructors

SQLite(String file, Scheme scheme)
Constructs a new instance of the class for the on-disk database.
SQLite.inMemory(Scheme scheme)
Constructs a new instance of the class for the in-memory database.

Properties

filename String?
The path to a database file, or null for an in-memory database.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scheme Scheme
The database Scheme that the application requires.
final

Methods

apply(Transaction transaction, {bool savepoint = false}) int
Inserts, deletes, and updates database rows in a batch.
beginTransaction() → void
Begins a transaction and creates a savepoint.
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
commitTransaction() → void
Commits the transaction, begins a new one, and creates a savepoint.
createSavepoint() → void
Creates a savepoint.
deactivate() → void
A public interface for object deactivation.
inherited
delete(SqlId id) bool
Deletes an existing JSON value identified by the id.
dispose() → void
Called by deactivate; should contain the actual object deactivation code.
domain(SqlId lower, SqlId upper) FullIdIterable
Returns all FullIds found in the database between lower and upper.
exists(SqlId id) bool
Returns true if a row with the SQL id exists in the database.
formatMakeColumn(MessageFormat message, String name, KindList kinds, Sql sql) String
Formats an SQL statement that creates a virtual column.
formatMakeIndex(MessageFormat message, String name, IndexColumns columns) String
Formats an SQL statement that creates a partial index.
free(QueryId id) → void
Releases resources associated with the given QueryId.
getStoredDefinition() → StdMap
Returns the overall scheme version currently stored in the database.
initialize() → void
A public interface for object initialization.
inherited
insert(KeyId id, Object value) bool
Inserts a new JSON value identified by the id.
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
migrateScheme(StdMap stored, StdMap actual) → void
Migrates a scheme from the stored overall version to the actual one.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prepare({List<Sql> columns = const [], Sql? search, Sql? where, List<QueryOrdering> order = const [], QueryDistinction distinction = QueryDistinction.rowid, int limit = -1}) QueryId
Prepares an advanced SELECT-based query for subsequent executions.
propose() → void
Called by initialize; should contain the actual object initialization code.
query(QueryId id, {QueryParameters parameters = const {}, QueryDirection direction = QueryDirection.forward, QueryRowPosition? start}) QueryRows
Executes a query identified by the given id and returns the result.
raiseInactive() → void
Throws an InactiveActorException if the state is no longer set to Active.
inherited
rollbackToSavepoint() → void
Rolls back to the savepoint.
rollbackTransaction() → void
Rolls back the transaction.
select(SqlId id) FullIdWithValue?
Returns a FullId key and a JSON Object value for the SQL id.
setActive() → void
Sets the state to Active.
inherited
setDeactivated() → void
Sets the state to Deactivated.
inherited
statement(String sql) → CommonPreparedStatement
Returns a prepared statement object for the given SQL string.
toString() String
A string representation of this object.
inherited
update(SqlId id, Object value) bool
Updates an existing JSON value identified by the id with a new value.
updated() bool
Returns whether a row was inserted, updated, or deleted.

Operators

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