# Db

## Content

# Class: Db<S, T\>

Abstract base class implementing the database adapter interface.

## Type parameters

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

## Hierarchy

- **`Db`**

  ↳ [`MemoryDb`](MemoryDb)

## Implements

- [`IDatabaseAdapter`](../interfaces/IDatabaseAdapter)<`S`, `T`\>

## Table of contents

### Constructors

- [constructor](Db#constructor)

### Methods

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

## Constructors

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

• **new Db**<`S`, `T`\>()

#### Type parameters

| Name |
| :------ |
| `S` |
| `T` |

## Methods

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

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

Closes the database connection.

#### Returns

`Promise`<`void`\>

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[close](../interfaces/IDatabaseAdapter#close)

___

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

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

Commits an operation to the database.

#### Parameters

| Name | Type |
| :------ | :------ |
| `id` | `string` |
| `op` | [`IOp`](../interfaces/IOp)<`T`\> |
| `document` | [`IDocument`](../interfaces/IDocument) |
| `options?` | `unknown` |

#### Returns

`Promise`<`boolean`\>

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[commitOp](../interfaces/IDatabaseAdapter#commitop)

___

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

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

Commits a snapshot to the database.

#### Parameters

| Name | Type |
| :------ | :------ |
| `id` | `string` |
| `snapshot` | [`ICommitSnapshot`](../interfaces/ICommitSnapshot)<`S`\> |
| `options?` | `unknown` |

#### Returns

`Promise`<`boolean`\>

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[commitSnapshot](../interfaces/IDatabaseAdapter#commitsnapshot)

___

### <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 |
| :------ | :------ |
| `id` | `string` |
| `to` | `number` |
| `op` | [`IOp`](../interfaces/IOp)<`object`\> |

#### Returns

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

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[getCommittedOpVersion](../interfaces/IDatabaseAdapter#getcommittedopversion)

___

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

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

Retrieves document information by ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `id` | `string` |
| `options?` | `unknown` |

#### Returns

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

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[getDocument](../interfaces/IDatabaseAdapter#getdocument)

___

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

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

Retrieves a specific fragment of a document by ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `id` | `string` |
| `fragmentId` | `string` |
| `options?` | `unknown` |

#### Returns

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

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[getFragment](../interfaces/IDatabaseAdapter#getfragment)

___

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

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

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

#### Parameters

| Name | Type |
| :------ | :------ |
| `id` | `string` |
| `from` | `number` |
| `to?` | `number` |
| `options?` | `unknown` |

#### Returns

`Promise`<[`IOp`](../interfaces/IOp)<`T`\>[]\>

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[getOps](../interfaces/IDatabaseAdapter#getops)

___

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

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

Retrieves the snapshot of a document by ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `id` | `string` |
| `options?` | `unknown` |

#### Returns

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

#### Implementation of

[IDatabaseAdapter](../interfaces/IDatabaseAdapter).[getSnapshot](../interfaces/IDatabaseAdapter#getsnapshot)
