index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict';
  2. const SqlString = require('sqlstring');
  3. const Connection = require('./lib/connection.js');
  4. const ConnectionConfig = require('./lib/connection_config.js');
  5. const parserCache = require('./lib/parsers/parser_cache');
  6. exports.createConnection = function(opts) {
  7. return new Connection({ config: new ConnectionConfig(opts) });
  8. };
  9. exports.connect = exports.createConnection;
  10. exports.Connection = Connection;
  11. const Pool = require('./lib/pool.js');
  12. exports.createPool = function(config) {
  13. const PoolConfig = require('./lib/pool_config.js');
  14. return new Pool({ config: new PoolConfig(config) });
  15. };
  16. exports.createPoolCluster = function(config) {
  17. const PoolCluster = require('./lib/pool_cluster.js');
  18. return new PoolCluster(config);
  19. };
  20. exports.createQuery = Connection.createQuery;
  21. exports.Pool = Pool;
  22. exports.createServer = function(handler) {
  23. const Server = require('./lib/server.js');
  24. const s = new Server();
  25. if (handler) {
  26. s.on('connection', handler);
  27. }
  28. return s;
  29. };
  30. exports.PoolConnection = require('./lib/pool_connection');
  31. exports.escape = SqlString.escape;
  32. exports.escapeId = SqlString.escapeId;
  33. exports.format = SqlString.format;
  34. exports.raw = SqlString.raw;
  35. exports.__defineGetter__(
  36. 'createConnectionPromise',
  37. () => require('./promise.js').createConnection
  38. );
  39. exports.__defineGetter__(
  40. 'createPoolPromise',
  41. () => require('./promise.js').createPool
  42. );
  43. exports.__defineGetter__(
  44. 'createPoolClusterPromise',
  45. () => require('./promise.js').createPoolCluster
  46. );
  47. exports.__defineGetter__('Types', () => require('./lib/constants/types.js'));
  48. exports.__defineGetter__('Charsets', () =>
  49. require('./lib/constants/charsets.js')
  50. );
  51. exports.__defineGetter__('CharsetToEncoding', () =>
  52. require('./lib/constants/charset_encodings.js')
  53. );
  54. exports.setMaxParserCache = function(max) {
  55. parserCache.setMaxCache(max);
  56. };
  57. exports.clearParserCache = function() {
  58. parserCache.clearCache();
  59. };