Data Source

Injectable as: db

The server-side api for retrieving and updating Business Objects.

db contains all of the Business Object Models for interfacing with the persistence layer, as described in Data Model

Todo

Document the Business Object Model’s enhanced mongoose API in mongoose_intercept and add a bo-model.rst

generateId()

Generates a random UUID and returns in URL-safe base64.

Returns

string – new v4 URL-safe base64-encoded UUID

_svc

Contains references to datasource submodules: field types, data triggers, query operations, gridFS access, reference processing, and package building/installation.

Internal Functions

Below are functions used internally for system initialization and package installation.

installBusinessObjectDef(bodObj)

Used internally for package installation. Creates or updates BOD in the database, and adds it to the Model cache. If the BOD indicates it is a child class whose parent model is not yet in the cache, it stores it to be installed on subsequent call for parent BOD

Todo

clean up return value to be more sensible

Arguments
  • bodObj (object) – a plain-object representation of a BusinessObjectDef

Returns

Promise.<(null|true)> – resolving to null when model is installed and initialization is complete or true if awaiting parent class installation

bootstrapDatabase(adminPw)

Used internally by CLI. Bootstrap a clean database

Arguments
  • adminPw (string) – password for admin account. If null, password is set to a newly-generated UUID and printed to console.error

Returns

Promise.<User> – business object for admin user

refreshModels()

Completely refresh data layer (called on package install). Delete all models in the cash, and reload from BusinessObjectDefs and MemberFunctions in the database

Returns

Promise – resolves when reload is complete

db.init(conf)

Initialize mongo connection and the entire data layer.

Arguments
  • conf (object) – instance configuration to use

Returns

Promise – resolved upon completion