propose method
Called by initialize; should contain the actual object initialization code.
The method is allowed to throw in the case of an error. If it throws an
Exception, the default Actor implementation will call dispose
afterward to clean up even a partially initialized object.
Implementation
@protected
@override
void propose() {
super.propose();
_database = sqlite3.open(filename);
_begin = statement("BEGIN TRANSACTION");
_commit = statement("COMMIT TRANSACTION");
_rollback = statement("ROLLBACK TRANSACTION");
_beginSavepoint = statement("SAVEPOINT sp");
_commitSavepoint = statement("RELEASE SAVEPOINT sp");
_rollbackSavepoint = statement("ROLLBACK TO SAVEPOINT sp");
var ct = MessageFormat(
"CREATE TABLE IF NOT EXISTS {0} " +
"($columnKeyId NOT NULL UNIQUE, $columnValue NOT NULL)",
);
_database!.execute(ct.xFormat([tableMapping]));
_database!.execute(ct.xFormat([tableScheme]));
var stored = getStoredDefinition();
var actual = scheme.toDefinition();
if (!(const DeepCollectionEquality()).equals(stored, actual))
migrateScheme(stored, actual);
else
scheme.initializeUpdatersLookup(this);
_insert = statement(
"INSERT OR IGNORE INTO $tableMapping ($columnKeyId, $columnValue) "
"VALUES (?, jsonb(?)) RETURNING $columnKind, $columnRowId",
);
_updateByRowId = statement(
"UPDATE OR IGNORE $tableMapping SET $columnValue = jsonb(?) "
"WHERE $columnRowId == ? RETURNING $columnKind",
);
_updateByKeyId = statement(
"UPDATE OR IGNORE $tableMapping SET $columnValue = jsonb(?) "
"WHERE $columnKeyId == ? RETURNING $columnKind, $columnRowId",
);
_deleteByRowId = statement(
"DELETE FROM $tableMapping "
"WHERE $columnRowId == ? RETURNING $columnKind",
);
_deleteByKeyId = statement(
"DELETE FROM $tableMapping "
"WHERE $columnKeyId == ? RETURNING $columnKind, $columnRowId",
);
_existsByRowId = statement(
"SELECT COUNT($columnRowId) "
"FROM $tableMapping WHERE $columnRowId == ?",
);
_existsByKeyId = statement(
"SELECT COUNT($columnKeyId) "
"FROM $tableMapping WHERE $columnKeyId == ?",
);
_selectByRowId = statement(
"SELECT $columnKeyId, json($columnValue) "
"FROM $tableMapping WHERE $columnRowId == ?",
);
_selectByKeyId = statement(
"SELECT $columnRowId, json($columnValue) "
"FROM $tableMapping WHERE $columnKeyId == ?",
);
_domainQueryId = prepare(
where: SqlI(columnKeyId).between(SqlP("@L"), SqlP("@U")),
distinction: QueryDistinction.keyid,
);
begin();
}