WebWorkerSQLiteDriver


public final class WebWorkerSQLiteDriver implements SQLiteDriver


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

Inherited methods

From androidx.sqlite.SQLiteDriver
abstract boolean

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

abstract @NonNull SQLiteConnection

Opens a new database connection asynchronously.