WebWorkerSQLiteDriver



A SQLiteDriver that communicates with a web worker delegating database operations to the web worker.

The driver communicates with the web worker though a message protocol. All messages, requests and responses are wrapper in a container message format. It contains an id to correlate between requests and responses along with the message data and an optional error. Requests are differentiated from responses because their data have a cmd identifier.

A request from the driver to the worker has the following structure:

{
"id": <number>,
"data": {
"cmd": "<command_name>",
...
}
}

A response from the worker to the driver has the following structure:

Success:

{
"id": <number>,
"data": { ... }
}

Error:

{
"id": <number>,
"error": "<error_message>"
}

The list of request commands and responses are as following:

open

Opens a new database connection. If successful responds with the database connection unique ID.

Request

{
"cmd": "open",
"fileName": "<string>"
}

Response

{
"databaseId": <number>
}

prepare

Prepares a new SQL statement for execution. If successful responds with the statement unique ID and information about the prepared statement.

Request

{
"cmd": "prepare",
"databaseId": <number>,
"sql": "<string>"
}

Response:

{
"statementId": <number>,
"parameterCount": <number>,
"columnNames": ["<string>", ...]
}

step

Executes a prepared statement. Involves binding parameters sent in the request and then stepping through all the result rows of the statement to respond with their column result.

Request

{
"cmd": "step",
"statementId": <number>,
"bindings": [...]
}

Response

{
"rows": [[...], ...],
"columnTypes": [<number>, ...]
}

close

Closes a prepared statement or a database connection. This is a one-way command; no success response is sent.

Request

{
"cmd": "close",
"statementId": <number>,
"databaseId": <number>
}

Summary

Public constructors

JS
JS

Public functions

open suspend SQLiteConnection
openAsync(fileName: String)

Opens a new database connection asynchronously.

JS
open suspend SQLiteConnection
openAsync(fileName: String)

Opens a new database connection asynchronously.

JS

Public properties

open Boolean

Identifies whether the driver has an internal connection pool or not.

JS
open Boolean

Identifies whether the driver has an internal connection pool or not.

JS

Inherited functions

From androidx.sqlite.SQLiteDriver
abstract suspend SQLiteConnection
openAsync(fileName: String)

Opens a new database connection asynchronously.

Cmn

Inherited properties

From androidx.sqlite.SQLiteDriver
abstract Boolean

Identifies whether the driver has an internal connection pool or not.

Cmn

Public constructors

WebWorkerSQLiteDriver

WebWorkerSQLiteDriver(worker: Worker)

WebWorkerSQLiteDriver

WebWorkerSQLiteDriver(worker: Worker)

Public functions

openAsync

open suspend fun openAsync(fileName: String): SQLiteConnection

Opens a new database connection asynchronously.

To open an in-memory database use the special name :memory: as the fileName.

Parameters
fileName: String

Name of the database file.

Returns
SQLiteConnection

the database connection.

openAsync

open suspend fun openAsync(fileName: String): SQLiteConnection

Opens a new database connection asynchronously.

To open an in-memory database use the special name :memory: as the fileName.

Parameters
fileName: String

Name of the database file.

Returns
SQLiteConnection

the database connection.

Public properties

hasConnectionPool

open val hasConnectionPoolBoolean

Identifies whether the driver has an internal connection pool or not.

A driver with an internal pool should be capable of opening connections that are safe to be used in a multi-thread and concurrent environment whereas a driver that does not have an internal pool will require the application to manage connections in a thread-safe manner. A driver might not report containing a connection pool but might still be safe to be used in a multi-thread environment, such behavior will depend on the driver implementation.

The value returned should be used as a signal to higher abstractions in order to determine if the driver and its connections should be managed by an external connection pool or not.

hasConnectionPool

open val hasConnectionPoolBoolean

Identifies whether the driver has an internal connection pool or not.

A driver with an internal pool should be capable of opening connections that are safe to be used in a multi-thread and concurrent environment whereas a driver that does not have an internal pool will require the application to manage connections in a thread-safe manner. A driver might not report containing a connection pool but might still be safe to be used in a multi-thread environment, such behavior will depend on the driver implementation.

The value returned should be used as a signal to higher abstractions in order to determine if the driver and its connections should be managed by an external connection pool or not.