.driver
このデータストアの汎用的でステートレスな低レベルドライバ(アダプタでサポートされている場合)。
datastore.driver;
このプロパティは、すべてデータベースアダプタで存在することが保証されていません。データストアの基盤となるアダプタが標準化されたドライバインターフェースをサポートしていない場合、
driver
は存在しません。
独自の構造化データビジュアライザ(例:phpMyAdmin)を構築しているとします。さまざまなデータベースに動的に接続したい場合があります。
// Get the generic, stateless driver for our database (e.g. MySQL).
var Driver = sails.getDatastore().driver;
// Create our own dynamic connection manager (e.g. connection pool)
var manager = (
await Driver.createManager({ connectionString: req.param('connectionUrl') })
).manager;
var db;
try {
db = (
await Driver.getConnection({ manager: managerReport.manager })
).connection;
} catch (err) {
await Driver.destroyManager({ manager: managerReport.manager });
throw err;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Do some stuff here...
// e.g.
// await Driver.sendNativeQuery({
// connection: db,
// nativeQuery: '...'
// });
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Finally, before we continue, tear down the dynamic connection manager.
// (this also takes care of releasing the active connection we acquired above)
await Driver.destroyManager({ manager: managerReport.manager });
return res.ok();