# IDatabaseAdapter

## Content

# Interface: IDatabaseAdapter<S, T\>

Defines the interface for a database adapter in operational transformation.

## Type parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `S` | `unknown` | The type of snapshot data. |
| `T` | `unknown` | The type of operation data. |

## Implemented by

- [`Db`](../classes/Db)

## Table of contents

### Methods

- [close](IDatabaseAdapter#close)
- [commitOp](IDatabaseAdapter#commitop)
- [commitSnapshot](IDatabaseAdapter#commitsnapshot)
- [getCommittedOpVersion](IDatabaseAdapter#getcommittedopversion)
- [getDocument](IDatabaseAdapter#getdocument)
- [getFragment](IDatabaseAdapter#getfragment)
- [getOps](IDatabaseAdapter#getops)
- [getSnapshot](IDatabaseAdapter#getsnapshot)

## Methods

### <a id="close" name="close"></a> close

▸ **close**(): `Promise`<`void`\>

Closes the database connection.

#### Returns

`Promise`<`void`\>

A promise that resolves when the database is closed.

___

### <a id="commitop" name="commitop"></a> commitOp

▸ **commitOp**(`id`, `op`, `document`, `options?`): `Promise`<`boolean`\>

Commits an operation to the database.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The document ID. |
| `op` | [`IOp`](IOp)<`T`\> | The operation to commit. |
| `document` | [`IDocument`](IDocument) | The document metadata. |
| `options?` | `unknown` | - |

#### Returns

`Promise`<`boolean`\>

A promise resolving to true if the operation was committed, false otherwise.

___

### <a id="commitsnapshot" name="commitsnapshot"></a> commitSnapshot

▸ **commitSnapshot**(`id`, `snapshot`, `options?`): `Promise`<`boolean`\>

Commits a snapshot to the database.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The document ID. |
| `snapshot` | [`ICommitSnapshot`](ICommitSnapshot)<`S`\> | The snapshot to commit. |
| `options?` | `unknown` | - |

#### Returns

`Promise`<`boolean`\>

A promise resolving to true if the snapshot was committed, false otherwise.

___

### <a id="getcommittedopversion" name="getcommittedopversion"></a> getCommittedOpVersion

▸ **getCommittedOpVersion**(`id`, `to`, `op`): `Promise`<``null`` \| `number`\>

Retrieves the committed version of an operation, if it exists.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The document ID. |
| `to` | `number` | The ending version to check up to. |
| `op` | [`IOp`](IOp)<`unknown`\> | The operation to verify. |

#### Returns

`Promise`<``null`` \| `number`\>

A promise resolving to the committed version or null if not committed.

___

### <a id="getdocument" name="getdocument"></a> getDocument

▸ **getDocument**(`id`, `options?`): `Promise`<``null`` \| [`IDocument`](IDocument)\>

Retrieves document information by ID.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The document ID. |
| `options?` | `unknown` | - |

#### Returns

`Promise`<``null`` \| [`IDocument`](IDocument)\>

A promise resolving to the document info or null if not found.

___

### <a id="getfragment" name="getfragment"></a> getFragment

▸ **getFragment**(`id`, `fragmentId`, `options?`): `Promise`<``null`` \| { `data`: ``null`` \| `S` ; `version`: `number`  }\>

Retrieves a specific fragment of a document by ID.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The document ID. |
| `fragmentId` | `string` | The ID of the fragment. |
| `options?` | `unknown` | - |

#### Returns

`Promise`<``null`` \| { `data`: ``null`` \| `S` ; `version`: `number`  }\>

| null>} Resolves to an object with fragment version and data, or null if the document does not exist. If the document exists but the fragment does not, data is null.

___

### <a id="getops" name="getops"></a> getOps

▸ **getOps**(`id`, `from`, `to?`, `options?`): `Promise`<[`IOp`](IOp)<`T`\>[]\>

Retrieves operations between two versions (inclusive of 'from', exclusive of 'to').

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The document ID. |
| `from` | `number` | The starting version. |
| `to?` | `number` | - |
| `options?` | `unknown` | - |

#### Returns

`Promise`<[`IOp`](IOp)<`T`\>[]\>

A promise resolving to an array of operations.

___

### <a id="getsnapshot" name="getsnapshot"></a> getSnapshot

▸ **getSnapshot**(`id`, `options?`): `Promise`<``null`` \| [`ISnapshot`](ISnapshot)<`S`\>\>

Retrieves the snapshot of a document by ID.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The document ID. |
| `options?` | `unknown` | - |

#### Returns

`Promise`<``null`` \| [`ISnapshot`](ISnapshot)<`S`\>\>

A promise resolving to the snapshot or null if not found.
