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_directoryopt)

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

Parameters:
Name Type Attributes Default Description
models_directory string <optional>
'./app/models'

path to the directory with the model definition schemata

Extends

Members

(static) name

Gets the name of the service provided by this unit: 'database'

(static) services

Defines the services required by this unit.

(private) _di_allow_defer :boolean

If true, the injector will defer the class if the class requests any services that the container is missing. These services are filled in later and added to the prototype and any instances. True by default.

Type:
  • boolean

(private) _di_deferred_instances :Array.<module:flitter-di/src/Injectable~Injectable>

Collection of instances of this class that need to have the deferred service instances injected into them when the deferred services are finally provided.

(private) _di_deferred_services :Array.<string>

List of services that were deferred and not provided at the time of injection.

Type:
  • Array.<string>

connect_string

Get the standard formatted MongoDB connect string using the configured information. e.g. 'mongodb://user:pass@host:port/db' &c.

Methods

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

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}

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

Returns:
Type
Object

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

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>

migrations() → {string}

Get the fully-qualified path to the migrations provided by this unit.

Returns:
Type
string

name() → {String}

Get the name of the unit. Should be a lowercase, alphanum/dash/underscore string.

Returns:
Type
String

status(setopt) → {string}

Get or set the unit's current status.

Parameters:
Name Type Attributes Description
set string <optional>

if provided, set the status of the unit

Returns:
  • current status of the unit
Type
string

templates() → {Object}

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

Returns:
Type
Object