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:
- SQLite.new constructs a new instance of the class;
SQLite.initializecreates a new database or opens an existing one;SQLite.deactivatecloses a database;- SQLite.apply inserts, deletes, and updates database rows in a batch within a transaction;
- SQLite.exists, SQLite.select, and SQLite.domain provide basic querying;
- SQLite.prepare, SQLite.free, and SQLite.query provide advanced free-form querying and full-text search.
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
nullfor 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
ActiveorDeactivated.inherited -
checkUndeactivated(
) → void -
Throws an Error if the state is not set to either
UninitializedorActive.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
lowerandupper. -
exists(
SqlId id) → bool -
Returns
trueif a row with the SQLidexists 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
valueidentified by theid. -
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
ActiveorDeactivated.inherited -
isUndeactivated(
) → bool -
Whether the state is set to either
UninitializedorActive.inherited -
isUninitialized(
) → bool -
Whether the state is set to
Uninitialized.inherited -
migrateScheme(
StdMap stored, StdMap actual) → void -
Migrates a scheme from the
storedoverall version to theactualone. -
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
idand returns the result. -
raiseInactive(
) → void -
Throws an
InactiveActorExceptionif the state is no longer set toActive.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
idwith a newvalue. -
updated(
) → bool - Returns whether a row was inserted, updated, or deleted.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited