Schema

flitter-orm/src/schema/Schema~ Schema

Database schema base class. Provides logic for parsing and recursively building a schema from a definition, and coercing an object, recursively, to comply with the schema definition.


Constructor

new Schema(definition)

Instantiates the schema and builds the schema object from the provided definition.

Parameters:
Name Type Description
definition object

the schema definition

Members

definition :object

The original schema definition.

Type:
  • object

schema :object

The built schema object.

Type:
  • object

types :object

Schema types supported by this Schema class. Provides a mapping from reference name => Type class.

Type:
  • object

Methods

build_schema(defs) → {object}

Recursively build a schema object from the provided definition.

Parameters:
Name Type Description
defs object

the schema definition

Returns:
  • the schema object
Type
object

cast_to_schema(object, levelopt) → {object}

Cast the provided object to the specified schema. Particularly, this function is used externally to cast objects to this schema, recursively.

After this cast, the resulting object is safe to persist, at least for what this library guarantees.

Parameters:
Name Type Attributes Default Description
object object

object to cast

level object <optional>
false

the current level of the schema object (usually leave this blank)

Returns:
  • the casted object
Type
object

parse_default(default_value) → {function}

Create a function that returns the specified default value. If default_value is a function, it will be called. Otherwise, this will return a function that evaluates to default_value.

Parameters:
Name Type Description
default_value function | *
Returns:
Type
function

parse_type(type) → {module:flitter-orm/src/schema/Type~Type}

Parse the schema type from the specified type identifier.

Parameters:
Name Type Description
type Date | String | Number | Boolean | ObjectId | Array | Object