new DatabaseContext()
Creates a MySQL connection. Uses environment variables:
DB_TYPE=mysqlMYSQL_DB_HOST=the host name e.g. localhostMYSQL_DB_USER=the user name e.g. rootMYSQL_DB_PASS=the password for the userMYSQL_DB_NAME=the name of the database e.g. IsatDataPro
Methods
-
close()
infra/database/repositories/mysqlRepository.js, line 408 -
Closes the database connection
-
delete(item){boolean}
infra/database/repositories/mysqlRepository.js, line 354 -
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, older){Array.<Object>}
infra/database/repositories/mysqlRepository.js, line 188 -
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)
olderDate optional Searches for records older than the Date
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/mysqlRepository.js, line 113 -
Initializes the MySQL database if required
-
upsert(item, filterOn, newerThan){Object}
infra/database/repositories/mysqlRepository.js, line 265 -
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/table
- Type
- Error
-
Returns:
Type Description Object -