Package-level declarations

Types

Link copied to clipboard
internal class AppleSuspensionSqlDriver(delegate: SqlDriver, databaseKind: String, diagnostics: DatabaseOperationDiagnostics = SuspensionDatabaseOperations) : SqlDriver

Observes API operations, including standalone reads outside account write admission. These are not VFS lock counts. Native synchronous results stay synchronous. Async results remain outstanding until await completes; a transaction stays outstanding until SQLDelight's commit/rollback callback, or an observed post-commit listener failure. If native transaction end fails, its missing end remains visible rather than claiming release.

Link copied to clipboard
internal class AppleWriteAccessSqlDriver(delegate: SqlDriver, writes: AccountResourceAccess) : SqlDriver

Keeps the driver alive while pausing database access before process suspension. Transactions keep admission until SQLDelight reports commit or rollback, including nested work. A failed native transaction end must not release ownership through a finally block.

Link copied to clipboard
internal interface DatabaseOperationDiagnostics
Link copied to clipboard
class DatabaseOptimizer(sqlDriver: SqlDriver, writeDispatcher: WriteDispatcher)
Link copied to clipboard
class DbInvalidationController(enabled: Boolean, notifyKey: (String) -> Unit)

Controls SQLDelight query invalidations (notifyListeners).

Link copied to clipboard
sealed interface DBProfile
Link copied to clipboard
class DebugExtension(sqlDriver: SqlDriver, isEncrypted: Boolean, metaDataDao: MetadataDAO)
Link copied to clipboard

Fine tuning configuration for the driver. This is useful if we want to squeeze the last bit of performance out of the database. Or if we want to enable some SQLite specific features.

Link copied to clipboard
class ExistingDatabaseException(val reason: ExistingDatabaseException.Reason, val cleanupUncertain: Boolean = false, cause: Throwable? = null) : IllegalStateException

An existing-store failure. If cleanupUncertain is true, the account owner must retain its lease until process exit: the native driver can lose a connection during partial opening or failed close.

Link copied to clipboard
class GlobalDatabaseBuilder(sqlDriver: SqlDriver, platformDatabaseData: PlatformDatabaseData, queriesContext: CoroutineContext = KaliumDispatcherImpl.io)
Link copied to clipboard
@JvmInline
value class GlobalDatabaseSecret(val value: ByteArray)
Link copied to clipboard
internal object InMemoryDatabaseCache

Provides an in-memory cache for in-memory databases.

internal object InMemoryDatabaseCache

Provides an in-memory cache for in-memory databases.

Link copied to clipboard
class MessageEffectDAOs(val conversations: ConversationDAO, val messages: MessageDAO, val reactions: ReactionDAO, val composites: CompositeMessageDAO, val polls: PollMessageDAO, val assets: AssetDAO, val pendingActions: PendingActionDAO, val deliveries: PendingDeliveryConfirmationDAO, val receipts: ReceiptDAO, val users: UserDAO, val prefs: UserConfigStorage, val config: UserConfigDAO, val folders: ConversationFolderDAO, val metadata: MetadataDAO, val members: MemberDAO, val meetings: MeetingDao, val apps: AppDAO, val clients: ClientDAO, val newClients: NewClientDAO, val connections: ConnectionDAO)

Canonical DAOs bound to the caller's single writer transaction, including all reads.

Link copied to clipboard
class MutedSqlDriver(val delegate: SqlDriver, val invalidationController: DbInvalidationController) : SqlDriver

SqlDriver wrapper that can mute invalidations.

Link copied to clipboard

Platform-specific data used to create the database that might be necessary for future operations in the future like nuke

actual data class PlatformDatabaseData

Platform-specific data used to create the database that might be necessary for future operations in the future like nuke

Platform-specific data used to create the database that might be necessary for future operations in the future like nuke

Platform-specific data used to create the database that might be necessary for future operations in the future like nuke

actual data class PlatformDatabaseData

Platform-specific data used to create the database that might be necessary for future operations in the future like nuke

Link copied to clipboard
@JvmInline
value class ReadDispatcher(val value: CoroutineDispatcher)

Dispatcher for database read operations. Limited to MAX_READ_PARALLELISM (32) concurrent reads to prevent SQLCipher connection pool exhaustion while maintaining good throughput.

