Copy as Markdown[View as Markdown](/docs/sdk/functions/addDataStoreToService.md)

***

# Function: addDataStoreToService()

> **addDataStoreToService**(`directory`): (`id`, `operation`, `dataStore`, `version`?) => `Promise`<`void`>

Defined in: services.ts:589

Add a data store to a service by it's id.

Optionally specify a version to add the data store to a specific version of the service.

## Parameters[​](#parameters "Direct link to Parameters")

| Parameter   | Type     |
| ----------- | -------- |
| `directory` | `string` |

## Returns[​](#returns "Direct link to Returns")

`Function`

### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter            | Type                                     |
| -------------------- | ---------------------------------------- |
| `id`                 | `string`                                 |
| `operation`          | `"writesTo"` \| `"readsFrom"`            |
| `dataStore`          | { `id`: `string`; `version`: `string`; } |
| `dataStore.id`       | `string`                                 |
| `dataStore.version`? | `string`                                 |
| `version`?           | `string`                                 |

### Returns[​](#returns-1 "Direct link to Returns")

`Promise`<`void`>

## Example[​](#example "Direct link to Example")

```
import utils from '@eventcatalog/utils';

// Adds an data store to the service
const { addDataStoreToService } = utils('/path/to/eventcatalog');

// Adds a new data store (orders-db) that the InventoryService will write to
await addDataStoreToService('InventoryService', 'writesTo', { id: 'orders-db', version: '2.0.0' });

* // Adds a new data store (OrderComplete) that the InventoryService will read from
await addDataStoreToService('InventoryService', 'readsFrom', { id: 'orders-db', version: '1.0.0' });
```
