Module: Schema

Schema factory.
Mixes In:

Members


<static, readonly> ValidationLevel :string

Enum to identify schema validation levels.
Type:
  • string
Example
ValidationLevel.OFF
ValidationLevel.STRICT

Methods


createCollection(name [, options])

Create a new collection in the schema.
Parameters:
Name Type Argument Description
name string collection name
options module:Schema.CreateCollectionOptions <optional>
Returns:
Type
Promise.<module:Collection>

dropCollection(name)

Drop a collection from the schema (without failing even if the collection does not exist).
Parameters:
Name Type Description
name string collection name
Returns:
Type
Promise.<boolean>

existsInDatabase()

Check if this schema exists in the database.
Returns:
Type
Promise.<boolean>

getCollection(name)

Retrieve the instance of a given collection.
Parameters:
Name Type Description
name string collection name
Returns:
Type
module:Collection

getCollectionAsTable(name)

Retrieve the instance of a given table or named collection.
Parameters:
Name Type Description
name string collection name
Returns:
Type
module:Table

getCollections()

Retrieve the list of collections that exist in the schema.
Returns:
A promise that resolves to the array of collection instances.
Type
Promise.<Array.<module:Collection>>

getName()

Retrieve the schema name.
Returns:
Type
string

getTable(name)

Retrieve the instance of a given table.
Parameters:
Name Type Description
name string table name
Returns:
Type
module:Table

getTables()

Retrieve the list of tables that exist in the schema.
Returns:
A promise that resolves to the array of table instances.
Type
Promise.<Array.<module:Table>>

inspect()

Retrieve the schema metadata.
Returns:
An object containing the relevant metadata.
Type
Object

modifyCollection(name [, options])

Modify the options of an existing collection in the schema.
Parameters:
Name Type Argument Description
name string collection name
options module:Schema.ModifyCollectionOptions <optional>
Returns:
Type
Promise.<module:Collection>

Type Definitions


CreateCollectionOptions

Options available for creating a new collection.
Type:
  • object
Properties:
Name Type Argument Description
reuseExisting bool <optional>
re-use or throw error if a collection with the same name already exists
validation module:Schema.SchemaValidationOptions <optional>
schema validation options

ModifyCollectionOptions

Options available for modifying an existing collection.
Type:
  • object
Properties:
Name Type Argument Description
validation module:Schema.SchemaValidationOptions <optional>
schema validation options

SchemaValidationOptions

Options available for specifying a collection validation schema.
Type:
  • object
Properties:
Name Type Argument Description
schema object <optional>
JSON Schema definition
level module:Schema.ValidationLevel <optional>
enforcement level