Constructor
new DatabaseUnit(models_directoryopt)
Instantiate the unit. Resolve the path to the directory with the model definition schemata.
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) provides
Return the services provided by this unit. In this case, the ORM scaffold service is registered.
(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.
- boolean
- Overrides:
- Source:
(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.
- Source:
(private) _di_deferred_services :Array.<string>
List of services that were deferred and not provided at the time of injection.
- Array.<string>
- Source:
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.
Name | Type | Description |
---|---|---|
app |
module:libflitter/app/FlitterApp~FlitterApp | the Flitter app |
- Overrides:
- Type
- Promise.<void>
directories() → {Object}
Get the directories provided by this unit. Currently, module:libflitter/database/DatabaseUnit~DatabaseUnit#directory
- Overrides:
- 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.
Name | Type | Description |
---|---|---|
app |
module:libflitter/app/FlitterApp~FlitterApp | the Flitter app |
context |
module:libflitter/Context~Context | the Unit's context |
- Overrides:
- Type
- Promise.<void>
migrations() → {string}
Get the fully-qualified path to the migrations provided by this unit.
- Type
- string
name() → {String}
Get the name of the unit. Should be a lowercase, alphanum/dash/underscore string.
- Overrides:
- Source:
- Type
- String
status(setopt) → {string}
Get or set the unit's current status.
Name | Type | Attributes | Description |
---|---|---|---|
set |
string |
<optional> |
if provided, set the status of the unit |
- Overrides:
- Source:
- current status of the unit
- Type
- string
templates() → {Object}
Get the templates provided by the unit. Currently, "model" provided by module:libflitter/templates/model
- Type
- Object