# IUnifiedStorage\<I, C>

Defined in: [atomiq-sdk/src/storage/IUnifiedStorage.ts:53](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage/IUnifiedStorage.ts#L53)

Interface for a generic unified storage implementations

## Type Parameters

| Type Parameter                                                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `I` *extends* [`UnifiedStorageIndexes`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/UnifiedStorageIndexes.md)                   |
| `C` *extends* [`UnifiedStorageCompositeIndexes`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/UnifiedStorageCompositeIndexes.md) |

## Methods

### init()

```
init(indexes, compositeIndexes): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage/IUnifiedStorage.ts:61](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage/IUnifiedStorage.ts#L61)

Initializes the storage with given indexes and composite indexes

#### Parameters

| Parameter          | Type | Description |
| ------------------ | ---- | ----------- |
| `indexes`          | `I`  |             |
| `compositeIndexes` | `C`  |             |

#### Returns

`Promise`<`void`>

***

### query()

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

Defined in: [atomiq-sdk/src/storage/IUnifiedStorage.ts:76](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage/IUnifiedStorage.ts#L76)

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`\[]>

***

### remove()

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

Defined in: [atomiq-sdk/src/storage/IUnifiedStorage.ts:118](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage/IUnifiedStorage.ts#L118)

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                                 |
| --------- | ----- | ------------------------------------------- |
| `value`   | `any` | Object to remove (must have an id property) |

#### Returns

`Promise`<`void`>

***

### removeAll()

```
removeAll(value, lenient?): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage/IUnifiedStorage.ts:134](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage/IUnifiedStorage.ts#L134)

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                                                                                                                                                                                                                                                                         |
| ---------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value`    | `any`\[]  | Array of objects to remove                                                                                                                                                                                                                                                          |
| `lenient?` | `boolean` | In lenient mode the persistency layer doesn't throw on individual swap failures due to optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap isn't mission-critical for executing next steps (e.g. in tick or sync loops) |

#### Returns

`Promise`<`void`>

***

### save()

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

Defined in: [atomiq-sdk/src/storage/IUnifiedStorage.ts:89](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage/IUnifiedStorage.ts#L89)

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                               |
| --------- | ----- | ----------------------------------------- |
| `value`   | `any` | Object to save (must have an id property) |

#### Returns

`Promise`<`void`>

***

### saveAll()

```
saveAll(value, lenient?): Promise<void>;
```

Defined in: [atomiq-sdk/src/storage/IUnifiedStorage.ts:105](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/storage/IUnifiedStorage.ts#L105)

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                                                                                                                                                                                                                                                                         |
| ---------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value`    | `any`\[]  | Array of objects to save                                                                                                                                                                                                                                                            |
| `lenient?` | `boolean` | In lenient mode the persistency layer doesn't throw on individual swap failures due to optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap isn't mission-critical for executing next steps (e.g. in tick or sync loops) |

#### Returns

`Promise`<`void`>
