DataTableManager

When a custom integration performs scaffolding, the run method receives a project.dataTableManager parameter:

function run(config, project, context) {
  console.log(project.dataTableManager);
}

This parameter implements the DataTableManager interface, which contains methods for creating and retrieving database tables.

Note: The DataTableManager interface is, in many ways, similar to the FlowManager interface.

Signature

interface DataTableManager {
  createFolder(folderName: string): void;
  getFolders(): string[];
  createTable(folderName: string, table: DataTable): void;
  getTables(folderName: string): DataTable[];
}

Properties

NameTypeRequiredDescription
createFolder(folderName: string) => voidYesCreates a folder for organizing database tables.
getFolders() => string[];YesGets a list of database table folders.
createTable(folderName: string, table: DataTable) => void;YesCreates a database table in the specified folder.
getTables(folderName: string) => DataTable[];YesGets a list of database tables from the specified folder.

Methods

createFolder

Creates a folder for organizing database tables.

Signature

createFolder(folderName: string): void;

Usage

function run(config, project, context) {
  project.dataTableManager.createFolder("Hello world");
}

Parameters

NameTypeRequiredDescription
namestringYesThe name of the folder.

Returns

void

getFolders

Gets a list of database table folders.

Signature

getFolders(): string[];

Usage

function run(config, project, context) {
  project.dataTableManager.getFolders();
}

Parameters

This method doesn't have any parameters.

Returns

string[]

createTable

Creates a database table in the specified folder.

Signature

createTable(folderName: string, table: DataTable): void;

Usage

function run(config, project, context) {
  project.dataTableManager.createTable("Hello world", {
    name: "Posts",
    columns: [
      { name: "title", type: "string" },
      { name: "content", type: "string" },
      { name: "publishedAt", type: "datetime" },
    ],
  });
}

Parameters

NameTypeRequiredDescription
namestringYesThe name of the database table.
tableDataTableYesThe structure of the database table.

Returns

void

getTables

Gets a list of database tables from the specified folder.

Signature

getTables(folderName: string): DataTable[];

Usage

function run(config, project, context) {
  project.dataTableManager.getTables("Hello world");
}

Parameters

NameTypeRequiredDescription
folderNamestringYesThe name of a folder.

Returns

DataTable[]

Types

DataTable

Represents the structure of a database table.

Signature

type DataTable = {
  name: string;
  columns: Column[];
};

Properties

NameTypeRequiredDescription
namestringYesThe name of the database table.
columnsColumn[]YesThe database table's columns.

Column

Represents a column of a database table.

Signature

type Column = {
  name: string;
  nullable: boolean;
} & (
  | {
      type: "string";
      metadata?: {
        regex?: string;
        minLength?: number;
        maxLength?: number;
        defaultValue?: string;
      };
    }
  | {
      type: "integer" | "float" | "decimal";
      metadata?: {
        minValue?: number;
        maxValue?: number;
        defaultValue?: number;
      };
    }
  | {
      type: "guid";
      metadata?: {
        defaultValueExpression?: string;
        defaultValue?: string;
      };
    }
  | {
      type: "boolean";
      metadata?: {
        defaultValue?: boolean;
      };
    }
  | {
      type: "datetime";
      metadata?: {
        defaultValueExpression?: string;
        defaultValue?: string;
      };
    }
  | {
      type: "reference";
      metadata?: {
        ReferenceTypeId?: string;
      };
    }
);

Properties

The following properties are common to all data types:

NameTypeRequiredDescription
namestringYesThe name of the column.
nullablebooleanYesIf true, the column can contain null values.
typestringYesThe data type of the column.
metadataobjectNoOptions for configuring the behavior of the column.

Additional properties depend on the data type of the column.

string
NameTypeRequiredDescription
metadata.regexstringNoA regular expression for validating values that can be saved in the column.
metadata.minLengthstringNoThe minimum length of values that can be saved in the column.
metadata.maxLengthstringNoThe maximum length of values that can be saved in the column.
metadata.defaultValuestringNoWhen a value isn't otherwise provided, this value is used instead.
integer / float / decimal
NameTypeRequiredDescription
metadata.minValuenumberNoThe minimum allowed number that can be saved in the column.
metadata.maxValuenumberNoThe maximum allowed number that can be saved in the column.
metadata.defaultValuenumberNoWhen a value isn't otherwise provided, this value is used instead.
guid
NameTypeRequiredDescription
metadata.defaultExpressionValuestringNo???
metadata.defaultValuestringNoWhen a value isn't otherwise provided, this value is used instead.
boolean
NameTypeRequiredDescription
metadata.defaultValuebooleanNoWhen a value isn't otherwise provided, this value is used instead.
datetime
NameTypeRequiredDescription
metadata.defaultExpressionValuestringNo???
metadata.defaultValuestringNoWhen a value isn't otherwise provided, this value is used instead.
reference
NameTypeRequiredDescription
metadata.ReferenceTypeIdstringNo???