DatabaseUnit

libflitter/database/DatabaseUnit~ DatabaseUnit

The database unit loads the model schemas from the specified directory and creates Mongoose models from them. Then, using the specified values it connects to the MongoDB database and continues initializing the stack from within the context of a guaranteed connection to the database.

Constructor

new DatabaseUnit(models_directory)

Source:

Instantiate the unit. Resolve the path to the directory with the model definition schemata.

Parameters:
Name Type Default Description
models_directory string ./app/models

path to the directory with the model definition schemata

Extends

Methods

(async) cleanup(app) → {Promise.<void>}

Source:
Overrides:

Cleans up the unit's resources before Flitter exits. Closes the MongoDB connection cleanly.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

Returns:
Type
Promise.<void>

directories() → {Object}

Source:
Overrides:

Get the directories provided by this unit. Currently, module:libflitter/database/DatabaseUnit~DatabaseUnit#directory

Returns:
Type
Object

(async) go(app, context) → {Promise.<void>}

Source:
Overrides:

Loads the unit. Loads the model definition schemata from module:libflitter/database/DatabaseUnit~DatabaseUnit#directory and creates Mongoose models from them. Then, it binds the models, schemata, and helper functions to the appropriate contexts. Opens the database connection using the values configured in the 'database' configuration.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

context module:libflitter/Context~Context

the Unit's context

Returns:
Type
Promise.<void>

model(name) → {Mongoose/Model}

Source:

Helper function to get the Mongoose model instance by its Flitter canonical name. This is usually bound to the relevant module:libflitter/app/FlitterApp~FlitterApp instance.

Parameters:
Name Type Description
name string

the Flitter canonical name of the model

Returns:
Type
Mongoose/Model

name() → {string}

Source:
Overrides:

Get the name of the unit.

Returns:

"database"

Type
string

schema(name) → {Object}

Source:

Helper function to get the model definition schema instance by its Flitter canonical name. This is usually bound to the relevant module:libflitter/app/FlitterApp~FlitterApp instance.

Parameters:
Name Type Description
name string

the Flitter canonical name of the model definition schema

Returns:
Type
Object

templates() → {Object}

Source:

Get the templates provided by the unit. Currently, "model" provided by module:libflitter/templates/model

Returns:
Type
Object