# @ovok/native/bluetooth/sqlite

Canonical page: https://docs.ovok.com/native-sdk/reference/bluetooth-sqlite

The outbox store on `expo-sqlite`, for an app that builds its own instead of passing `sqlite` to the `Ovok` client.
Import from `@ovok/native/bluetooth/sqlite`. It has its own subpath so apps without `expo-sqlite`, and browser
bundles, never load it.

## Classes [#classes]

### SqliteOutboxStore [#sqliteoutboxstore]

The outbox store on `expo-sqlite`, for phones; `expo-sqlite` is an optional peer dependency, loaded on first use.

#### Extends [#extends]

- `SqliteDatabaseOutboxStore`

#### Constructors [#constructors]

##### Constructor [#constructor]

```ts
new SqliteOutboxStore(options?): SqliteOutboxStore;
```

###### Parameters [#parameters]

| Parameter | Type |
| ------ | ------ |
| `options?` | [`SqliteOutboxOptions`](#sqliteoutboxoptions) |

###### Returns [#returns]

[`SqliteOutboxStore`](#sqliteoutboxstore)

###### Overrides [#overrides]

`SqliteDatabaseOutboxStore.constructor`

#### Methods [#methods]

##### count() [#count]

```ts
count(ownerKey, state): Promise<number>;
```

How many of the owner's items are in `state`.

###### Parameters [#parameters-1]

| Parameter | Type |
| ------ | ------ |
| `ownerKey` | `string` |
| `state` | `OutboxState` |

###### Returns [#returns-1]

`Promise`\<`number`\>

###### Inherited from [#inherited-from]

`SqliteDatabaseOutboxStore.count`

##### due() [#due]

```ts
due(
   ownerKey,
   now,
   limit
): Promise<OutboxItem[]>;
```

The owner's pending items that are due, newest recorded first, then by position in the recording.

###### Parameters [#parameters-2]

| Parameter | Type |
| ------ | ------ |
| `ownerKey` | `string` |
| `now` | `number` |
| `limit` | `number` |

###### Returns [#returns-2]

`Promise`\<`OutboxItem`[]\>

###### Inherited from [#inherited-from-1]

`SqliteDatabaseOutboxStore.due`

##### get() [#get]

```ts
get(id): Promise<OutboxItem | null>;
```

Returns an item, or `null` when there is none.

###### Parameters [#parameters-3]

| Parameter | Type |
| ------ | ------ |
| `id` | `string` |

###### Returns [#returns-3]

`Promise`\<`OutboxItem` \| `null`\>

###### Inherited from [#inherited-from-2]

`SqliteDatabaseOutboxStore.get`

##### put() [#put]

```ts
put(item): Promise<void>;
```

Stores an item, replacing the one with the same id.

###### Parameters [#parameters-4]

| Parameter | Type |
| ------ | ------ |
| `item` | `OutboxItem` |

###### Returns [#returns-4]

`Promise`\<`void`\>

###### Inherited from [#inherited-from-3]

`SqliteDatabaseOutboxStore.put`

##### remove() [#remove]

```ts
remove(id): Promise<void>;
```

Deletes an item; an unknown id is not an error.

###### Parameters [#parameters-5]

| Parameter | Type |
| ------ | ------ |
| `id` | `string` |

###### Returns [#returns-5]

`Promise`\<`void`\>

###### Inherited from [#inherited-from-4]

`SqliteDatabaseOutboxStore.remove`

##### summaries() [#summaries]

```ts
summaries(ownerKey): Promise<OutboxItemSummary[]>;
```

Every item of the owner in any state, newest recorded first, without its entries.

###### Parameters [#parameters-6]

| Parameter | Type |
| ------ | ------ |
| `ownerKey` | `string` |

###### Returns [#returns-6]

`Promise`\<`OutboxItemSummary`[]\>

###### Inherited from [#inherited-from-5]

`SqliteDatabaseOutboxStore.summaries`

## Interfaces [#interfaces]

### SqliteDatabase [#sqlitedatabase]

The part of an `expo-sqlite` database the outbox store uses.

#### Extends [#extends-1]

- [`SqliteTransaction`](#sqlitetransaction)

#### Methods [#methods-1]

##### execAsync() [#execasync]

```ts
execAsync(source): Promise<void>;
```

Runs statements that take no parameters.

###### Parameters [#parameters-7]

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |

###### Returns [#returns-7]

`Promise`\<`void`\>

###### Inherited from [#inherited-from-6]

[`SqliteTransaction`](#sqlitetransaction).[`execAsync`](#execasync-1)

##### getAllAsync() [#getallasync]

```ts
getAllAsync<Row>(source, params): Promise<Row[]>;
```

Returns every row a query finds.

###### Type Parameters [#type-parameters]

| Type Parameter |
| ------ |
| <a id="type-parameter-row"></a> `Row` |

###### Parameters [#parameters-8]

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |
| `params` | [`SqliteBindValue`](#sqlitebindvalue)[] |

###### Returns [#returns-8]

`Promise`\<`Row`[]\>

##### getFirstAsync() [#getfirstasync]

```ts
getFirstAsync<Row>(source, params): Promise<Row | null>;
```

Returns the first row a query finds, or `null`.

###### Type Parameters [#type-parameters-1]

| Type Parameter |
| ------ |
| <a id="type-parameter-row-1"></a> `Row` |

###### Parameters [#parameters-9]

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |
| `params` | [`SqliteBindValue`](#sqlitebindvalue)[] |

###### Returns [#returns-9]

`Promise`\<`Row` \| `null`\>

###### Inherited from [#inherited-from-7]

[`SqliteTransaction`](#sqlitetransaction).[`getFirstAsync`](#getfirstasync-1)

##### runAsync() [#runasync]

```ts
runAsync(source, params): Promise<unknown>;
```

Runs one statement that writes.

###### Parameters [#parameters-10]

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |
| `params` | [`SqliteBindValue`](#sqlitebindvalue)[] |

###### Returns [#returns-10]

`Promise`\<`unknown`\>

###### Inherited from [#inherited-from-8]

[`SqliteTransaction`](#sqlitetransaction).[`runAsync`](#runasync-1)

##### withExclusiveTransactionAsync() [#withexclusivetransactionasync]

```ts
withExclusiveTransactionAsync(task): Promise<void>;
```

Runs `task` in one exclusive transaction: it commits when `task` resolves and rolls back when it throws.

###### Parameters [#parameters-11]

| Parameter | Type |
| ------ | ------ |
| `task` | (`transaction`) => `Promise`\<`void`\> |

###### Returns [#returns-11]

`Promise`\<`void`\>

***

### SqliteTransaction [#sqlitetransaction]

The part of an `expo-sqlite` transaction the outbox store uses.

#### Extended by [#extended-by]

- [`SqliteDatabase`](#sqlitedatabase)

#### Methods [#methods-2]

##### execAsync() [#execasync-1]

```ts
execAsync(source): Promise<void>;
```

Runs statements that take no parameters.

###### Parameters [#parameters-12]

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |

###### Returns [#returns-12]

`Promise`\<`void`\>

##### getFirstAsync() [#getfirstasync-1]

```ts
getFirstAsync<Row>(source, params): Promise<Row | null>;
```

Returns the first row a query finds, or `null`.

###### Type Parameters [#type-parameters-2]

| Type Parameter |
| ------ |
| <a id="type-parameter-row-2"></a> `Row` |

###### Parameters [#parameters-13]

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |
| `params` | [`SqliteBindValue`](#sqlitebindvalue)[] |

###### Returns [#returns-13]

`Promise`\<`Row` \| `null`\>

##### runAsync() [#runasync-1]

```ts
runAsync(source, params): Promise<unknown>;
```

Runs one statement that writes.

###### Parameters [#parameters-14]

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |
| `params` | [`SqliteBindValue`](#sqlitebindvalue)[] |

###### Returns [#returns-14]

`Promise`\<`unknown`\>

## Type Aliases [#type-aliases]

### SqliteBindValue [#sqlitebindvalue]

```ts
type SqliteBindValue = string | number | null;
```

A value SQLite binds to a `?` placeholder.

***

### SqliteDatabaseOutboxOptions [#sqlitedatabaseoutboxoptions]

```ts
type SqliteDatabaseOutboxOptions = object;
```

How `SqliteDatabaseOutboxStore` opens its database.

#### Properties [#properties]

##### logger? [#logger]

```ts
logger?: Logger;
```

Where structured events go; silent by default.

##### name? [#name]

```ts
name?: string;
```

The database file name; `ovok-outbox.db` by default.

##### open [#open]

```ts
open: (name) => Promise<SqliteDatabase>;
```

Opens the named database, such as `expo-sqlite`'s `openDatabaseAsync`.

###### Parameters [#parameters-15]

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |

###### Returns [#returns-15]

`Promise`\<[`SqliteDatabase`](#sqlitedatabase)\>

***

### SqliteOutboxOptions [#sqliteoutboxoptions]

```ts
type SqliteOutboxOptions = Partial<SqliteDatabaseOutboxOptions>;
```

Every field has a default for a phone app; `open` defaults to `expo-sqlite`'s `openDatabaseAsync`.

## References [#references]

### OvokSqlite [#ovoksqlite]

Re-exports [OvokSqlite](next.mdx#ovoksqlite)
