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