Link copied to clipboard
internal class SchemaInitializingSqlDriver(delegate: SqlDriver, initialize: suspend () -> Unit) : SqlDriver
Link copied to clipboard
sealed class StorageData
sealed interface StorageData
Link copied to clipboard
internal object TableMapper
Link copied to clipboard
class UserDatabaseBuilder(userId: UserIDEntity, val sqlDriver: SqlDriver, dispatcher: CoroutineDispatcher, platformDatabaseData: PlatformDatabaseData, isEncrypted: Boolean, val dbInvalidationController: DbInvalidationController, initializeSelfUser: Boolean = true)
Link copied to clipboard
@JvmInline
value class UserDBSecret(val value: ByteArray)
Link copied to clipboard
@JvmInline
value class WriteDispatcher(val value: CoroutineDispatcher)

Dispatcher for database write operations. Limited to MAX_WRITE_PARALLELISM (1) to serialize writes and aligning with SQLite's single-writer model.

Properties

Link copied to clipboard
internal val isPlaintextHeaderUsed: Boolean

Whether encrypted databases keep their first PLAINTEXT_HEADER_SIZE bytes readable, see setSqlCipherKey. Only iOS needs it; on macOS the whole database is encrypted, with the salt in its header, as SQLCipher does by default. It is part of the database format, so it depends on nothing but the platform.

Link copied to clipboard
internal const val PLAINTEXT_HEADER_SIZE: Int = 32

The first bytes of an encrypted iOS database that stay unencrypted, see setSqlCipherKey. 32 is what SQLCipher recommends for this.

Functions

Link copied to clipboard
actual suspend fun SqlDriver.checkFKViolations(): Boolean
actual suspend fun SqlDriver.checkFKViolations(): Boolean
expect suspend fun SqlDriver.checkFKViolations(): Boolean
actual suspend fun SqlDriver.checkFKViolations(): Boolean
actual suspend fun SqlDriver.checkFKViolations(): Boolean
Link copied to clipboard
fun clearInMemoryDatabase(userId: UserIDEntity): Boolean

Clears the in-memory database for the given user. This closes the database connection and removes it from the cache, causing SQLite to delete the shared in-memory database.

