VersionedSqliteDb Class

Abstract base class for a SQLite database that has SQLiteDb.RequiredVersionRanges stored in it. This class provides version checking when the database is opened, to guarantee that a valid version of software is always used for access.

Notes:

  • This class may be used either to access a local file, or one stored in a cloud container.
  • Subclasses must provide a myVersion member indicating the version of its software, and implement the createDDL member to create its tables.

Extends

Extended by

Methods

Name Description
constructor(): VersionedSqliteDb    
createDDL(): void ProtectedAbstract Implement this method to create all tables for this subclass of VersionedSqliteDb when a new database file is created.  
getRequiredVersions(): SQLiteDb.RequiredVersionRanges Get the required version ranges necessary to open this VersionedSqliteDb.  
openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void Open this database and verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.  
setRequiredVersions(versions: SQLiteDb.RequiredVersionRanges): void Change the "versions required to open this database" property stored in this database.  
upgradeSchema(arg: { dbName: string, lockContainer?: { container: CloudSqlite.CloudContainer, user: string }, upgradeFn: () => void }): Promise<void | () => void>    
verifyVersions(): void Protected Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.  
createNewDb(fileName: string): void Static Create a new database file for the subclass of VersionedSqliteDb.  

Inherited methods

Name Inherited from Description
abandonChanges(): void SQLiteDb Abandon (cancel) the outermost transaction, discarding all changes since last save.
closeDb(saveChanges?: boolean): void SQLiteDb Close SQLiteDb.
createDb(dbName: string): void SQLiteDb Create a SQLiteDb
createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void SQLiteDb  
createTable(args: { addTimestamp?: boolean, columns: string, constraints?: string, tableName: string }): void Protected SQLiteDb Create a new table in this database.
dispose(): void SQLiteDb alias for closeDb.
executeSQL(sql: string): DbResult SQLiteDb execute an SQL statement
readLastModTime(tableName: string, rowId: number): Date SQLiteDb Get the last modified date for a row in a table of this database.
saveChanges(): void SQLiteDb Commit the outermost transaction, writing changes to the file.
vacuum(args?: SQLiteDb.VacuumDbArgs): void SQLiteDb vacuum this database
withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T SQLiteDb Open a database, perform an operation, then close the database.
withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T SQLiteDb Use a prepared SQL statement, potentially from the statement cache.
withSavePoint(savePointName: string, operation: () => void): void SQLiteDb Perform an operation on this database within a savepoint.
withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T SQLiteDb Prepare and execute a callback on a SQL statement.

Properties

Name Type Description
_versionProps ProtectedStatic { name: "versions", namespace: "SQLiteDb" }    
myVersion Abstract string The current semver "persistence version" of this class.  

Inherited properties

Name Type Inherited from Description
isOpen Accessor ReadOnly boolean SQLiteDb Returns true if this SQLiteDb is open
isReadonly Accessor ReadOnly boolean SQLiteDb Returns true if this SQLiteDb is open readonly

Defined in

Last Updated: 25 April, 2024