DatabaseModelsUnit

libflitter/database/DatabaseModelsUnit~ DatabaseModelsUnit

Unit to load and manage database models.


Constructor

new DatabaseModelsUnit(base_directoryopt)

Instantiate the unit.

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

base directory to search

Extends

Members

(static) name

Defines the name of the service provided by this unit: 'models'

(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>

canonical_item :string

The canonical name of the item.

Type:
  • string

canonical_items :object

Mapping of canonical names to instances for this item.

Type:
  • object

directory :Promise.<void>|Promise.<string>

The root directory for this canonical resource's files.

Type:
  • Promise.<void> | Promise.<string>

suffix :string

The file extension of the canonical item files.

Type:
  • string

Methods

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

Cleans up the unit's resources before Flitter closes.

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.

Returns:
Type
object

external_model(unit, name, instance) → {string}

Register an external model provided by a unit.

Parameters:
Name Type Description
unit libflitter/Unit~Unit

the parent unit of the model

name string

the name of the model

instance libflitter/database/Model~Model | object

model class

Returns:
  • the flitter canonical name of the registered model
Type
string

get(name) → {object}

Resolve an unqualified canonical name to a registered canonical item.

Parameters:
Name Type Description
name string
Returns:
Type
object

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

Initializes the unit. Ensures that the Flitter-ORM scaffold service exists.

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

the Flitter app

Returns:
Type
Promise.<void>

(async) init_canonical_file(info) → {Promise.<*>}

Prepare a single canonical model and return the value that should be given by the resolver.

Parameters:
Name Type Description
info object
Properties
Name Type Description
app module:libflitter/app/FlitterApp
name string

the unqualified canonical name

instance *

the static model CLASS from the file

Returns:
Type
Promise.<*>

model(name) → {Mongoose/Model}

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}

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