Class: DatabaseContext

repositories/azureCosmosRepository~ DatabaseContext

new DatabaseContext()

infra/database/repositories/azureCosmosRepository.js, line 34

Creates a Cosmos DB connection. Uses environment variables:

  • DB_TYPE=azureCosmos
  • COSMOS_DB_HOST= the Cosmos URI/URL
  • COSMOS_DB_PASS= the password
  • COSMOS_DB_NAME= the name e.g. IsatDataPro
  • COSMOS_DB_CONTAINER= the container e.g. Main
  • COSMOS_DB_PARTITION=category the partition key
  • COSMOS_DB_THROUGHPUT the 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
item Object

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
category string

the model category e.g. message_return

include Object optional

key/value pairs for equality filtering

exclude Object optional

key/value pairs for inequality filtering

options Object optional

e.g. { limit: 1, desc: 'dbTimestamp' }

Name Type Description
limit number optional

Maximum items to return

desc string optional

Property to sort descending (e.g. _ts timestamp)

asc string 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
item Object

The item to upsert

filterOn Object optional

Optional filter on properties defining "exists"

newerThan Object 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