connect()
This function is used to connect simply-xp to a database, and configure client options.
If options.type is omitted, connect() defaults to mongodb at runtime.
When provided, xp_rate in options must be "slow", "normal", "fast", or a finite number greater than 0.
Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
| uri | string | β | The URI to connect to the database. |
| options | ConnectionOptions | β | The options to configure the client. |
Returnsβ
- Promise<
boolean> - If the connection was successful.
Throwsβ
XpFatal- If the connection was unsuccessful, or if the URI is invalid.XpFatalwitherror.code === "SX_ADAPTER_MISSING"- If the adapter package for the selectedtype(mongodborbetter-sqlite3) is not installed. The message includes the exact install command to run.
[JS] Exampleβ
const {connect} = require('simply-xp');
connect('path/to/file.sqlite', { type: 'sqlite' }) // Returns Promise<boolean>
.then(console.log) // Returns true if connection was successful
.catch((err) => console.log(err)); // Returns the error