The Database Unit
Creates Mongoose models from defined schemata and connects to the database.
constructor(String models_directory = './app/models')
Uses the path package to resolve the fully-qualified path to the models directory and stores it in
this.directory, which is where model schemata should be placed. Creates a new instance of
go(express app, function next)
Recursively iterates over all files in
this.directory and gets the model schemata from them. Then, creates Mongoose models for each schema using the name parsed from the file. Model names are parsed from the schema file name and follow the Flitter convention for sub-directory naming. For example, the schema file
models/auth/User.model.js would create a model with the name
auth:User. Creates global access functions for these models and schemata. Next, it tries to connect to the MongoDB using the credentials specified in the
database config. The
Database context is created here and the
next function in the stack is called under it.
Object describing the services, templates, and directories provided by this unit. They are as follows:
||The name of the service. This is added to the
||The fully-qualified path of the model schemata files. This is added to the
||Template that creates new model schema file in
Set on initialization. Specifies the fully-qualified path of the model schema files to be processed. Each of these files should export an
Object of key-value pairs that comprise the Mongoose schema for the model to be created. Each file's schema is assigned a name based on the name of the file it was retrieved from. This includes sub-directories. As is convention in Flitter, sub-directories are delineated with a
: character. So a schema loaded from the file
auth/User.model.js would be named
This context provides access to the imported schemata and their respective models, as well as a guaranteed-successful database connection.
Holds variables and functions provided in this context.
Contains the imported schemata in key-value pairs such that the keys are the parsed names of the schemata, which follow Flitter's convention for sub-directory naming, and the values are the
Object instances that contain the schemata.
Contains the Mongoose models created from the imported schemata in key-value pairs such that the keys are the parsed names of the models, which follow Flitter's convention for sub-directory naming, and the values are instances of
Contains the address used to connect to the MongoDB server. This is usually formatted:
Retrieves a schema with the specified
_flit.orm.schemas and returns it.
Retrieves a model with the specified
_flit.orm.models and returns it.