DynamicSchema()

new DynamicSchema()

Create an new DynamicSchema instance

Members

definition :object

The table's column definitions.

tableName :string

The name of the table.

tableSlug :string

The slug of the table.

Methods

addColumn(name, type, descriptionopt) → {Promise}

Add a single column to the table's schema definition.

Parameters:
Name Type Attributes Description
name string

The name of the column to add

type string

Type of the column to add

description string <optional>

Description of the column to add

Returns:
Promise

addColumns(definitions) → {Promise}

Add multiple columns to the table's schema definition.

Parameters:
Name Type Description
definitions object

Object of objects containing new columns definitions

Returns:
Promise

addIndex(options) → {Promise}

Add an index to the table's schema.

Parameters:
Name Type Description
options object
Properties
Name Type Attributes Description
name string

The name of the column to be used as index

unique boolean <optional>

Whether the index is unique or not

autoInrement boolean <optional>

Whether it is an auto-incrementing index or not. If true, options.unique is automatically set to true

Returns:
Promise

changeColumnType(name, newType) → {Promise}

Change the type of a single column in the table's schema definition.

Parameters:
Name Type Description
name string

The name of the column to change type

newType string

The new type of the target column

Returns:
Promise

createTable(schema) → {Promise}

Create a new table with the given schema. Schema must adhere to the JSON Schema definition set out in https://json-schema.org/

Each property corresponds to each column in the database. A few custom attributes to each property can be included for use by DynamicSchema to generate columns for special behaviour.

These properties are:

  • isIndex: Whether the column is an index field
  • isUnique: Whether the column is an unique field
  • isAutoIncrement: Whether the column is an auto-incrementing integer
Parameters:
Name Type Description
schema object
Properties
Name Type Attributes Description
$id string

ID of the table, must be unique

title string <optional>

Defaults to schema.$id

properties object

The column definitions of the table

Returns:
Promise

define(definition) → {Promise}

Define the table's columns. Passed object must adhere to properties attribute of JSON Schema's definition.

Parameters:
Name Type Description
definition object

Definition of the table columns

Returns:
Promise

read(tableSlug) → {Promise}

Read the schema definition from the database.

Parameters:
Name Type Description
tableSlug string

The name of the table schema to retrieve

Returns:
Promise -
  • Return promise, resolves to this object instance

removeColumn(name) → {Promise}

Remove a single column from the table's schema definition.

Parameters:
Name Type Description
name string

The name of the column to remove

Returns:
Promise

removeIndex(columnName) → {Promise}

Remove an index to the table's schema

Parameters:
Name Type Description
columnName string

The name of the index to remove

Returns:
Promise

renameColumn(name, newName) → {Promise}

Rename a single column in the table's schema definition.

Parameters:
Name Type Description
name string

The name of the column to rename

newName string

The new name of the target column

Returns:
Promise

renameTable(newSlug, newNameopt) → {Promise}

Add an index to the table's schema

Parameters:
Name Type Attributes Description
newSlug string
newName string <optional>

Defaults to newSlug

Returns:
Promise