new DatabaseContext()
Creates a Cosmos DB connection. Uses environment variables:
DB_TYPE=azureCosmosCOSMOS_DB_HOST=the Cosmos URI/URLCOSMOS_DB_PASS=the passwordCOSMOS_DB_NAME=the name e.g. IsatDataProCOSMOS_DB_CONTAINER=the container e.g. MainCOSMOS_DB_PARTITION=categorythe partition keyCOSMOS_DB_THROUGHPUTthe throughput e.g. 400
Methods
-
close()
infra/database/repositories/azureCosmosRepository.js, line 267 -
Closes the database connection (null op for Cosmos DB)
-
delete(item){boolean}
infra/database/repositories/azureCosmosRepository.js, line 240 -
Deletes an item from the database
Name Type Description itemObject The category in the collection
Throws:
-
-
if database not initialized
- Type
- Error
-
-
-
if item.category is invalid
- Type
- Error
-
Returns:
Type Description boolean result -
-
find(category, include, exclude, options){Array.<Object>}
infra/database/repositories/azureCosmosRepository.js, line 82 -
Returns database entries matching a criteria
Name Type Description categorystring the model category e.g.
message_returnincludeObject optional key/value pairs for equality filtering
excludeObject optional key/value pairs for inequality filtering
optionsObject optional e.g.
{ limit: 1, desc: 'dbTimestamp' }Name Type Description limitnumber optional Maximum items to return
descstring optional Property to sort descending (e.g. _ts timestamp)
ascstring optional Property to sort descending (e.g. _ts timestamp)
Throws:
-
-
if database not initialized
- Type
- Error
-
-
-
if category is invalid
- Type
- Error
-
Returns:
Type Description Array.<Object> a list of row objects matching the criteria -
-
initialize()
infra/database/repositories/azureCosmosRepository.js, line 43 -
Initializes the database if/as required
-
upsert(item, filterOn, newerThan){Object}
infra/database/repositories/azureCosmosRepository.js, line 153 -
Updates an existing entity in the database or creates a new one. Null and undefined values are not pushed in an update. If the item includes a .newest prototype property it will discard update if older than that property in the database entity.
Name Type Description itemObject The item to upsert
filterOnObject optional Optional filter on properties defining "exists"
newerThanObject optional Optional filter on properties involving timestamp
Throws:
-
-
if database not initialized
- Type
- Error
-
-
-
if item.category is invalid
- Type
- Error
-
-
-
if filterOn is not an Object
- Type
- Error
-
-
-
if multiple matching entries found in database
- Type
- Error
-
Returns:
Type Description Object -