promise.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const pkg = require('./package.json')
  3. require('please-upgrade-node')(pkg)
  4. const Connection = require('./lib/connection');
  5. const PoolPromise = require('./lib/pool-promise');
  6. const PoolCluster = require('./lib/pool-cluster');
  7. const ConnOptions = require('./lib/config/connection-options');
  8. const PoolOptions = require('./lib/config/pool-options');
  9. const PoolClusterOptions = require('./lib/config/pool-cluster-options');
  10. module.exports.version = require('./package.json').version;
  11. module.exports.SqlError = require('./lib/misc/errors').SqlError;
  12. module.exports.createConnection = function createConnection(opts) {
  13. try {
  14. const options = new ConnOptions(opts);
  15. return new Connection(options).connect();
  16. } catch (err) {
  17. return Promise.reject(err);
  18. }
  19. };
  20. module.exports.createPool = function createPool(opts) {
  21. const options = new PoolOptions(opts);
  22. const pool = new PoolPromise(options, false);
  23. pool.initialize();
  24. return pool;
  25. };
  26. module.exports.createPoolCluster = function createPoolCluster(opts) {
  27. const options = new PoolClusterOptions(opts);
  28. return new PoolCluster(options);
  29. };