---
title: "Datasource factory"
slug: "datasource-factory-1523464"
abstract: ""
---
# Datasource factory

The datasource factory creates datasource instances for the two types of datasources (`Optionlists` in JavaScript SDK).

> [!note]
> In the following code examples, the `client` variable refers to the `ContentHubClient` instance. When using the JavaScript SDK, the variable name can be chosen freely, but is also called `client` at instantiation in the documentation.

## Creating flat datasources

To create a flat datasource, pass a unique name for the datasource to the `createFlatOptionList` method:

```javascript
await client.optionListFactory.createFlatOptionList("NewFlatDataSource");

```

## Creating hierarchical datasources

To create a hierarchical datasource, pass a unique name for the datasource to the `createHierarchicalOptionList` method:

```javascript
await client.optionListFactory.createHierarchicalOptionList("NewHierarchicalDataSource");

```

> [!note]
> The datasource instance is not persisted. The factory only creates an object. If the datasource needs to be persisted, use the `createAsync` method on the `IDataSourcesClient`.