fun clearInMemoryDatabase(userId: UserIDEntity): Boolean
Link copied to clipboard
internal actual fun createEmptyDatabaseFile(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal actual fun createEmptyDatabaseFile(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal expect fun createEmptyDatabaseFile(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal actual fun createEmptyDatabaseFile(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal actual fun createEmptyDatabaseFile(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
Link copied to clipboard
fun createGlobalInMemoryDatabase(dispatcher: CoroutineDispatcher): GlobalDatabaseBuilder
Link copied to clipboard
internal fun createKaliumWebWorkerDriver(): SqlDriver
Link copied to clipboard
fun databaseDriver(context: Context, dbName: String, passphrase: ByteArray? = null, schema: SqlSchema<QueryResult.Value<Unit>>, config: DriverConfigurationBuilder.() -> Unit = {}): SqlDriver
fun databaseDriver(driverUri: String?, dbName: String, schema: SqlSchema<QueryResult.Value<Unit>>, passphrase: ByteArray? = null, config: DriverConfigurationBuilder.() -> Unit = {}): SqlDriver
fun databaseDriver(uri: String, schema: SqlSchema<QueryResult.Value<Unit>>? = null, config: DriverConfigurationBuilder.() -> Unit = {}): SqlDriver

Creates a JVM SQLite driver with optional SQLDelight-managed schema initialization.

Link copied to clipboard
internal fun existingDatabaseDriver(storagePath: String, name: String, schemaVersion: Long, passphrase: UserDBSecret?): SqlDriver
Link copied to clipboard
fun existingUserDatabaseBuilder(storagePath: String, userId: UserIDEntity, dispatcher: CoroutineDispatcher, passphrase: UserDBSecret? = null): UserDatabaseBuilder

Caller holds the account lease. Never creates the main database, migrates, or inserts SelfUser.

Link copied to clipboard

Reads the app's current database key and salt only; never generates or migrates a key.

Link copied to clipboard
internal actual fun getDatabaseAbsoluteFileLocation(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal actual fun getDatabaseAbsoluteFileLocation(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal expect fun getDatabaseAbsoluteFileLocation(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal actual fun getDatabaseAbsoluteFileLocation(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
internal actual fun getDatabaseAbsoluteFileLocation(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity): String?
Link copied to clipboard
actual fun globalDatabaseProvider(platformDatabaseData: PlatformDatabaseData, queriesContext: CoroutineDispatcher, passphrase: GlobalDatabaseSecret?, enableWAL: Boolean): GlobalDatabaseBuilder

Creates a new instance of the GlobalDatabaseBuilder.

actual fun globalDatabaseProvider(platformDatabaseData: PlatformDatabaseData, queriesContext: CoroutineDispatcher, passphrase: GlobalDatabaseSecret?, enableWAL: Boolean): GlobalDatabaseBuilder

Creates a new instance of the GlobalDatabaseBuilder.

expect fun globalDatabaseProvider(platformDatabaseData: PlatformDatabaseData, queriesContext: CoroutineDispatcher = KaliumDispatcherImpl.io, passphrase: GlobalDatabaseSecret?, enableWAL: Boolean = false): GlobalDatabaseBuilder

Creates a new instance of the GlobalDatabaseBuilder.

actual fun globalDatabaseProvider(platformDatabaseData: PlatformDatabaseData, queriesContext: CoroutineDispatcher, passphrase: GlobalDatabaseSecret?, enableWAL: Boolean): GlobalDatabaseBuilder

Creates a new instance of the GlobalDatabaseBuilder.

actual fun globalDatabaseProvider(platformDatabaseData: PlatformDatabaseData, queriesContext: CoroutineDispatcher, passphrase: GlobalDatabaseSecret?, enableWAL: Boolean): GlobalDatabaseBuilder

Creates a new instance of the GlobalDatabaseBuilder.

Link copied to clipboard
fun inMemoryDatabase(context: Context, userId: UserIDEntity, dispatcher: CoroutineDispatcher): UserDatabaseBuilder
fun inMemoryDatabase(userId: UserIDEntity, dispatcher: CoroutineDispatcher): UserDatabaseBuilder

Creates an in-memory user database, or returns an existing one if it already exists.

fun inMemoryDatabase(userId: UserIDEntity, dispatcher: CoroutineDispatcher): UserDatabaseBuilder

Creates an in-memory user database, or returns an existing one if it already exists.

Link copied to clipboard
actual suspend fun SqlDriver.migrate(sqlSchema: SqlSchema<QueryResult.AsyncValue<Unit>>): Boolean
actual suspend fun SqlDriver.migrate(sqlSchema: SqlSchema<QueryResult.AsyncValue<Unit>>): Boolean
expect suspend fun SqlDriver.migrate(sqlSchema: SqlSchema<QueryResult.AsyncValue<Unit>>): Boolean
actual suspend fun SqlDriver.migrate(sqlSchema: SqlSchema<QueryResult.AsyncValue<Unit>>): Boolean
actual suspend fun SqlDriver.migrate(sqlSchema: SqlSchema<QueryResult.AsyncValue<Unit>>): Boolean
Link copied to clipboard
internal suspend fun SqlDriver.migrateSchema(sqlSchema: SqlSchema<QueryResult.AsyncValue<Unit>>): Boolean
Link copied to clipboard
internal fun nativeDatabaseDriver(configuration: DatabaseConfiguration, maxReaderConnections: Int, databaseKind: String = "user_database"): SqlDriver

Track connection creation, including connections that fail before SQLDelight registers them.

Link copied to clipboard
actual fun nuke(platformDatabaseData: PlatformDatabaseData): Boolean
internal actual fun nuke(userId: UserIDEntity, platformDatabaseData: PlatformDatabaseData): Boolean
actual fun nuke(platformDatabaseData: PlatformDatabaseData): Boolean
internal actual fun nuke(userId: UserIDEntity, platformDatabaseData: PlatformDatabaseData): Boolean
expect fun nuke(platformDatabaseData: PlatformDatabaseData): Boolean
internal expect fun nuke(userId: UserIDEntity, platformDatabaseData: PlatformDatabaseData): Boolean
actual fun nuke(platformDatabaseData: PlatformDatabaseData): Boolean
internal actual fun nuke(userId: UserIDEntity, platformDatabaseData: PlatformDatabaseData): Boolean
actual fun nuke(platformDatabaseData: PlatformDatabaseData): Boolean
internal actual fun nuke(userId: UserIDEntity, platformDatabaseData: PlatformDatabaseData): Boolean
Link copied to clipboard
internal fun openExistingNativeDriver(storagePath: String, name: String, schemaVersion: Long, journalMode: JournalMode, key: String? = null): SqlDriver
Link copied to clipboard
internal actual fun platformDatabaseLogger(): String
internal actual fun platformDatabaseLogger(): String
internal expect fun platformDatabaseLogger(): String
internal actual fun platformDatabaseLogger(): String
internal actual fun platformDatabaseLogger(): String
Link copied to clipboard

Requery retained observers after the NSE may have committed changes through its own driver.

Link copied to clipboard
internal fun DatabaseConnection.requireSqlCipher()

Kalium doesn't link SQLCipher on Apple. CoreCrypto's library contains it and exports the SQLite API, and every app using Kalium links CoreCrypto, so the SQLite that SQLiter calls is SQLCipher. Plain SQLite would accept PRAGMA key and write the database unencrypted, so a connection whose SQLite isn't SQLCipher is refused.

Link copied to clipboard
internal fun requireSqlCipherKey(key: String)

Checks that key can encrypt a database on this platform. On iOS, it has to be SQLCipher's raw-key form with the salt, x'<64 hex digits key><32 hex digits salt>', as SecurityHelper creates it there from the key and salt it stores together. With the readable header, SQLCipher has no place to keep a salt of its own: it would encrypt a new database with a random one, and lose it.

Link copied to clipboard
fun runSqlDelightAsyncSmoke(): Promise<String>
Link copied to clipboard
internal fun DatabaseConnection.setSqlCipherKey(key: String)

Keys a connection with key, see requireSqlCipherKey. On iOS, also keeps the first PLAINTEXT_HEADER_SIZE bytes of the database unencrypted.

Link copied to clipboard
actual fun userDatabaseBuilder(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity, passphrase: UserDBSecret?, dispatcher: CoroutineDispatcher, enableWAL: Boolean, dbInvalidationControlEnabled: Boolean): UserDatabaseBuilder

Creates a UserDatabaseBuilder for the given userId and passphrase

actual fun userDatabaseBuilder(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity, passphrase: UserDBSecret?, dispatcher: CoroutineDispatcher, enableWAL: Boolean, dbInvalidationControlEnabled: Boolean): UserDatabaseBuilder

Creates a UserDatabaseBuilder for the given userId and passphrase

expect fun userDatabaseBuilder(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity, passphrase: UserDBSecret?, dispatcher: CoroutineDispatcher, enableWAL: Boolean = true, dbInvalidationControlEnabled: Boolean = false): UserDatabaseBuilder

Creates a UserDatabaseBuilder for the given userId and passphrase

actual fun userDatabaseBuilder(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity, passphrase: UserDBSecret?, dispatcher: CoroutineDispatcher, enableWAL: Boolean, dbInvalidationControlEnabled: Boolean): UserDatabaseBuilder

Creates a UserDatabaseBuilder for the given userId and passphrase

actual fun userDatabaseBuilder(platformDatabaseData: PlatformDatabaseData, userId: UserIDEntity, passphrase: UserDBSecret?, dispatcher: CoroutineDispatcher, enableWAL: Boolean, dbInvalidationControlEnabled: Boolean): UserDatabaseBuilder

Creates a UserDatabaseBuilder for the given userId and passphrase

Link copied to clipboard
actual fun userDatabaseDriverByPath(platformDatabaseData: PlatformDatabaseData, path: String, passphrase: UserDBSecret?, enableWAL: Boolean): SqlDriver

Opens a database driver for an arbitrary path.

actual fun userDatabaseDriverByPath(platformDatabaseData: PlatformDatabaseData, path: String, passphrase: UserDBSecret?, enableWAL: Boolean): SqlDriver

Opens a database driver for an arbitrary path.

internal expect fun userDatabaseDriverByPath(platformDatabaseData: PlatformDatabaseData, path: String, passphrase: UserDBSecret?, enableWAL: Boolean): SqlDriver

Opens a database driver for an arbitrary path.

actual fun userDatabaseDriverByPath(platformDatabaseData: PlatformDatabaseData, path: String, passphrase: UserDBSecret?, enableWAL: Boolean): SqlDriver

Opens a database driver for an arbitrary path.

actual fun userDatabaseDriverByPath(platformDatabaseData: PlatformDatabaseData, path: String, passphrase: UserDBSecret?, enableWAL: Boolean): SqlDriver

Opens a database driver for an arbitrary path.