# IndexedDBUnifiedStorage

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:66](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L66)

Browser IndexedDB storage implementation

## Implements

* [`IUnifiedStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md)<[`UnifiedSwapStorageIndexes`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/UnifiedSwapStorageIndexes.md), [`UnifiedStorageCompositeIndexes`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/UnifiedStorageCompositeIndexes.md)>

## Constructors

### Constructor

```
new IndexedDBUnifiedStorage(storageKey): IndexedDBUnifiedStorage;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:73](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L73)

#### Parameters

| Parameter    | Type     |
| ------------ | -------- |
| `storageKey` | `string` |

#### Returns

`IndexedDBUnifiedStorage`

## Properties

### db?

```
optional db: IDBDatabase;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:71](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L71)

***

### storageKey

```
readonly storageKey: string;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:70](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L70)

***

### logger

```
protected readonly logger: LoggerType;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:68](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L68)

## Methods

### init()

```
init(): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:246](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L246)

Initializes the storage with given indexes and composite indexes

#### Returns

`Promise`<`void`>

#### Implementation of

[`IUnifiedStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md).[`init`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md#init)

***

### query()

```
query(params): Promise<any[]>;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:268](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L268)

Params are specified in the following way:

* \[\[condition1, condition2]] - returns all rows where condition1 AND condition2 is met
* \[\[condition1], \[condition2]] - returns all rows where condition1 OR condition2 is met
* \[\[condition1, condition2], \[condition3]] - returns all rows where (condition1 AND condition2) OR condition3 is met

You can also add an optional `_meta` field in the returned unified storage object which gets attached to that returned object and will be present for subsequent saves and removal of this object, if you specify the `_meta` field here, you need to explicitly handle it in the all the saving and remove functions and not simply serialize it into the storage

#### Parameters

| Parameter | Type                                                                                                             | Description |
| --------- | ---------------------------------------------------------------------------------------------------------------- | ----------- |
| `params`  | [`QueryParams`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/QueryParams.md)\[]\[] |             |

#### Returns

`Promise`<`any`\[]>

#### Implementation of

[`IUnifiedStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md).[`query`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md#query)

***

### remove()

```
remove(object): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:319](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L319)

Removes an object from storage

If the object contains a `_meta` field, this will be also present in the to-be-removed value, to mutate the `_meta` field of the object that is saved, you can mutate the `_meta` field directly on the passed value, which then gets reflected automatically in the existing object. The mutated `_meta` field is copied even if the function throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests that might fail.

#### Parameters

| Parameter | Type  | Description                                 |
| --------- | ----- | ------------------------------------------- |
| `object`  | `any` | Object to remove (must have an id property) |

#### Returns

`Promise`<`void`>

#### Implementation of

[`IUnifiedStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md).[`remove`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md#remove)

***

### removeAll()

```
removeAll(arr): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:327](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L327)

Removes multiple objects from storage in a batch operation

If the objects contain a `_meta` field, this will be also present in the to-be-removed values, to mutate the `_meta` field of the objects that are saved, you can mutate the `_meta` field directly on the passed values, which then gets reflected automatically in the existing objects. The mutated `_meta` field is copied even if the function throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests that might fail.

#### Parameters

| Parameter | Type     | Description                |
| --------- | -------- | -------------------------- |
| `arr`     | `any`\[] | Array of objects to remove |

#### Returns

`Promise`<`void`>

#### Implementation of

[`IUnifiedStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md).[`removeAll`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md#removeall)

***

### save()

```
save(object): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:337](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L337)

Saves an object to storage, updating indexes as needed

If the object contains a `_meta` field, this will be also present in the to-be-saved value, to mutate the `_meta` field of the object that is saved, you can mutate the `_meta` field directly on the passed value, which then gets reflected automatically in the existing object. The mutated `_meta` field is copied even if the function throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests that might fail.

#### Parameters

| Parameter | Type  | Description                               |
| --------- | ----- | ----------------------------------------- |
| `object`  | `any` | Object to save (must have an id property) |

#### Returns

`Promise`<`void`>

#### Implementation of

[`IUnifiedStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md).[`save`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md#save)

***

### saveAll()

```
saveAll(arr): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:344](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L344)

Saves multiple objects to storage in a batch operation

If the objects contain a `_meta` field, this will be also present in the to-be-saved values, to mutate the `_meta` field of the objects that are saved, you can mutate the `_meta` field directly on the passed values, which then gets reflected automatically in the existing objects. The mutated `_meta` field is copied even if the function throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests that might fail.

#### Parameters

| Parameter | Type     | Description              |
| --------- | -------- | ------------------------ |
| `arr`     | `any`\[] | Array of objects to save |

#### Returns

`Promise`<`void`>

#### Implementation of

[`IUnifiedStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md).[`saveAll`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IUnifiedStorage.md#saveall)

***

### tryMigrate()

```
tryMigrate(storageKeys, reviver): Promise<boolean>;
```

Defined in: [atomiq-sdk/src/storage-browser/IndexedDBUnifiedStorage.ts:179](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage-browser/IndexedDBUnifiedStorage.ts#L179)

Attempts to migrate the swap database from old implementations (either using prior version of IndexedDB or Local Storage)

NOTE: Reviver also needs to update the swap to the latest version

#### Parameters

| Parameter     | Type                                                                                                                 | Description                                                              |
| ------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `storageKeys` | \[`string`, [`SwapType`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/enumerations/SwapType.md)]\[] | An array of tuples of storage keys used for the corresponding swap types |
| `reviver`     | (`obj`) => [`ISwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwap.md)                 | Swap data deserializer                                                   |

#### Returns

`Promise`<`boolean`>
