@contember/database 2.1.0-rc.3 → 2.2.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/CLAUDE.md +22 -0
  2. package/dist/development/index.cjs +9 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +10 -1
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/builders/CaseStatement.cjs.map +1 -1
  7. package/dist/development/src/builders/CaseStatement.js.map +1 -1
  8. package/dist/development/src/builders/ColumnExpressionFactory.cjs.map +1 -1
  9. package/dist/development/src/builders/ColumnExpressionFactory.js.map +1 -1
  10. package/dist/development/src/builders/Compiler.cjs.map +1 -1
  11. package/dist/development/src/builders/Compiler.js.map +1 -1
  12. package/dist/development/src/builders/ConditionBuilder.cjs +6 -0
  13. package/dist/development/src/builders/ConditionBuilder.cjs.map +1 -1
  14. package/dist/development/src/builders/ConditionBuilder.js +6 -0
  15. package/dist/development/src/builders/ConditionBuilder.js.map +1 -1
  16. package/dist/development/src/builders/DeleteBuilder.cjs.map +1 -1
  17. package/dist/development/src/builders/DeleteBuilder.js.map +1 -1
  18. package/dist/development/src/builders/InsertBuilder.cjs.map +1 -1
  19. package/dist/development/src/builders/InsertBuilder.js.map +1 -1
  20. package/dist/development/src/builders/LimitByGroupWrapper.cjs +1 -1
  21. package/dist/development/src/builders/LimitByGroupWrapper.cjs.map +1 -1
  22. package/dist/development/src/builders/LimitByGroupWrapper.js +1 -1
  23. package/dist/development/src/builders/LimitByGroupWrapper.js.map +1 -1
  24. package/dist/development/src/builders/SelectBuilder.cjs.map +1 -1
  25. package/dist/development/src/builders/SelectBuilder.js.map +1 -1
  26. package/dist/development/src/builders/UpdateBuilder.cjs.map +1 -1
  27. package/dist/development/src/builders/UpdateBuilder.js.map +1 -1
  28. package/dist/development/src/builders/WindowFunction.cjs +1 -1
  29. package/dist/development/src/builders/WindowFunction.cjs.map +1 -1
  30. package/dist/development/src/builders/WindowFunction.js +1 -1
  31. package/dist/development/src/builders/WindowFunction.js.map +1 -1
  32. package/dist/development/src/builders/internal/Returning.cjs.map +1 -1
  33. package/dist/development/src/builders/internal/Returning.js.map +1 -1
  34. package/dist/development/src/builders/internal/Subqueries.cjs.map +1 -1
  35. package/dist/development/src/builders/internal/Subqueries.js.map +1 -1
  36. package/dist/development/src/builders/internal/Where.cjs.map +1 -1
  37. package/dist/development/src/builders/internal/Where.js.map +1 -1
  38. package/dist/development/src/builders/internal/With.cjs.map +1 -1
  39. package/dist/development/src/builders/internal/With.js.map +1 -1
  40. package/dist/development/src/builders/utils.cjs.map +1 -1
  41. package/dist/development/src/builders/utils.js.map +1 -1
  42. package/dist/development/src/client/AcquiredConnection.cjs +105 -32
  43. package/dist/development/src/client/AcquiredConnection.cjs.map +1 -1
  44. package/dist/development/src/client/AcquiredConnection.js +107 -34
  45. package/dist/development/src/client/AcquiredConnection.js.map +1 -1
  46. package/dist/development/src/client/Client.cjs +9 -1
  47. package/dist/development/src/client/Client.cjs.map +1 -1
  48. package/dist/development/src/client/Client.js +9 -1
  49. package/dist/development/src/client/Client.js.map +1 -1
  50. package/dist/development/src/client/Connection.cjs +19 -1
  51. package/dist/development/src/client/Connection.cjs.map +1 -1
  52. package/dist/development/src/client/Connection.js +19 -1
  53. package/dist/development/src/client/Connection.js.map +1 -1
  54. package/dist/development/src/client/EventManager.cjs +6 -2
  55. package/dist/development/src/client/EventManager.cjs.map +1 -1
  56. package/dist/development/src/client/EventManager.js +6 -2
  57. package/dist/development/src/client/EventManager.js.map +1 -1
  58. package/dist/development/src/client/Pool.cjs.map +1 -1
  59. package/dist/development/src/client/Pool.js.map +1 -1
  60. package/dist/development/src/client/RequestMemoryBudget.cjs +237 -0
  61. package/dist/development/src/client/RequestMemoryBudget.cjs.map +1 -0
  62. package/dist/development/src/client/RequestMemoryBudget.js +237 -0
  63. package/dist/development/src/client/RequestMemoryBudget.js.map +1 -0
  64. package/dist/development/src/client/ScopeLimitedConnection.cjs +37 -0
  65. package/dist/development/src/client/ScopeLimitedConnection.cjs.map +1 -0
  66. package/dist/development/src/client/ScopeLimitedConnection.js +37 -0
  67. package/dist/development/src/client/ScopeLimitedConnection.js.map +1 -0
  68. package/dist/development/src/client/Transaction.cjs +20 -8
  69. package/dist/development/src/client/Transaction.cjs.map +1 -1
  70. package/dist/development/src/client/Transaction.js +21 -9
  71. package/dist/development/src/client/Transaction.js.map +1 -1
  72. package/dist/development/src/client/cancelRunningStatement.cjs +32 -0
  73. package/dist/development/src/client/cancelRunningStatement.cjs.map +1 -0
  74. package/dist/development/src/client/cancelRunningStatement.js +32 -0
  75. package/dist/development/src/client/cancelRunningStatement.js.map +1 -0
  76. package/dist/development/src/client/errors.cjs +6 -0
  77. package/dist/development/src/client/errors.cjs.map +1 -1
  78. package/dist/development/src/client/errors.js +6 -0
  79. package/dist/development/src/client/errors.js.map +1 -1
  80. package/dist/development/src/metadata/DatabaseMetadata.cjs.map +1 -1
  81. package/dist/development/src/metadata/DatabaseMetadata.js.map +1 -1
  82. package/dist/development/src/metadata/DatabaseMetadataResolver.cjs.map +1 -1
  83. package/dist/development/src/metadata/DatabaseMetadataResolver.js.map +1 -1
  84. package/dist/development/src/metadata/IndexMetadata.cjs.map +1 -1
  85. package/dist/development/src/metadata/IndexMetadata.js.map +1 -1
  86. package/dist/development/src/metadata/UniqueConstraintMetadata.cjs.map +1 -1
  87. package/dist/development/src/metadata/UniqueConstraintMetadata.js.map +1 -1
  88. package/dist/development/src/queryable/DatabaseQuery.cjs.map +1 -1
  89. package/dist/development/src/queryable/DatabaseQuery.js.map +1 -1
  90. package/dist/development/src/queryable/DatabaseQueryable.cjs.map +1 -1
  91. package/dist/development/src/queryable/DatabaseQueryable.js.map +1 -1
  92. package/dist/development/src/utils/ConstraintHelper.cjs.map +1 -1
  93. package/dist/development/src/utils/ConstraintHelper.js.map +1 -1
  94. package/dist/development/src/utils/Semaphore.cjs +43 -0
  95. package/dist/development/src/utils/Semaphore.cjs.map +1 -0
  96. package/dist/development/src/utils/Semaphore.js +43 -0
  97. package/dist/development/src/utils/Semaphore.js.map +1 -0
  98. package/dist/development/src/utils/createDatabaseIfNotExists.cjs.map +1 -1
  99. package/dist/development/src/utils/createDatabaseIfNotExists.js.map +1 -1
  100. package/dist/development/src/utils/listen.cjs.map +1 -1
  101. package/dist/development/src/utils/listen.js.map +1 -1
  102. package/dist/development/src/utils/pgClientFactory.cjs +9 -4
  103. package/dist/development/src/utils/pgClientFactory.cjs.map +1 -1
  104. package/dist/development/src/utils/pgClientFactory.js +9 -4
  105. package/dist/development/src/utils/pgClientFactory.js.map +1 -1
  106. package/dist/development/src/utils/retryTransaction.cjs.map +1 -1
  107. package/dist/development/src/utils/retryTransaction.js.map +1 -1
  108. package/dist/development/src/utils/sql.cjs.map +1 -1
  109. package/dist/development/src/utils/sql.js.map +1 -1
  110. package/dist/development/src/utils/withDatabaseAdvisoryLock.cjs.map +1 -1
  111. package/dist/development/src/utils/withDatabaseAdvisoryLock.js.map +1 -1
  112. package/dist/production/index.cjs +9 -0
  113. package/dist/production/index.cjs.map +1 -1
  114. package/dist/production/index.js +10 -1
  115. package/dist/production/index.js.map +1 -1
  116. package/dist/production/src/builders/CaseStatement.cjs.map +1 -1
  117. package/dist/production/src/builders/CaseStatement.js.map +1 -1
  118. package/dist/production/src/builders/ColumnExpressionFactory.cjs.map +1 -1
  119. package/dist/production/src/builders/ColumnExpressionFactory.js.map +1 -1
  120. package/dist/production/src/builders/Compiler.cjs.map +1 -1
  121. package/dist/production/src/builders/Compiler.js.map +1 -1
  122. package/dist/production/src/builders/ConditionBuilder.cjs +6 -0
  123. package/dist/production/src/builders/ConditionBuilder.cjs.map +1 -1
  124. package/dist/production/src/builders/ConditionBuilder.js +6 -0
  125. package/dist/production/src/builders/ConditionBuilder.js.map +1 -1
  126. package/dist/production/src/builders/DeleteBuilder.cjs.map +1 -1
  127. package/dist/production/src/builders/DeleteBuilder.js.map +1 -1
  128. package/dist/production/src/builders/InsertBuilder.cjs.map +1 -1
  129. package/dist/production/src/builders/InsertBuilder.js.map +1 -1
  130. package/dist/production/src/builders/LimitByGroupWrapper.cjs +1 -1
  131. package/dist/production/src/builders/LimitByGroupWrapper.cjs.map +1 -1
  132. package/dist/production/src/builders/LimitByGroupWrapper.js +1 -1
  133. package/dist/production/src/builders/LimitByGroupWrapper.js.map +1 -1
  134. package/dist/production/src/builders/SelectBuilder.cjs.map +1 -1
  135. package/dist/production/src/builders/SelectBuilder.js.map +1 -1
  136. package/dist/production/src/builders/UpdateBuilder.cjs.map +1 -1
  137. package/dist/production/src/builders/UpdateBuilder.js.map +1 -1
  138. package/dist/production/src/builders/WindowFunction.cjs +1 -1
  139. package/dist/production/src/builders/WindowFunction.cjs.map +1 -1
  140. package/dist/production/src/builders/WindowFunction.js +1 -1
  141. package/dist/production/src/builders/WindowFunction.js.map +1 -1
  142. package/dist/production/src/builders/internal/Returning.cjs.map +1 -1
  143. package/dist/production/src/builders/internal/Returning.js.map +1 -1
  144. package/dist/production/src/builders/internal/Subqueries.cjs.map +1 -1
  145. package/dist/production/src/builders/internal/Subqueries.js.map +1 -1
  146. package/dist/production/src/builders/internal/Where.cjs.map +1 -1
  147. package/dist/production/src/builders/internal/Where.js.map +1 -1
  148. package/dist/production/src/builders/internal/With.cjs.map +1 -1
  149. package/dist/production/src/builders/internal/With.js.map +1 -1
  150. package/dist/production/src/builders/utils.cjs.map +1 -1
  151. package/dist/production/src/builders/utils.js.map +1 -1
  152. package/dist/production/src/client/AcquiredConnection.cjs +105 -32
  153. package/dist/production/src/client/AcquiredConnection.cjs.map +1 -1
  154. package/dist/production/src/client/AcquiredConnection.js +107 -34
  155. package/dist/production/src/client/AcquiredConnection.js.map +1 -1
  156. package/dist/production/src/client/Client.cjs +9 -1
  157. package/dist/production/src/client/Client.cjs.map +1 -1
  158. package/dist/production/src/client/Client.js +9 -1
  159. package/dist/production/src/client/Client.js.map +1 -1
  160. package/dist/production/src/client/Connection.cjs +19 -1
  161. package/dist/production/src/client/Connection.cjs.map +1 -1
  162. package/dist/production/src/client/Connection.js +19 -1
  163. package/dist/production/src/client/Connection.js.map +1 -1
  164. package/dist/production/src/client/EventManager.cjs +6 -2
  165. package/dist/production/src/client/EventManager.cjs.map +1 -1
  166. package/dist/production/src/client/EventManager.js +6 -2
  167. package/dist/production/src/client/EventManager.js.map +1 -1
  168. package/dist/production/src/client/Pool.cjs.map +1 -1
  169. package/dist/production/src/client/Pool.js.map +1 -1
  170. package/dist/production/src/client/RequestMemoryBudget.cjs +237 -0
  171. package/dist/production/src/client/RequestMemoryBudget.cjs.map +1 -0
  172. package/dist/production/src/client/RequestMemoryBudget.js +237 -0
  173. package/dist/production/src/client/RequestMemoryBudget.js.map +1 -0
  174. package/dist/production/src/client/ScopeLimitedConnection.cjs +37 -0
  175. package/dist/production/src/client/ScopeLimitedConnection.cjs.map +1 -0
  176. package/dist/production/src/client/ScopeLimitedConnection.js +37 -0
  177. package/dist/production/src/client/ScopeLimitedConnection.js.map +1 -0
  178. package/dist/production/src/client/Transaction.cjs +20 -8
  179. package/dist/production/src/client/Transaction.cjs.map +1 -1
  180. package/dist/production/src/client/Transaction.js +21 -9
  181. package/dist/production/src/client/Transaction.js.map +1 -1
  182. package/dist/production/src/client/cancelRunningStatement.cjs +32 -0
  183. package/dist/production/src/client/cancelRunningStatement.cjs.map +1 -0
  184. package/dist/production/src/client/cancelRunningStatement.js +32 -0
  185. package/dist/production/src/client/cancelRunningStatement.js.map +1 -0
  186. package/dist/production/src/client/errors.cjs +6 -0
  187. package/dist/production/src/client/errors.cjs.map +1 -1
  188. package/dist/production/src/client/errors.js +6 -0
  189. package/dist/production/src/client/errors.js.map +1 -1
  190. package/dist/production/src/metadata/DatabaseMetadata.cjs.map +1 -1
  191. package/dist/production/src/metadata/DatabaseMetadata.js.map +1 -1
  192. package/dist/production/src/metadata/DatabaseMetadataResolver.cjs.map +1 -1
  193. package/dist/production/src/metadata/DatabaseMetadataResolver.js.map +1 -1
  194. package/dist/production/src/metadata/IndexMetadata.cjs.map +1 -1
  195. package/dist/production/src/metadata/IndexMetadata.js.map +1 -1
  196. package/dist/production/src/metadata/UniqueConstraintMetadata.cjs.map +1 -1
  197. package/dist/production/src/metadata/UniqueConstraintMetadata.js.map +1 -1
  198. package/dist/production/src/queryable/DatabaseQuery.cjs.map +1 -1
  199. package/dist/production/src/queryable/DatabaseQuery.js.map +1 -1
  200. package/dist/production/src/queryable/DatabaseQueryable.cjs.map +1 -1
  201. package/dist/production/src/queryable/DatabaseQueryable.js.map +1 -1
  202. package/dist/production/src/utils/ConstraintHelper.cjs.map +1 -1
  203. package/dist/production/src/utils/ConstraintHelper.js.map +1 -1
  204. package/dist/production/src/utils/Semaphore.cjs +43 -0
  205. package/dist/production/src/utils/Semaphore.cjs.map +1 -0
  206. package/dist/production/src/utils/Semaphore.js +43 -0
  207. package/dist/production/src/utils/Semaphore.js.map +1 -0
  208. package/dist/production/src/utils/createDatabaseIfNotExists.cjs.map +1 -1
  209. package/dist/production/src/utils/createDatabaseIfNotExists.js.map +1 -1
  210. package/dist/production/src/utils/listen.cjs.map +1 -1
  211. package/dist/production/src/utils/listen.js.map +1 -1
  212. package/dist/production/src/utils/pgClientFactory.cjs +9 -4
  213. package/dist/production/src/utils/pgClientFactory.cjs.map +1 -1
  214. package/dist/production/src/utils/pgClientFactory.js +9 -4
  215. package/dist/production/src/utils/pgClientFactory.js.map +1 -1
  216. package/dist/production/src/utils/retryTransaction.cjs.map +1 -1
  217. package/dist/production/src/utils/retryTransaction.js.map +1 -1
  218. package/dist/production/src/utils/sql.cjs.map +1 -1
  219. package/dist/production/src/utils/sql.js.map +1 -1
  220. package/dist/production/src/utils/withDatabaseAdvisoryLock.cjs.map +1 -1
  221. package/dist/production/src/utils/withDatabaseAdvisoryLock.js.map +1 -1
  222. package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts +2 -0
  223. package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts.map +1 -0
  224. package/dist/tests/cases/unit/acquiredConnection.test.d.ts +2 -0
  225. package/dist/tests/cases/unit/acquiredConnection.test.d.ts.map +1 -0
  226. package/dist/tests/cases/unit/createConnectionMockAlt.d.ts +6 -3
  227. package/dist/tests/cases/unit/createConnectionMockAlt.d.ts.map +1 -1
  228. package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts +2 -0
  229. package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts.map +1 -0
  230. package/dist/tests/cases/unit/scopeLimitedConnection.test.d.ts +2 -0
  231. package/dist/tests/cases/unit/scopeLimitedConnection.test.d.ts.map +1 -0
  232. package/dist/tests/cases/unit/semaphore.test.d.ts +2 -0
  233. package/dist/tests/cases/unit/semaphore.test.d.ts.map +1 -0
  234. package/dist/tests/src/tags.d.ts.map +1 -1
  235. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  236. package/dist/types/Literal.d.ts.map +1 -1
  237. package/dist/types/builders/CaseStatement.d.ts +2 -2
  238. package/dist/types/builders/CaseStatement.d.ts.map +1 -1
  239. package/dist/types/builders/ColumnExpressionFactory.d.ts +6 -6
  240. package/dist/types/builders/ColumnExpressionFactory.d.ts.map +1 -1
  241. package/dist/types/builders/Compiler.d.ts +5 -5
  242. package/dist/types/builders/Compiler.d.ts.map +1 -1
  243. package/dist/types/builders/ConditionBuilder.d.ts +8 -6
  244. package/dist/types/builders/ConditionBuilder.d.ts.map +1 -1
  245. package/dist/types/builders/DeleteBuilder.d.ts +8 -8
  246. package/dist/types/builders/DeleteBuilder.d.ts.map +1 -1
  247. package/dist/types/builders/InsertBuilder.d.ts +10 -10
  248. package/dist/types/builders/InsertBuilder.d.ts.map +1 -1
  249. package/dist/types/builders/LimitByGroupWrapper.d.ts +3 -3
  250. package/dist/types/builders/LimitByGroupWrapper.d.ts.map +1 -1
  251. package/dist/types/builders/QueryBuilder.d.ts +5 -5
  252. package/dist/types/builders/QueryBuilder.d.ts.map +1 -1
  253. package/dist/types/builders/SelectBuilder.d.ts +9 -9
  254. package/dist/types/builders/SelectBuilder.d.ts.map +1 -1
  255. package/dist/types/builders/UpdateBuilder.d.ts +9 -9
  256. package/dist/types/builders/UpdateBuilder.d.ts.map +1 -1
  257. package/dist/types/builders/WindowFunction.d.ts +4 -3
  258. package/dist/types/builders/WindowFunction.d.ts.map +1 -1
  259. package/dist/types/builders/index.d.ts +12 -12
  260. package/dist/types/builders/index.d.ts.map +1 -1
  261. package/dist/types/builders/internal/Returning.d.ts +3 -3
  262. package/dist/types/builders/internal/Returning.d.ts.map +1 -1
  263. package/dist/types/builders/internal/Subqueries.d.ts +4 -4
  264. package/dist/types/builders/internal/Subqueries.d.ts.map +1 -1
  265. package/dist/types/builders/internal/Where.d.ts +3 -3
  266. package/dist/types/builders/internal/Where.d.ts.map +1 -1
  267. package/dist/types/builders/internal/With.d.ts +3 -3
  268. package/dist/types/builders/internal/With.d.ts.map +1 -1
  269. package/dist/types/builders/utils.d.ts +2 -2
  270. package/dist/types/builders/utils.d.ts.map +1 -1
  271. package/dist/types/client/AcquiredConnection.d.ts +9 -4
  272. package/dist/types/client/AcquiredConnection.d.ts.map +1 -1
  273. package/dist/types/client/Client.d.ts +12 -4
  274. package/dist/types/client/Client.d.ts.map +1 -1
  275. package/dist/types/client/Connection.d.ts +12 -4
  276. package/dist/types/client/Connection.d.ts.map +1 -1
  277. package/dist/types/client/EventManager.d.ts +6 -2
  278. package/dist/types/client/EventManager.d.ts.map +1 -1
  279. package/dist/types/client/PgClient.d.ts +12 -1
  280. package/dist/types/client/PgClient.d.ts.map +1 -1
  281. package/dist/types/client/Pool.d.ts +3 -3
  282. package/dist/types/client/Pool.d.ts.map +1 -1
  283. package/dist/types/client/RequestMemoryBudget.d.ts +41 -0
  284. package/dist/types/client/RequestMemoryBudget.d.ts.map +1 -0
  285. package/dist/types/client/ScopeLimitedConnection.d.ts +34 -0
  286. package/dist/types/client/ScopeLimitedConnection.d.ts.map +1 -0
  287. package/dist/types/client/Transaction.d.ts +5 -5
  288. package/dist/types/client/Transaction.d.ts.map +1 -1
  289. package/dist/types/client/cancelRunningStatement.d.ts +7 -0
  290. package/dist/types/client/cancelRunningStatement.d.ts.map +1 -0
  291. package/dist/types/client/errors.d.ts +3 -0
  292. package/dist/types/client/errors.d.ts.map +1 -1
  293. package/dist/types/client/index.d.ts +8 -7
  294. package/dist/types/client/index.d.ts.map +1 -1
  295. package/dist/types/index.d.ts +11 -10
  296. package/dist/types/index.d.ts.map +1 -1
  297. package/dist/types/metadata/DatabaseMetadata.d.ts +3 -3
  298. package/dist/types/metadata/DatabaseMetadata.d.ts.map +1 -1
  299. package/dist/types/metadata/DatabaseMetadataResolver.d.ts +2 -2
  300. package/dist/types/metadata/DatabaseMetadataResolver.d.ts.map +1 -1
  301. package/dist/types/metadata/ForeignKeyConstraintMetadata.d.ts.map +1 -1
  302. package/dist/types/metadata/IndexMetadata.d.ts.map +1 -1
  303. package/dist/types/metadata/UniqueConstraintMetadata.d.ts.map +1 -1
  304. package/dist/types/metadata/index.d.ts +5 -5
  305. package/dist/types/metadata/index.d.ts.map +1 -1
  306. package/dist/types/metadata/stringArrayEquals.d.ts.map +1 -1
  307. package/dist/types/queryable/DatabaseQuery.d.ts +1 -1
  308. package/dist/types/queryable/DatabaseQuery.d.ts.map +1 -1
  309. package/dist/types/queryable/DatabaseQueryable.d.ts +1 -1
  310. package/dist/types/queryable/DatabaseQueryable.d.ts.map +1 -1
  311. package/dist/types/queryable/index.d.ts +2 -2
  312. package/dist/types/queryable/index.d.ts.map +1 -1
  313. package/dist/types/tsconfig.tsbuildinfo +1 -1
  314. package/dist/types/types.d.ts +16 -0
  315. package/dist/types/types.d.ts.map +1 -1
  316. package/dist/types/utils/ConstraintHelper.d.ts +2 -2
  317. package/dist/types/utils/ConstraintHelper.d.ts.map +1 -1
  318. package/dist/types/utils/Mutex.d.ts.map +1 -1
  319. package/dist/types/utils/Semaphore.d.ts +17 -0
  320. package/dist/types/utils/Semaphore.d.ts.map +1 -0
  321. package/dist/types/utils/createDatabaseIfNotExists.d.ts +1 -1
  322. package/dist/types/utils/createDatabaseIfNotExists.d.ts.map +1 -1
  323. package/dist/types/utils/index.d.ts +11 -10
  324. package/dist/types/utils/index.d.ts.map +1 -1
  325. package/dist/types/utils/listen.d.ts +1 -1
  326. package/dist/types/utils/listen.d.ts.map +1 -1
  327. package/dist/types/utils/pgClientFactory.d.ts +3 -3
  328. package/dist/types/utils/pgClientFactory.d.ts.map +1 -1
  329. package/dist/types/utils/retryTransaction.d.ts.map +1 -1
  330. package/dist/types/utils/sql.d.ts +1 -1
  331. package/dist/types/utils/sql.d.ts.map +1 -1
  332. package/dist/types/utils/withDatabaseAdvisoryLock.d.ts +1 -1
  333. package/dist/types/utils/withDatabaseAdvisoryLock.d.ts.map +1 -1
  334. package/package.json +3 -3
  335. package/src/builders/CaseStatement.ts +3 -3
  336. package/src/builders/ColumnExpressionFactory.ts +7 -7
  337. package/src/builders/Compiler.ts +9 -9
  338. package/src/builders/ConditionBuilder.ts +13 -7
  339. package/src/builders/DeleteBuilder.ts +8 -8
  340. package/src/builders/InsertBuilder.ts +11 -11
  341. package/src/builders/LimitByGroupWrapper.ts +6 -6
  342. package/src/builders/QueryBuilder.ts +5 -5
  343. package/src/builders/SelectBuilder.ts +11 -11
  344. package/src/builders/UpdateBuilder.ts +10 -10
  345. package/src/builders/WindowFunction.ts +7 -6
  346. package/src/builders/index.ts +12 -12
  347. package/src/builders/internal/Returning.ts +4 -4
  348. package/src/builders/internal/Subqueries.ts +4 -4
  349. package/src/builders/internal/Where.ts +4 -4
  350. package/src/builders/internal/With.ts +4 -4
  351. package/src/builders/utils.ts +4 -4
  352. package/src/client/AcquiredConnection.ts +131 -39
  353. package/src/client/Client.ts +16 -6
  354. package/src/client/Connection.ts +27 -7
  355. package/src/client/EventManager.ts +12 -2
  356. package/src/client/PgClient.ts +16 -1
  357. package/src/client/Pool.ts +5 -5
  358. package/src/client/RequestMemoryBudget.ts +260 -0
  359. package/src/client/ScopeLimitedConnection.ts +65 -0
  360. package/src/client/Transaction.ts +24 -11
  361. package/src/client/cancelRunningStatement.ts +36 -0
  362. package/src/client/errors.ts +6 -0
  363. package/src/client/index.ts +8 -7
  364. package/src/index.ts +12 -10
  365. package/src/metadata/DatabaseMetadata.ts +3 -3
  366. package/src/metadata/DatabaseMetadataResolver.ts +5 -5
  367. package/src/metadata/IndexMetadata.ts +1 -1
  368. package/src/metadata/UniqueConstraintMetadata.ts +1 -1
  369. package/src/metadata/index.ts +5 -5
  370. package/src/queryable/DatabaseQuery.ts +2 -2
  371. package/src/queryable/DatabaseQueryable.ts +1 -1
  372. package/src/queryable/index.ts +2 -2
  373. package/src/types.ts +16 -0
  374. package/src/utils/ConstraintHelper.ts +3 -3
  375. package/src/utils/Semaphore.ts +49 -0
  376. package/src/utils/createDatabaseIfNotExists.ts +3 -3
  377. package/src/utils/index.ts +11 -10
  378. package/src/utils/listen.ts +2 -2
  379. package/src/utils/pgClientFactory.ts +18 -10
  380. package/src/utils/retryTransaction.ts +1 -1
  381. package/src/utils/sql.ts +1 -1
  382. package/src/utils/withDatabaseAdvisoryLock.ts +1 -1
  383. package/tests/cases/integration/requestMemoryBudget.test.ts +296 -0
  384. package/tests/cases/unit/acquiredConnection.test.ts +154 -0
  385. package/tests/cases/unit/connection.test.ts +34 -2
  386. package/tests/cases/unit/createConnectionMockAlt.ts +18 -4
  387. package/tests/cases/unit/eventManager.test.ts +2 -2
  388. package/tests/cases/unit/pool.test.ts +1 -1
  389. package/tests/cases/unit/queryBuilder.test.ts +29 -4
  390. package/tests/cases/unit/requestMemoryBudget.test.ts +287 -0
  391. package/tests/cases/unit/scopeLimitedConnection.test.ts +204 -0
  392. package/tests/cases/unit/semaphore.test.ts +53 -0
