# MemoryDb

## Content

# Class: MemoryDb<S, T\>

## Type parameters

| Name | Type |
| :------ | :------ |
| `S` | `unknown` |
| `T` | `unknown` |

## Hierarchy

- [`Db`](Db)<`S`, `T`\>

  ↳ **`MemoryDb`**

## Table of contents

### Constructors

- [constructor](MemoryDb#constructor)

### Methods

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

## Constructors

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

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

#### Type parameters

| Name | Type |
| :------ | :------ |
| `S` | `unknown` |
| `T` | `unknown` |

#### Inherited from

[Db](Db).[constructor](Db#constructor)

## Methods

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

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

Closes the database connection.

#### Returns

`Promise`<`void`\>

#### Overrides

[Db](Db).[close](Db#close)

___

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

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

Commits an operation to the database.

#### Parameters

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

#### Returns

`Promise`<`boolean`\>

#### Overrides

[Db](Db).[commitOp](Db#commitop)

___

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

▸ **commitSnapshot**(`roomId`, `snapshot`): `Promise`<`boolean`\>

Commits a snapshot to the database.

#### Parameters

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

#### Returns

`Promise`<`boolean`\>

#### Overrides

[Db](Db).[commitSnapshot](Db#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`\>

#### Inherited from

[Db](Db).[getCommittedOpVersion](Db#getcommittedopversion)

___

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

▸ **getDocument**(`roomId`): `Promise`<``null`` \| [`IDocument`](../interfaces/IDocument)\>

Retrieves document information by ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `roomId` | `string` |

#### Returns

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

#### Overrides

[Db](Db).[getDocument](Db#getdocument)

___

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

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

Retrieves a specific fragment of a document by ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `roomId` | `string` |
| `fragmentId` | `string` |

#### Returns

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

#### Overrides

[Db](Db).[getFragment](Db#getfragment)

___

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

▸ **getOps**(`roomId`, `fromVersion`, `toVersion?`): `Promise`<[`IOp`](../interfaces/IOp)<`T`\>[]\>

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

#### Parameters

| Name | Type |
| :------ | :------ |
| `roomId` | `string` |
| `fromVersion` | `number` |
| `toVersion?` | `number` |

#### Returns

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

#### Overrides

[Db](Db).[getOps](Db#getops)

___

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

▸ **getSnapshot**(`roomId`): `Promise`<``null`` \| [`ISnapshot`](../interfaces/ISnapshot)<`S`\>\>

Retrieves the snapshot of a document by ID.

#### Parameters

| Name | Type |
| :------ | :------ |
| `roomId` | `string` |

#### Returns

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

#### Overrides

[Db](Db).[getSnapshot](Db#getsnapshot)
