connectバージョン: v2.0
目次
connect()
この関数は、simply-xp をデータベースに接続し、クライアントオプションを構成するために使用します。
options.type を省略した場合、connect() は実行時に mongodb を既定値として使用します。
options 内で xp_rate を指定する場合は、"slow"、"normal"、"fast" のいずれか、または 0 より大きい有限数である必要があります。
パラメーター
Section titled “パラメーター”| Parameter | Type | Required | Description |
|---|---|---|---|
| uri | string | ✅ | データベース接続先の URI。 |
| options | ConnectionOptions | ❌ | クライアント構成用オプション。 |
- Promise<
boolean> - 接続が成功した場合はtrue。
XpFatal- 接続に失敗した場合、または URI が無効な場合。
[JS] 例
Section titled “[JS] 例”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