# GC.Data.DataManager

## Content

# Class: DataManager

[GC](../modules/GC).[Data](../modules/GC.Data).DataManager

## Table of contents

### Constructors

- [constructor](GC.Data.DataManager#constructor)

### Properties

- [relationships](GC.Data.DataManager#relationships)
- [tables](GC.Data.DataManager#tables)

### Methods

- [addRelationship](GC.Data.DataManager#addrelationship)
- [addTable](GC.Data.DataManager#addtable)
- [removeRelationship](GC.Data.DataManager#removerelationship)
- [removeTable](GC.Data.DataManager#removetable)

## Constructors

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

• **new DataManager**()

Represents the data manager.

**`example`**
```
// Create a data manager
var dataManager = new GC.Data.DataManager();
```

## Properties

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

• **relationships**: [`IRelationship`](../interfaces/GC.Data.IRelationship)[]

Represents the relationship array. Each relationship includes the following field,

**`property`** {GC.Data.Table} sourceTable - The source table.

**`property`** {string} sourceFieldName - The field name of the source table.

**`property`** {string} sourceRelationshipName - The relationship name which can be used in source table.

**`property`** {GC.Data.Table} targetTable - The target table.

**`property`** {string} targetFieldName - The field name of the target table.

**`property`** {string} targetRelationshipName - The relationship name which can be used in target table.

___

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

• **tables**: [`ITables`](../interfaces/GC.Data.ITables)

Represents the table collection. Its key is table name, and value is GC.Data.Table instance.

## Methods

### <a id="addrelationship" name="addrelationship"></a> addRelationship

▸ **addRelationship**(`sourceTable`, `sourceFieldName`, `sourceRelationshipName`, `targetTable`, `targetFieldName`, `targetRelationshipName`): [`IRelationship`](../interfaces/GC.Data.IRelationship)

Adds a relationship into the data manager.

**`example`**
```
// Add relationship between products table and categories table
dataManager.addRelationship(productTable, "categoryId", "categories", categoriesTable, "id", "products");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `sourceTable` | [`Table`](GC.Data.Table) | The source table, which foreign key is target table's primary key. |
| `sourceFieldName` | `string` | The source field name. |
| `sourceRelationshipName` | `string` | The source relationship name. |
| `targetTable` | [`Table`](GC.Data.Table) | The target table, which primary key is source table's foreign key. |
| `targetFieldName` | `string` | The target field name. |
| `targetRelationshipName` | `string` | The target relationship name. |

#### Returns

[`IRelationship`](../interfaces/GC.Data.IRelationship)

Returns the relationship.

___

### <a id="addtable" name="addtable"></a> addTable

▸ **addTable**(`name`, `dataSourceOption`): [`Table`](GC.Data.Table)

Add a table into the data manager.

**`example`**
```
// Add a sample table to read data
var tableName = "products";
var dataSourceOption = {
     remote: {
        read: {
            url: "https://demodata.mescius.io/northwind/api/v1/orders"
        }
    },
    schema: {
        columns: {
            orderId: {dataName: "id"},
            orderDate: {dataType: "date", dataPattern: "yyyy-MM-dd hh:mm:ss.000"},
            requiredDate: {dataType: "date"},
            shippedDate: {dataType: "date"},
            shipVia: {dataMap: {1: "Speedy Express", 2: "United Package", 3: "Federal Shipping"}}
        }
    }
};
var dataManager = new GC.Data.DataManager();
var productTable = dataManager.addTable(tableName, dataSourceOption);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The table name. |
| `dataSourceOption` | [`IDataSourceOption`](../modules/GC.Data#idatasourceoption) | The data source option for creating a table, which contains the following properties. |

#### Returns

[`Table`](GC.Data.Table)

Returns the table.

___

### <a id="removerelationship" name="removerelationship"></a> removeRelationship

▸ **removeRelationship**(`name`): `void`

Removes a relationship from the data manager by source relationship name.

**`example`**
```
// Remove a relationship from the data manager by source relationship name
dataManager.removeRelationship("categories");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The source relationship name. |

#### Returns

`void`

___

### <a id="removetable" name="removetable"></a> removeTable

▸ **removeTable**(`name`): `void`

Removes a table from the data manager.

**`example`**
```
// Remove a table from data manager by table name
dataManager.removeTable("products");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The table name. |

#### Returns

`void`
