Introduction
Databases in SOAJS are dynamic Registry entries. Each database is linked to a cluster and altogether form up the configuration that the database client connector needs to establish and maintain the database connection.
Objective
- Manage Databases
- Prefix
- Session
- Connecting to a Database
Manage Databases
This modules provides wizards to create and manage databases' entries inside the registry.
Managing databases is very easy with SOAJS, each database requires a name, the cluster it should use and simply specify if it is a standalone or multitenant database.
Once Created, SOAJS will provide the databases via the registry object at runtime: req.soajs.registry.
If you are using MongoDB as a database, you can use the SOAJS Mongo Client Driver and benefit from communicating with multitenant and standalone databases. Click here to learn more.
List Databases | Add New Database |
---|---|
Prefix
You can add an optional prefix to your databases, by default the value is empty.
If you enter a prefix, the prefix is automatically added to the database name when you request the registry information from SOAJS.
EX:
Prefix: test_
Database: myDatabase
Result:
{ "test_myDatabase": { "prefix": "test_", "servers": [{ "host": "127.0.0.1", "port": 27017 }], "credentials": null, "streaming": {}, "URLParam": { "connectTimeoutMS": 0, "socketTimeoutMS": 0, "maxPoolSize": 5, "wtimeoutMS": 0, "slaveOk": true }, "registryLocation": { "l1": "coreDB", "l2": "myDatabase", "env": "dev" }, "name": "myDatabase" } }
Session
The session database has a different configuration since this database comes equipped with a store so you can save data and share it between the microservices deployed.
In addition to the store and unlike normal database entries, session entries automatically expire after a period of time that is also configurable.
You can read more about session store on Express session store.
Connecting to a Database
Once a database has been created, you can connect to it in your code by fetching its entry from the Registry.
Grab the Database entry from the registry and pass it to your Client Driver. If your database is a MongoDB, you can use the SOAJS Mongo Client (examples available).
Add Comment