index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. 'use strict'
  2. const ConnectionPool = require('./connection-pool')
  3. const PreparedStatement = require('./prepared-statement')
  4. const Request = require('./request')
  5. const Transaction = require('./transaction')
  6. const { ConnectionError, TransactionError, RequestError, PreparedStatementError, MSSQLError } = require('../error')
  7. const shared = require('../shared')
  8. const Table = require('../table')
  9. const ISOLATION_LEVEL = require('../isolationlevel')
  10. const { TYPES } = require('../datatypes')
  11. const { connect, close, on, off, removeListener, query, batch } = require('../global-connection')
  12. module.exports = {
  13. ConnectionPool,
  14. Transaction,
  15. Request,
  16. PreparedStatement,
  17. ConnectionError,
  18. TransactionError,
  19. RequestError,
  20. PreparedStatementError,
  21. MSSQLError,
  22. driver: shared.driver,
  23. exports: {
  24. ConnectionError,
  25. TransactionError,
  26. RequestError,
  27. PreparedStatementError,
  28. MSSQLError,
  29. Table,
  30. ISOLATION_LEVEL,
  31. TYPES,
  32. MAX: 65535, // (1 << 16) - 1
  33. map: shared.map,
  34. getTypeByValue: shared.getTypeByValue,
  35. connect,
  36. close,
  37. on,
  38. removeListener,
  39. off,
  40. query,
  41. batch
  42. }
  43. }
  44. Object.defineProperty(module.exports, 'Promise', {
  45. enumerable: true,
  46. get: () => {
  47. return shared.Promise
  48. },
  49. set: (value) => {
  50. shared.Promise = value
  51. }
  52. })
  53. for (const key in TYPES) {
  54. const value = TYPES[key]
  55. module.exports.exports[key] = value
  56. module.exports.exports[key.toUpperCase()] = value
  57. }
  58. /**
  59. * @callback Request~requestCallback
  60. * @param {Error} err Error on error, otherwise null.
  61. * @param {Object} [result] Request result.
  62. */
  63. /**
  64. * @callback Request~bulkCallback
  65. * @param {Error} err Error on error, otherwise null.
  66. * @param {Number} [rowsAffected] Number of affected rows.
  67. */
  68. /**
  69. * @callback basicCallback
  70. * @param {Error} err Error on error, otherwise null.
  71. * @param {Connection} [connection] Acquired connection.
  72. */
  73. /**
  74. * @callback acquireCallback
  75. * @param {Error} err Error on error, otherwise null.
  76. * @param {Connection} [connection] Acquired connection.
  77. * @param {Object} [config] Connection config
  78. */
  79. /**
  80. * Dispatched after connection has established.
  81. * @event ConnectionPool#connect
  82. */
  83. /**
  84. * Dispatched after connection has closed a pool (by calling close).
  85. * @event ConnectionPool#close
  86. */
  87. /**
  88. * Dispatched when transaction begin.
  89. * @event Transaction#begin
  90. */
  91. /**
  92. * Dispatched on successful commit.
  93. * @event Transaction#commit
  94. */
  95. /**
  96. * Dispatched on successful rollback.
  97. * @event Transaction#rollback
  98. */
  99. /**
  100. * Dispatched when metadata for new recordset are parsed.
  101. * @event Request#recordset
  102. */
  103. /**
  104. * Dispatched when new row is parsed.
  105. * @event Request#row
  106. */
  107. /**
  108. * Dispatched when request is complete.
  109. * @event Request#done
  110. */
  111. /**
  112. * Dispatched on error.
  113. * @event Request#error
  114. */