Connection
The first step to working with MVOM is to establish a connection to the database server via MVIS. Establishing a connection is facilitated via the Connection
class which is exported from MVOM as a named export.
Creating a connection
A connection to the database server is established using the createConnection
static factory method of the Connection
class. Calling this method will return an instance of the Connection
class.
Syntax
Connection.createConnection(mvisUrl: string, mvisAdminUrl: string, mvisAdminUsername: string, mvisAdminPassword: string, account: string, options?: CreateConnectionOptions): Connection
Parameters
Parameter | Type | Description | Example |
---|---|---|---|
mvisUrl | string | The URL to the MVIS server instance | http://foo.bar.com |
mvisAdminUrl | string | The URL of the MVIS Admin instance | mvis-admin.bar.com |
mvisAdminUsername | string | The username of a user account associated with the MVIS admin instance | username |
mvisAdminPassword | string | The password of a user account associated with the MVIS admin instance | password |
account | string | The account name as defined in MVIS configuration | demo |
options | object | Options object (see below) |
Options Object Properties
Property | Type | Default | Description |
---|---|---|---|
logger | Logger | An object implementing the Logger interface, used for logging messages emitted by MVOM | |
cacheMaxAge | number | 3600 | The maximum age of cached connection information, such as the current database date |
timeout | number | 0 | The request timeout in milliseconds (0 to disable) |
httpAgent | http.Agent | An http.Agent instance to use with http requests (recommended) | |
httpsAgent | https.Agent | An https.Agent instance to use with https requests (recommended) | |
maxReturnPayloadSize | number | 100_000_000 | The maximum allowed return payload size in bytes. If this size is exceeded a DbServerError will be thrown. Returning large payloads can have a significant impact on performance and is often the result of invalid database records or an improperly configured query; ie forgetting to use pagination. Tune this value to match your datasets and the type of queries you issue. This can also be configured on a per request basis. |
Example
import { Connection } from 'mvom';
const mvisUri = 'http://foo.bar.com';
const account = 'demo';
const options = { timeout: 30_000 };
const connection = Connection.createConnection(mvisUri, account, options);
Opening a connection
After a Connection
instance has been created, the connection must be opened before it can be used. The process of opening a connection will contact the MultiValue server and verify that the necessary database server subroutines have been installed. If they are available then the connection will be ready for use.
Syntax
open(options?: OpenOptions): Promise<void>
Parameters
Parameter | Type | Description | Example |
---|---|---|---|
options | object | Options object (see below) |
Options Object Properties
Property | Type | Default | Description |
---|---|---|---|
requestId | string | randomly generated UUID | A request/trace ID to be passed to MVIS as a request header with the key X-MVIS-Trace-Id |
Example
import { Connection } from 'mvom';
const mvisUri = 'http://foo.bar.com';
const account = 'demo';
const connectOptions = { timeout: 30_000 };
const openOptions = { requestId: 'trace' };
const makeConnection = async (): Connection => {
const connection = Connection.createConnection(mvisUri, account, connectOptions);
await connection.open(openOptions);
return connection;
};
export default makeConnection;
Deploying MVOM database server features
MVOM requires a database server subroutine called mvom_main
in order to perform its functionality on the database. If mvom_main
is not available, a connection cannot be established. The connection instance allows for manually deploying this subroutine, which will be cataloged globally for performance considerations. It is recommended to add handling for failed connections due to the subroutine not existing so that it is automatically deployed and the connection retried, but it is up to you when and how to deploy. The open
method will throw an InvalidServerFeaturesError
if the subroutine is out of date, and this error can be utilized as a trigger for deploying the subroutine.
Syntax
deploy(sourceDir: string, options?: DeployOptions)
Parameters
Parameter | Type | Description | Example |
---|---|---|---|
sourceDir | string | The directory on the database server where the subroutines will be created | mvom.bp |
options | object | Options object (see below) |
Options Object Properties
Property | Type | Default | Description |
---|---|---|---|
createDir | boolean | false | Create the directory prior to deploying if it is not present |