Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Latest commit

 

History

History
52 lines (39 loc) · 1.57 KB

File metadata and controls

52 lines (39 loc) · 1.57 KB

.driver

The generic, stateless, low-level driver for this datastore (if supported by the adapter).

datastore.driver;

This property is not guaranteed to exist for all database adapters. If the datastore's underlying adapter does not support the standardized driver interface, then driver will not exist.

Example

Imagine you're building your own structured data visualizer (e.g. phpMyAdmin). You might want to connect to any number of different databases dynamically.

// 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: manager })
  ).connection;
} catch (err) {
  await Driver.destroyManager({ manager: 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();