# WebWorkerSQLiteDriver

Artifact: [androidx.sqlite:sqlite-web](https://developer.android.com/jetpack/androidx/releases/sqlite) [View Source](https://cs.android.com/search?q=file:androidx/sqlite/driver/web/WebWorkerSQLiteDriver.+class:androidx.sqlite.driver.web.WebWorkerSQLiteDriver)

*** ** * ** ***


```
public final class WebWorkerSQLiteDriver implements SQLiteDriver
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/sqlite/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:

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

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

**Success:**

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

**Error:**

```sql
{
  "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**

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

**Response**

```sql
{
"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**

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

**Response:**

```sql
{
  "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**

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

**Response**

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

#### `close`

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

**Request**

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

## Summary

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteConnection` | `https://developer.android.com/reference/androidx/sqlite/driver/web/WebWorkerSQLiteDriver#open(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html fileName)` |

| ### Inherited methods |
|---|
| From [androidx.sqlite.SQLiteDriver](https://developer.android.com/reference/androidx/sqlite/SQLiteDriver) |---|---| | `abstract boolean` | `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver#hasConnectionPool()()` Identifies whether the driver has an internal connection pool or not. | |

## Public methods

### open

```
public @NonNull SQLiteConnection open(@NonNull String fileName)
```