@@ -1 +1 @@
1
- {"version":3,"file":"pgClientFactory.d.ts","sourceRoot":"","sources":["../../../src/utils/pgClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,MAAM,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAA;AAC5C,eAAO,MAAM,qBAAqB,GAAI,wEAAwE,cAAc,oBAO3H,CAAA"}
1
+ {"version":3,"file":"pgClientFactory.d.ts","sourceRoot":"","sources":["../../../src/utils/pgClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAA;AAC5C,eAAO,MAAM,qBAAqB,0FACuD,cAAc,oBAcrG,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"retryTransaction.d.ts","sourceRoot":"","sources":["../../../src/utils/retryTransaction.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAQD,eAAO,MAAM,gBAAgB,GAAU,CAAC,EACvC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,EACjC,UAAS,OAAO,CAAC,YAAY,CAAM,KACjC,OAAO,CAAC,CAAC,CA4BX,CAAA"}
1
+ {"version":3,"file":"retryTransaction.d.ts","sourceRoot":"","sources":["../../../src/utils/retryTransaction.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAQD,eAAO,MAAM,gBAAgB,GAAU,CAAC,MACnC,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,UAChB,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,YACxB,OAAO,CAAC,YAAY,CAAC,KAC5B,OAAO,CAAC,CAAC,CA4BX,CAAA"}
@@ -1,4 +1,4 @@
1
- import { Literal } from '../Literal';
1
+ import { Literal } from '../Literal.js';
2
2
  export declare const wrapIdentifier: (value: string) => string;
3
3
  export declare const aliasLiteral: (raw: Literal, alias?: string) => Literal;
4
4
  export declare const prependSchema: (tableExpression: string | Literal, schema: string, cteAliases: Set<string>) => Literal;
@@ -1 +1 @@
1
- {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../../src/utils/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,WAA0C,CAAA;AAEtF,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,EAAE,QAAQ,MAAM,KAAG,OAK3D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,iBAAiB,MAAM,GAAG,OAAO,EAAE,QAAQ,MAAM,EAAE,YAAY,GAAG,CAAC,MAAM,CAAC,YASvG,CAAA;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAMpF"}
1
+ {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../../src/utils/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,eAAO,MAAM,cAAc,UAAW,MAAM,WAA0C,CAAA;AAEtF,eAAO,MAAM,YAAY,QAAS,OAAO,UAAU,MAAM,KAAG,OAK3D,CAAA;AAED,eAAO,MAAM,aAAa,oBAAqB,MAAM,GAAG,OAAO,UAAU,MAAM,cAAc,GAAG,CAAC,MAAM,CAAC,YASvG,CAAA;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAMpF"}
@@ -1,3 +1,3 @@
1
- import { Connection } from '../client';
1
+ import { Connection } from '../client/index.js';
2
2
  export declare const withDatabaseAdvisoryLock: <Result>(connection: Connection.ConnectionLike, lock: number, callback: () => Result | Promise<Result>) => Promise<Result>;
3
3
  //# sourceMappingURL=withDatabaseAdvisoryLock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withDatabaseAdvisoryLock.d.ts","sourceRoot":"","sources":["../../../src/utils/withDatabaseAdvisoryLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,eAAO,MAAM,wBAAwB,GAAU,MAAM,EACpD,YAAY,UAAU,CAAC,cAAc,EACrC,MAAM,MAAM,EACZ,UAAU,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KACtC,OAAO,CAAC,MAAM,CAWhB,CAAA"}
1
+ {"version":3,"file":"withDatabaseAdvisoryLock.d.ts","sourceRoot":"","sources":["../../../src/utils/withDatabaseAdvisoryLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,eAAO,MAAM,wBAAwB,GAAU,MAAM,cACxC,UAAU,CAAC,cAAc,QAC/B,MAAM,YACF,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KACtC,OAAO,CAAC,MAAM,CAWhB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/database",
3
- "version": "2.1.0-rc.3",
3
+ "version": "2.2.0-alpha.10",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/production/index.js",
6
6
  "typings": "./dist/types/index.d.ts",
@@ -23,10 +23,10 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@contember/queryable": "2.1.0-rc.3"
26
+ "@contember/queryable": "2.2.0-alpha.10"
27
27
  },
28
28
  "devDependencies": {
29
- "@contember/database-tester": "2.1.0-rc.3",
29
+ "@contember/database-tester": "2.2.0-alpha.10",
30
30
  "@types/node": "^24.12.0",
31
31
  "pg": "^8.20.0"
32
32
  },
@@ -1,6 +1,6 @@
1
- import { QueryBuilder } from './QueryBuilder'
2
- import { Literal } from '../Literal'
3
- import { columnExpressionToLiteral } from './utils'
1
+ import { QueryBuilder } from './QueryBuilder.js'
2
+ import { Literal } from '../Literal.js'
3
+ import { columnExpressionToLiteral } from './utils.js'
4
4
 
5
5
  class CaseStatement {
6
6
  constructor(private readonly options: CaseStatement.Options) {}
@@ -1,10 +1,10 @@
1
- import { QueryBuilder } from './QueryBuilder'
2
- import { Literal } from '../Literal'
3
- import { Value } from '../types'
4
- import { ConditionBuilder, ConditionExpression } from './ConditionBuilder'
5
- import { WindowFunction } from './WindowFunction'
6
- import { CaseStatement } from './CaseStatement'
7
- import { formatColumnIdentifier } from '../utils'
1
+ import { QueryBuilder } from './QueryBuilder.js'
2
+ import { Literal } from '../Literal.js'
3
+ import { Value } from '../types.js'
4
+ import { ConditionBuilder, ConditionExpression } from './ConditionBuilder.js'
5
+ import { WindowFunction } from './WindowFunction.js'
6
+ import { CaseStatement } from './CaseStatement.js'
7
+ import { formatColumnIdentifier } from '../utils/index.js'
8
8
 
9
9
  export class ColumnExpressionFactory {
10
10
  public select(columnName: QueryBuilder.ColumnIdentifier): Literal {
@@ -1,12 +1,12 @@
1
- import { aliasLiteral, assertNever, prependSchema, wrapIdentifier } from '../utils'
2
- import { SelectBuilder } from './SelectBuilder'
3
- import { Literal } from '../Literal'
4
- import { DeleteBuilder } from './DeleteBuilder'
5
- import { InsertBuilder } from './InsertBuilder'
6
- import { UpdateBuilder } from './UpdateBuilder'
7
- import { QueryBuilder } from './QueryBuilder'
8
- import { LockType } from './LockType'
9
- import { ConflictActionType } from './ConflictActionType'
1
+ import { aliasLiteral, assertNever, prependSchema, wrapIdentifier } from '../utils/index.js'
2
+ import { SelectBuilder } from './SelectBuilder.js'
3
+ import { Literal } from '../Literal.js'
4
+ import { DeleteBuilder } from './DeleteBuilder.js'
5
+ import { InsertBuilder } from './InsertBuilder.js'
6
+ import { UpdateBuilder } from './UpdateBuilder.js'
7
+ import { QueryBuilder } from './QueryBuilder.js'
8
+ import { LockType } from './LockType.js'
9
+ import { ConflictActionType } from './ConflictActionType.js'
10
10
 
11
11
  class Compiler {
12
12
  compileSelect(options: SelectBuilder.Options, namespaceContext: Compiler.Context): Literal {
@@ -1,10 +1,10 @@
1
- import { Value } from '../types'
2
- import { Literal } from '../Literal'
3
- import { QueryBuilder } from './QueryBuilder'
4
- import { SelectBuilder } from './SelectBuilder'
5
- import { Compiler } from './Compiler'
6
- import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
7
- import { formatColumnIdentifier } from '../utils'
1
+ import { Value } from '../types.js'
2
+ import { Literal } from '../Literal.js'
3
+ import { QueryBuilder } from './QueryBuilder.js'
4
+ import { SelectBuilder } from './SelectBuilder.js'
5
+ import { Compiler } from './Compiler.js'
6
+ import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
7
+ import { formatColumnIdentifier } from '../utils/index.js'
8
8
 
9
9
  export type ConditionCallback = (builder: ConditionBuilder) => ConditionBuilder
10
10
  export type ConditionExpression = ConditionBuilder | ConditionCallback
@@ -22,6 +22,8 @@ export enum Operator {
22
22
  'containsCI' = 'containsCI',
23
23
  'startsWithCI' = 'startsWithCI',
24
24
  'endsWithCI' = 'endsWithCI',
25
+ 'similar' = 'similar',
26
+ 'wordSimilar' = 'wordSimilar',
25
27
  }
26
28
 
27
29
  const likeOperators: string[] = [
@@ -170,6 +172,10 @@ export class ConditionBuilder {
170
172
  return `${left} LIKE '%' || ${right}`
171
173
  case Operator.endsWithCI:
172
174
  return `${left} ILIKE '%' || ${right}`
175
+ case Operator.similar:
176
+ return `${left} % ${right}`
177
+ case Operator.wordSimilar:
178
+ return `${right} <% ${left}`
173
179
  }
174
180
  return `${left} ${operator} ${right}`
175
181
  }
@@ -1,11 +1,11 @@
1
- import { Returning } from './internal/Returning'
2
- import { With } from './internal/With'
3
- import { Where } from './internal/Where'
4
- import { Compiler } from './Compiler'
5
- import { QueryBuilder } from './QueryBuilder'
6
- import { Client, Connection } from '../client'
7
- import { Literal } from '../Literal'
8
- import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
1
+ import { Returning } from './internal/Returning.js'
2
+ import { With } from './internal/With.js'
3
+ import { Where } from './internal/Where.js'
4
+ import { Compiler } from './Compiler.js'
5
+ import { QueryBuilder } from './QueryBuilder.js'
6
+ import { Client, Connection } from '../client/index.js'
7
+ import { Literal } from '../Literal.js'
8
+ import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
9
9
 
10
10
  class DeleteBuilder<Result extends DeleteBuilder.DeleteResult> implements Returning.Aware, With.Aware, Where.Aware, QueryBuilder {
11
11
  private constructor(private readonly options: DeleteBuilder.Options) {}
@@ -1,14 +1,14 @@
1
- import { Returning } from './internal/Returning'
2
- import { With } from './internal/With'
3
- import { Compiler } from './Compiler'
4
- import { QueryBuilder } from './QueryBuilder'
5
- import { Client, Connection } from '../client'
6
- import { Literal } from '../Literal'
7
- import { SelectBuilder } from './SelectBuilder'
8
- import { resolveValues } from './utils'
9
- import { ConflictActionType } from './ConflictActionType'
10
- import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
11
- import { Where } from './internal/Where'
1
+ import { Returning } from './internal/Returning.js'
2
+ import { With } from './internal/With.js'
3
+ import { Compiler } from './Compiler.js'
4
+ import { QueryBuilder } from './QueryBuilder.js'
5
+ import { Client, Connection } from '../client/index.js'
6
+ import { Literal } from '../Literal.js'
7
+ import { SelectBuilder } from './SelectBuilder.js'
8
+ import { resolveValues } from './utils.js'
9
+ import { ConflictActionType } from './ConflictActionType.js'
10
+ import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
11
+ import { Where } from './internal/Where.js'
12
12
 
13
13
  class InsertBuilder<Result extends InsertBuilder.InsertResult> implements With.Aware, QueryBuilder {
14
14
  private constructor(private readonly options: InsertBuilder.Options) {}
@@ -1,8 +1,8 @@
1
- import { QueryBuilder } from './QueryBuilder'
2
- import { SelectBuilder } from './SelectBuilder'
3
- import { Operator } from './ConditionBuilder'
4
- import { Client } from '../client'
5
- import { WindowFunction } from './WindowFunction'
1
+ import { QueryBuilder } from './QueryBuilder.js'
2
+ import { SelectBuilder } from './SelectBuilder.js'
3
+ import { Operator } from './ConditionBuilder.js'
4
+ import { Client } from '../client/index.js'
5
+ import { WindowFunction } from './WindowFunction.js'
6
6
 
7
7
  type OrderByCallback = <Orderable extends QueryBuilder.Orderable<any> | null>(
8
8
  orderable: Orderable,
@@ -42,7 +42,7 @@ class LimitByGroupWrapper {
42
42
  wrapperQb = wrapperQb.where(expr => expr.compare(['data', 'rowNumber_'], Operator.lte, start + limit))
43
43
  }
44
44
 
45
- return await wrapperQb.getResult(db)
45
+ return await wrapperQb.orderBy(['data', 'rowNumber_']).getResult(db)
46
46
  } else if (this.orderByCallback) {
47
47
  return await this.orderByCallback(null, qb)[1].getResult(db)
48
48
  }
@@ -1,8 +1,8 @@
1
- import { Literal } from '../Literal'
2
- import { Value } from '../types'
3
- import { ColumnExpressionFactory } from './ColumnExpressionFactory'
4
- import { Compiler } from './Compiler'
5
- import { SelectBuilder } from './SelectBuilder'
1
+ import { Literal } from '../Literal.js'
2
+ import { Value } from '../types.js'
3
+ import { ColumnExpressionFactory } from './ColumnExpressionFactory.js'
4
+ import { Compiler } from './Compiler.js'
5
+ import { SelectBuilder } from './SelectBuilder.js'
6
6
 
7
7
  interface QueryBuilder {
8
8
  createQuery(context: Compiler.Context): Literal
@@ -1,14 +1,14 @@
1
- import { With } from './internal/With'
2
- import { Where } from './internal/Where'
3
- import { aliasLiteral, formatColumnIdentifier } from '../utils'
4
- import { Compiler } from './Compiler'
5
- import { QueryBuilder } from './QueryBuilder'
6
- import { Client, Connection } from '../client'
7
- import { Literal } from '../Literal'
8
- import { ConditionBuilder, ConditionExpression } from './ConditionBuilder'
9
- import { LockModifier, LockType } from './LockType'
10
- import { columnExpressionToLiteral } from './utils'
11
- import { createSubQueryLiteralFactory, SubQueryExpression, SubQueryLiteralFactory } from './internal/Subqueries'
1
+ import { With } from './internal/With.js'
2
+ import { Where } from './internal/Where.js'
3
+ import { aliasLiteral, formatColumnIdentifier } from '../utils/index.js'
4
+ import { Compiler } from './Compiler.js'
5
+ import { QueryBuilder } from './QueryBuilder.js'
6
+ import { Client, Connection } from '../client/index.js'
7
+ import { Literal } from '../Literal.js'
8
+ import { ConditionBuilder, ConditionExpression } from './ConditionBuilder.js'
9
+ import { LockModifier, LockType } from './LockType.js'
10
+ import { columnExpressionToLiteral } from './utils.js'
11
+ import { createSubQueryLiteralFactory, SubQueryExpression, SubQueryLiteralFactory } from './internal/Subqueries.js'
12
12
 
13
13
  export type SelectBuilderSpecification = <Result>(qb: SelectBuilder<Result>) => SelectBuilder<Result>
14
14
 
@@ -1,13 +1,13 @@
1
- import { Returning } from './internal/Returning'
2
- import { With } from './internal/With'
3
- import { Where } from './internal/Where'
4
- import { Compiler } from './Compiler'
5
- import { QueryBuilder } from './QueryBuilder'
6
- import { Client, Connection } from '../client'
7
- import { Literal } from '../Literal'
8
- import { SelectBuilder } from './SelectBuilder'
9
- import { resolveValues } from './utils'
10
- import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
1
+ import { Returning } from './internal/Returning.js'
2
+ import { With } from './internal/With.js'
3
+ import { Where } from './internal/Where.js'
4
+ import { Compiler } from './Compiler.js'
5
+ import { QueryBuilder } from './QueryBuilder.js'
6
+ import { Client, Connection } from '../client/index.js'
7
+ import { Literal } from '../Literal.js'
8
+ import { SelectBuilder } from './SelectBuilder.js'
9
+ import { resolveValues } from './utils.js'
10
+ import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
11
11
 
12
12
  class UpdateBuilder<Result extends UpdateBuilder.UpdateResult> implements With.Aware, Where.Aware, QueryBuilder {
13
13
  private constructor(private readonly options: UpdateBuilder.Options) {}
@@ -1,7 +1,8 @@
1
- import { QueryBuilder } from './QueryBuilder'
2
- import { Literal } from '../Literal'
3
- import { columnExpressionToLiteral } from './utils'
4
- import { formatColumnIdentifier } from '../utils'
1
+ import { QueryBuilder } from './QueryBuilder.js'
2
+ import { Literal } from '../Literal.js'
3
+ import { columnExpressionToLiteral } from './utils.js'
4
+ import { formatColumnIdentifier } from '../utils/index.js'
5
+ import type { SelectBuilder } from './SelectBuilder.js'
5
6
 
6
7
  class WindowFunction<HasFunction extends boolean> implements QueryBuilder.Orderable<WindowFunction<HasFunction>> {
7
8
  private constructor(
@@ -30,12 +31,12 @@ class WindowFunction<HasFunction extends boolean> implements QueryBuilder.Ordera
30
31
 
31
32
  orderBy(
32
33
  expression: QueryBuilder.ColumnIdentifier | Literal,
33
- direction: 'asc' | 'desc' = 'asc',
34
+ direction: SelectBuilder.OrderByDirection = 'asc',
34
35
  ): WindowFunction<HasFunction> {
35
36
  const raw = expression instanceof Literal ? expression : new Literal(formatColumnIdentifier(expression))
36
37
  return new WindowFunction(this.windowFunction, this.partitionByExpr, [
37
38
  ...this.orderByColumns,
38
- raw.appendString(direction === 'asc' ? ' asc' : ' desc'),
39
+ raw.appendString(` ${direction}`),
39
40
  ])
40
41
  }
41
42
 
@@ -1,12 +1,12 @@
1
- export * from './Compiler'
2
- export * from './CaseStatement'
3
- export * from './ConditionBuilder'
4
- export * from './DeleteBuilder'
5
- export * from './InsertBuilder'
6
- export * from './LimitByGroupWrapper'
7
- export * from './QueryBuilder'
8
- export * from './SelectBuilder'
9
- export * from './UpdateBuilder'
10
- export * from './WindowFunction'
11
- export * from './LockType'
12
- export * from './ConflictActionType'
1
+ export * from './Compiler.js'
2
+ export * from './CaseStatement.js'
3
+ export * from './ConditionBuilder.js'
4
+ export * from './DeleteBuilder.js'
5
+ export * from './InsertBuilder.js'
6
+ export * from './LimitByGroupWrapper.js'
7
+ export * from './QueryBuilder.js'
8
+ export * from './SelectBuilder.js'
9
+ export * from './UpdateBuilder.js'
10
+ export * from './WindowFunction.js'
11
+ export * from './LockType.js'
12
+ export * from './ConflictActionType.js'
@@ -1,7 +1,7 @@
1
- import { QueryBuilder } from '../'
2
- import { Literal } from '../../Literal'
3
- import { Connection } from '../../client'
4
- import { formatColumnIdentifier } from '../../utils'
1
+ import { QueryBuilder } from '../index.js'
2
+ import { Literal } from '../../Literal.js'
3
+ import { Connection } from '../../client/index.js'
4
+ import { formatColumnIdentifier } from '../../utils/index.js'
5
5
 
6
6
  class Returning {
7
7
  constructor(private readonly columns: (QueryBuilder.ColumnIdentifier | Literal)[] = []) {}
@@ -1,7 +1,7 @@
1
- import { Compiler } from '../Compiler'
2
- import { Literal } from '../../Literal'
3
- import { SelectBuilder } from '../SelectBuilder'
4
- import { QueryBuilder } from '../QueryBuilder'
1
+ import { Compiler } from '../Compiler.js'
2
+ import { Literal } from '../../Literal.js'
3
+ import { SelectBuilder } from '../SelectBuilder.js'
4
+ import { QueryBuilder } from '../QueryBuilder.js'
5
5
 
6
6
  export type SubQueryLiteralFactory<Builder extends QueryBuilder = QueryBuilder> = (
7
7
  context: Compiler.Context,
@@ -1,7 +1,7 @@
1
- import { wrapIdentifier } from '../../utils'
2
- import { Literal } from '../../Literal'
3
- import { ConditionBuilder, ConditionCallback } from '../ConditionBuilder'
4
- import { Value } from '../../types'
1
+ import { wrapIdentifier } from '../../utils/index.js'
2
+ import { Literal } from '../../Literal.js'
3
+ import { ConditionBuilder, ConditionCallback } from '../ConditionBuilder.js'
4
+ import { Value } from '../../types.js'
5
5
 
6
6
  namespace Where {
7
7
  export interface Options {
@@ -1,7 +1,7 @@
1
- import { wrapIdentifier } from '../../utils'
2
- import { Literal } from '../../Literal'
3
- import { Compiler } from '../Compiler'
4
- import { SubQueryExpression, SubQueryLiteralFactory } from './Subqueries'
1
+ import { wrapIdentifier } from '../../utils/index.js'
2
+ import { Literal } from '../../Literal.js'
3
+ import { Compiler } from '../Compiler.js'
4
+ import { SubQueryExpression, SubQueryLiteralFactory } from './Subqueries.js'
5
5
 
6
6
  namespace With {
7
7
  type CteOptions = {
@@ -1,7 +1,7 @@
1
- import { Literal } from '../Literal'
2
- import { QueryBuilder } from './QueryBuilder'
3
- import { ColumnExpressionFactory } from './ColumnExpressionFactory'
4
- import { formatColumnIdentifier } from '../utils'
1
+ import { Literal } from '../Literal.js'
2
+ import { QueryBuilder } from './QueryBuilder.js'
3
+ import { ColumnExpressionFactory } from './ColumnExpressionFactory.js'
4
+ import { formatColumnIdentifier } from '../utils/index.js'
5
5
 
6
6
  export function resolveValues(values: QueryBuilder.Values): QueryBuilder.ResolvedValues {
7
7
  return Object.entries(values)
@@ -1,19 +1,22 @@
1
- import { Connection } from './Connection'
2
- import { EventManager } from './EventManager'
3
- import { Mutex } from '../utils'
4
- import { executeTransaction, Transaction } from './Transaction'
5
- import { ClientErrorCodes } from './errorCodes'
1
+ import { Connection } from './Connection.js'
2
+ import { EventManager } from './EventManager.js'
3
+ import { Mutex, MutexDeadlockError } from '../utils/index.js'
4
+ import { executeTransaction, Transaction } from './Transaction.js'
5
+ import { ClientErrorCodes } from './errorCodes.js'
6
6
  import {
7
7
  ForeignKeyViolationError,
8
8
  InvalidDataError,
9
9
  NotNullViolationError,
10
10
  QueryError,
11
11
  SerializationFailureError,
12
+ TerminatedConnectionError,
12
13
  TransactionAbortedError,
13
14
  UniqueViolationError,
14
- } from './errors'
15
- import { PgClient } from './PgClient'
16
- import { Notification } from 'pg'
15
+ } from './errors.js'
16
+ import { PgClient } from './PgClient.js'
17
+ import { cancelRunningStatement } from './cancelRunningStatement.js'
18
+ import { Notification, Query, QueryResult, QueryResultRow } from 'pg'
19
+ import { RequestMemoryBudget, RequestMemoryBudgetExceededError } from './RequestMemoryBudget.js'
17
20
 
18
21
  export class AcquiredConnection implements Connection.AcquiredConnectionLike {
19
22
  private mutex = new Mutex()
@@ -21,6 +24,7 @@ export class AcquiredConnection implements Connection.AcquiredConnectionLike {
21
24
  constructor(
22
25
  private readonly pgClient: PgClient,
23
26
  public readonly eventManager: EventManager,
27
+ private readonly physicalConnection = { terminated: false },
24
28
  ) {
25
29
  }
26
30
 
@@ -29,7 +33,7 @@ export class AcquiredConnection implements Connection.AcquiredConnectionLike {
29
33
  options: { eventManager?: EventManager } = {},
30
34
  ): Promise<Result> {
31
35
  return await this.mutex.execute(async () => {
32
- return await callback(new AcquiredConnection(this.pgClient, options.eventManager ?? this.eventManager))
36
+ return await callback(new AcquiredConnection(this.pgClient, options.eventManager ?? this.eventManager, this.physicalConnection))
33
37
  })
34
38
  }
35
39
 
@@ -49,51 +53,139 @@ export class AcquiredConnection implements Connection.AcquiredConnectionLike {
49
53
  parameters: any[] = [],
50
54
  meta: Record<string, any> = {},
51
55
  ): Promise<Connection.Result<Row>> {
52
- return await this.mutex.execute(async () => {
53
- try {
54
- this.eventManager.fire(EventManager.Event.queryStart, { sql, parameters, meta })
56
+ // A refusal before queryStart fires no event, so cleanup on a terminated connection stays out of query error metrics.
57
+ this.refuseExhaustedOrTerminated()
58
+
59
+ const query: Connection.Query = { sql, parameters, meta }
55
60
 
56
- let result: Connection.Result<Row>
61
+ try {
62
+ this.eventManager.fire(EventManager.Event.queryStart, query)
63
+
64
+ const result = await this.mutex.execute(async (): Promise<Connection.Result<Row>> => {
65
+ // A query queued behind the one that exhausted the budget reports the budget, not the terminated connection.
66
+ this.refuseExhaustedOrTerminated()
67
+ const memoryBudget = this.eventManager.memoryBudget
57
68
  const startHrTime = process.hrtime.bigint()
58
69
 
59
- result = await this.pgClient.query(prepareSql(sql), parameters)
70
+ const pgResult = memoryBudget && this.eventManager.chargesMemoryBudget
71
+ ? await this.queryWithMemoryBudget<Row>(prepareSql(sql), parameters, memoryBudget)
72
+ : await this.pgClient.query(prepareSql(sql), parameters)
60
73
 
61
74
  const endHrTime = process.hrtime.bigint()
62
75
  const durationUs = Math.floor(Number(endHrTime - startHrTime) / 1000)
63
- result = {
64
- ...result,
76
+
77
+ return {
78
+ ...pgResult,
65
79
  timing: {
66
80
  selfDuration: durationUs,
67
81
  totalDuration: durationUs,
68
82
  },
69
83
  }
84
+ })
70
85
 
71
- this.eventManager.fire(EventManager.Event.queryEnd, { sql, parameters, meta }, result)
86
+ this.eventManager.fire(EventManager.Event.queryEnd, query, result)
72
87
 
73
- return result
74
- } catch (error) {
75
- if (!(error instanceof Error)) {
76
- throw error
88
+ return result
89
+ } catch (error) {
90
+ if (!(error instanceof Error)) {
91
+ throw error
92
+ }
93
+ this.eventManager.fire(EventManager.Event.queryError, query, error)
94
+
95
+ // neither a mutex deadlock nor a budget refusal is a postgres failure, keep them untranslated
96
+ if (error instanceof MutexDeadlockError || error instanceof RequestMemoryBudgetExceededError || error instanceof TerminatedConnectionError) {
97
+ throw error
98
+ }
99
+
100
+ switch ((error as any).code) {
101
+ case ClientErrorCodes.NOT_NULL_VIOLATION:
102
+ throw new NotNullViolationError(sql, parameters, error)
103
+ case ClientErrorCodes.FOREIGN_KEY_VIOLATION:
104
+ throw new ForeignKeyViolationError(sql, parameters, error)
105
+ case ClientErrorCodes.UNIQUE_VIOLATION:
106
+ throw new UniqueViolationError(sql, parameters, error)
107
+ case ClientErrorCodes.T_R_SERIALIZATION_FAILURE:
108
+ throw new SerializationFailureError(sql, parameters, error)
109
+ case ClientErrorCodes.INVALID_TEXT_REPRESENTATION:
110
+ case ClientErrorCodes.DATETIME_FIELD_OVERFLOW:
111
+ throw new InvalidDataError(sql, parameters, error)
112
+ case ClientErrorCodes.IN_FAILED_SQL_TRANSACTION:
113
+ throw new TransactionAbortedError(sql, parameters, error)
114
+ default:
115
+ throw new QueryError(sql, parameters, error)
116
+ }
117
+ }
118
+ }
119
+
120
+ private refuseExhaustedOrTerminated(): void {
121
+ // The budget goes first: a connection the budget terminated reports the budget to every query still bound to it.
122
+ this.eventManager.memoryBudget?.check()
123
+ if (this.physicalConnection.terminated) {
124
+ throw new TerminatedConnectionError()
125
+ }
126
+ }
127
+
128
+ private async queryWithMemoryBudget<Row extends QueryResultRow>(
129
+ sql: string,
130
+ parameters: unknown[],
131
+ budget: RequestMemoryBudget,
132
+ ): Promise<Connection.Result<Row>> {
133
+ return await new Promise<Connection.Result<Row>>((resolve, reject) => {
134
+ let rows: Row[] | undefined
135
+ let failure: Error | undefined
136
+ let cleanup = () => {}
137
+ const stop = (error: Error) => {
138
+ failure = error
139
+ if (rows) {
140
+ rows.length = 0
77
141
  }
78
- this.eventManager.fire(EventManager.Event.queryError, { sql, parameters, meta }, error)
79
-
80
- switch ((error as any).code) {
81
- case ClientErrorCodes.NOT_NULL_VIOLATION:
82
- throw new NotNullViolationError(sql, parameters, error)
83
- case ClientErrorCodes.FOREIGN_KEY_VIOLATION:
84
- throw new ForeignKeyViolationError(sql, parameters, error)
85
- case ClientErrorCodes.UNIQUE_VIOLATION:
86
- throw new UniqueViolationError(sql, parameters, error)
87
- case ClientErrorCodes.T_R_SERIALIZATION_FAILURE:
88
- throw new SerializationFailureError(sql, parameters, error)
89
- case ClientErrorCodes.INVALID_TEXT_REPRESENTATION:
90
- case ClientErrorCodes.DATETIME_FIELD_OVERFLOW:
91
- throw new InvalidDataError(sql, parameters, error)
92
- case ClientErrorCodes.IN_FAILED_SQL_TRANSACTION:
93
- throw new TransactionAbortedError(sql, parameters, error)
94
- default:
95
- throw new QueryError(sql, parameters, error)
142
+ cleanup()
143
+ // A budget failure invalidates this connection; the enclosing pool scope disposes it.
144
+ this.physicalConnection.terminated = true
145
+ // Ending the socket alone leaves a statement still waiting for its first row running on the server.
146
+ // Cancelling is best effort and must not mask the budget error.
147
+ void cancelRunningStatement(this.pgClient).catch(() => {})
148
+ void this.pgClient.end().catch(reject)
149
+ reject(error)
150
+ }
151
+ const config = {
152
+ text: sql,
153
+ values: parameters,
154
+ callback: (error: Error | null, result?: QueryResult<Row>) => {
155
+ cleanup()
156
+ if (failure || error) {
157
+ reject(failure || error)
158
+ } else if (result) {
159
+ resolve(result)
160
+ } else {
161
+ reject(new Error('PostgreSQL query completed without a result'))
162
+ }
163
+ },
164
+ }
165
+ const query = new Query<Row>(config)
166
+ // A sibling query of the request may exhaust the budget while this one still waits for its first row.
167
+ cleanup = budget.onExceeded(stop)
168
+ query.on('row', (row, result) => {
169
+ rows = result?.rows
170
+ if (failure) {
171
+ if (rows) {
172
+ rows.length = 0
173
+ }
174
+ return
175
+ }
176
+ try {
177
+ budget.addDatabaseRow(row)
178
+ } catch (error) {
179
+ if (!failure) {
180
+ stop(error instanceof Error ? error : new Error('Failed to account for database row', { cause: error }))
181
+ }
96
182
  }
183
+ })
184
+ try {
185
+ this.pgClient.query(query)
186
+ } catch (error) {
187
+ cleanup()
188
+ reject(error)
97
189
  }
98
190
  })
99
191
  }