orcaq 1.0.21 → 1.0.26

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 (248) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/AKIL8y6B.js +1 -0
  3. package/.output/public/_nuxt/B5vWsFeq.js +160 -0
  4. package/.output/public/_nuxt/B7OaQ1wH.js +8 -0
  5. package/.output/public/_nuxt/BG-9_o0s.js +3 -0
  6. package/.output/public/_nuxt/BHnp06h8.js +1 -0
  7. package/.output/public/_nuxt/BKxFOGv6.js +1 -0
  8. package/.output/public/_nuxt/{8qASMGdV.js → BNIRlgC1.js} +1 -1
  9. package/.output/public/_nuxt/BNdHe5KI.js +1 -0
  10. package/.output/public/_nuxt/BQANhp-y.js +1 -0
  11. package/.output/public/_nuxt/BUYy1lWT.js +215 -0
  12. package/.output/public/_nuxt/Bdtn2mn5.js +1 -0
  13. package/.output/public/_nuxt/Ber6tLDb.js +1 -0
  14. package/.output/public/_nuxt/BgEovngA.js +1 -0
  15. package/.output/public/_nuxt/BhgYrVrc.js +6 -0
  16. package/.output/public/_nuxt/{CrgoNCm2.js → BmnOz39b.js} +2 -2
  17. package/.output/public/_nuxt/BuKJVBv4.js +1 -0
  18. package/.output/public/_nuxt/BxMjn94S.js +4 -0
  19. package/.output/public/_nuxt/C1dxTB9p.js +39 -0
  20. package/.output/public/_nuxt/C4mc67xO.js +31 -0
  21. package/.output/public/_nuxt/CAOPafml.js +1 -0
  22. package/.output/public/_nuxt/CPxn9ATh.js +1 -0
  23. package/.output/public/_nuxt/CQ_P7x7z.js +3 -0
  24. package/.output/public/_nuxt/CS9PCQVw.js +6 -0
  25. package/.output/public/_nuxt/{CbcyysXi.js → CdEjcJco.js} +1 -1
  26. package/.output/public/_nuxt/CeQk_zaG.js +3867 -0
  27. package/.output/public/_nuxt/CgN2MmkB.js +47 -0
  28. package/.output/public/_nuxt/CijEBUIh.js +9 -0
  29. package/.output/public/_nuxt/Cn-07UHL.js +1 -0
  30. package/.output/public/_nuxt/Co87DPdr.js +18 -0
  31. package/.output/public/_nuxt/D0LmHvgn.js +13 -0
  32. package/.output/public/_nuxt/D4_A4fm4.js +1 -0
  33. package/.output/public/_nuxt/D8pqASdN.js +1 -0
  34. package/.output/public/_nuxt/DAs4584G.js +72 -0
  35. package/.output/public/_nuxt/DBO1CAN4.js +1 -0
  36. package/.output/public/_nuxt/DF7Phtj8.js +39 -0
  37. package/.output/public/_nuxt/DMMO4O3Y.js +1 -0
  38. package/.output/public/_nuxt/DP-hoxaC.js +1 -0
  39. package/.output/public/_nuxt/DREcM-oC.js +20 -0
  40. package/.output/public/_nuxt/DX-rdvVh.js +28 -0
  41. package/.output/public/_nuxt/DXei3mDv.js +1 -0
  42. package/.output/public/_nuxt/DZcRPyDc.js +26 -0
  43. package/.output/public/_nuxt/D_QjJZ_n.js +1 -0
  44. package/.output/public/_nuxt/DhSSuHOz.js +32 -0
  45. package/.output/public/_nuxt/Dj2IVxO7.js +1 -0
  46. package/.output/public/_nuxt/DmMeuvwr.js +1 -0
  47. package/.output/public/_nuxt/DqlhGxxN.js +32 -0
  48. package/.output/public/_nuxt/GmXmO94-.js +1 -0
  49. package/.output/public/_nuxt/HPyUOgdi.js +1 -0
  50. package/.output/public/_nuxt/MdxV8r4v.js +1 -0
  51. package/.output/public/_nuxt/Mp6jDt1I.js +1 -0
  52. package/.output/public/_nuxt/QuickQuery.h4epNPla.css +1 -0
  53. package/.output/public/_nuxt/{CustomEdge.BNBpjEHb.css → WrapperErdDiagram.DeMTjOwN.css} +1 -1
  54. package/.output/public/_nuxt/Zvfofmwe.js +1 -0
  55. package/.output/public/_nuxt/{_fileId_.DmPfwyyD.css → _fileId_.BHiWIaF7.css} +1 -1
  56. package/.output/public/_nuxt/builds/latest.json +1 -1
  57. package/.output/public/_nuxt/builds/meta/db42d692-1628-4dd8-9442-d7621bdd9ac6.json +1 -0
  58. package/.output/public/_nuxt/cQYBDqKG.js +1 -0
  59. package/.output/public/_nuxt/default.BfdyU-m9.css +1 -0
  60. package/.output/public/_nuxt/entry.0UG0MnUy.css +1 -0
  61. package/.output/public/_nuxt/fIC3FurW.js +1 -0
  62. package/.output/public/_nuxt/{index.CrXmf4gr.css → index.BHg08rtV.css} +1 -1
  63. package/.output/public/_nuxt/kehy-5uo.js +1 -0
  64. package/.output/public/_nuxt/n9bD6NrC.js +2 -0
  65. package/.output/public/_nuxt/ykQL1ia3.js +271 -0
  66. package/.output/public/_nuxt/zD3bTrJp.js +1 -0
  67. package/.output/server/chunks/build/client.manifest.mjs +509 -358
  68. package/.output/server/chunks/build/client.manifest.mjs.map +1 -1
  69. package/.output/server/chunks/nitro/nitro.mjs +504 -274
  70. package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
  71. package/.output/server/chunks/routes/api/database-export/export-database.mjs +139 -0
  72. package/.output/server/chunks/routes/api/database-export/export-database.mjs.map +1 -0
  73. package/.output/server/chunks/routes/api/database-import/import-database.mjs +178 -0
  74. package/.output/server/chunks/routes/api/database-import/import-database.mjs.map +1 -0
  75. package/.output/server/chunks/routes/api/database-roles/adapters/postgres.adapter.mjs +700 -0
  76. package/.output/server/chunks/routes/api/database-roles/adapters/postgres.adapter.mjs.map +1 -0
  77. package/.output/server/chunks/routes/api/database-roles/adapters/types.mjs +2 -0
  78. package/.output/server/chunks/routes/api/database-roles/adapters/types.mjs.map +1 -0
  79. package/.output/server/chunks/routes/api/database-roles/create-role.mjs +46 -0
  80. package/.output/server/chunks/routes/api/database-roles/create-role.mjs.map +1 -0
  81. package/.output/server/chunks/routes/api/database-roles/delete-role.mjs +34 -0
  82. package/.output/server/chunks/routes/api/database-roles/delete-role.mjs.map +1 -0
  83. package/.output/server/chunks/routes/api/database-roles/get-databases-with-permissions.mjs +34 -0
  84. package/.output/server/chunks/routes/api/database-roles/get-databases-with-permissions.mjs.map +1 -0
  85. package/.output/server/chunks/routes/api/database-roles/get-databases.mjs +32 -0
  86. package/.output/server/chunks/routes/api/database-roles/get-databases.mjs.map +1 -0
  87. package/.output/server/chunks/routes/api/database-roles/get-permissions.mjs +32 -0
  88. package/.output/server/chunks/routes/api/database-roles/get-permissions.mjs.map +1 -0
  89. package/.output/server/chunks/routes/api/database-roles/get-role-inheritance.mjs +40 -0
  90. package/.output/server/chunks/routes/api/database-roles/get-role-inheritance.mjs.map +1 -0
  91. package/.output/server/chunks/routes/api/database-roles/get-role.mjs +26 -0
  92. package/.output/server/chunks/routes/api/database-roles/get-role.mjs.map +1 -0
  93. package/.output/server/chunks/routes/api/database-roles/get-roles.mjs +26 -0
  94. package/.output/server/chunks/routes/api/database-roles/get-roles.mjs.map +1 -0
  95. package/.output/server/chunks/routes/api/database-roles/get-schema-objects.mjs +38 -0
  96. package/.output/server/chunks/routes/api/database-roles/get-schema-objects.mjs.map +1 -0
  97. package/.output/server/chunks/routes/api/database-roles/get-schemas.mjs +32 -0
  98. package/.output/server/chunks/routes/api/database-roles/get-schemas.mjs.map +1 -0
  99. package/.output/server/chunks/routes/api/database-roles/grant-bulk-permissions.mjs +43 -0
  100. package/.output/server/chunks/routes/api/database-roles/grant-bulk-permissions.mjs.map +1 -0
  101. package/.output/server/chunks/routes/api/database-roles/grant-permission.mjs +41 -0
  102. package/.output/server/chunks/routes/api/database-roles/grant-permission.mjs.map +1 -0
  103. package/.output/server/chunks/routes/api/database-roles/index.mjs +39 -0
  104. package/.output/server/chunks/routes/api/database-roles/index.mjs.map +1 -0
  105. package/.output/server/chunks/routes/api/database-roles/revoke-permission.mjs +41 -0
  106. package/.output/server/chunks/routes/api/database-roles/revoke-permission.mjs.map +1 -0
  107. package/.output/server/chunks/routes/api/delete-function.mjs +65 -0
  108. package/.output/server/chunks/routes/api/delete-function.mjs.map +1 -0
  109. package/.output/server/chunks/routes/api/execute-bulk-delete.mjs +1 -1
  110. package/.output/server/chunks/routes/api/execute-bulk-delete.mjs.map +1 -1
  111. package/.output/server/chunks/routes/api/execute-bulk-update.mjs +1 -1
  112. package/.output/server/chunks/routes/api/execute-bulk-update.mjs.map +1 -1
  113. package/.output/server/chunks/routes/api/export-table-data.mjs +229 -0
  114. package/.output/server/chunks/routes/api/export-table-data.mjs.map +1 -0
  115. package/.output/server/chunks/routes/api/get-function-signature.mjs +96 -0
  116. package/.output/server/chunks/routes/api/get-function-signature.mjs.map +1 -0
  117. package/.output/server/chunks/routes/api/get-one-function.mjs +8 -2
  118. package/.output/server/chunks/routes/api/get-one-function.mjs.map +1 -1
  119. package/.output/server/chunks/routes/api/get-over-view-views.mjs +44 -0
  120. package/.output/server/chunks/routes/api/get-over-view-views.mjs.map +1 -0
  121. package/.output/server/chunks/routes/api/get-reverse-table-schemas.mjs +21 -10
  122. package/.output/server/chunks/routes/api/get-reverse-table-schemas.mjs.map +1 -1
  123. package/.output/server/chunks/routes/api/get-schema-meta-data.mjs +73 -5
  124. package/.output/server/chunks/routes/api/get-schema-meta-data.mjs.map +1 -1
  125. package/.output/server/chunks/routes/api/get-table-ddl.mjs +185 -0
  126. package/.output/server/chunks/routes/api/get-table-ddl.mjs.map +1 -0
  127. package/.output/server/chunks/routes/api/get-view-definition.mjs +57 -0
  128. package/.output/server/chunks/routes/api/get-view-definition.mjs.map +1 -0
  129. package/.output/server/chunks/routes/api/getMetricMonitor.mjs.map +1 -1
  130. package/.output/server/chunks/routes/api/raw-execute.mjs +1 -2
  131. package/.output/server/chunks/routes/api/raw-execute.mjs.map +1 -1
  132. package/.output/server/chunks/routes/api/rename-function.mjs +77 -0
  133. package/.output/server/chunks/routes/api/rename-function.mjs.map +1 -0
  134. package/.output/server/chunks/routes/api/update-function.mjs +65 -0
  135. package/.output/server/chunks/routes/api/update-function.mjs.map +1 -0
  136. package/.output/server/chunks/routes/renderer.mjs +1 -1
  137. package/.output/server/index.mjs +1 -1
  138. package/.output/server/node_modules/cross-spawn/index.js +39 -0
  139. package/.output/server/node_modules/cross-spawn/lib/enoent.js +59 -0
  140. package/.output/server/node_modules/cross-spawn/lib/parse.js +91 -0
  141. package/.output/server/node_modules/cross-spawn/lib/util/escape.js +47 -0
  142. package/.output/server/node_modules/cross-spawn/lib/util/readShebang.js +23 -0
  143. package/.output/server/node_modules/cross-spawn/lib/util/resolveCommand.js +52 -0
  144. package/.output/server/node_modules/cross-spawn/package.json +73 -0
  145. package/.output/server/node_modules/execa/index.js +268 -0
  146. package/.output/server/node_modules/execa/lib/command.js +52 -0
  147. package/.output/server/node_modules/execa/lib/error.js +88 -0
  148. package/.output/server/node_modules/execa/lib/kill.js +115 -0
  149. package/.output/server/node_modules/execa/lib/promise.js +46 -0
  150. package/.output/server/node_modules/execa/lib/stdio.js +52 -0
  151. package/.output/server/node_modules/execa/lib/stream.js +97 -0
  152. package/.output/server/node_modules/execa/package.json +74 -0
  153. package/.output/server/node_modules/get-stream/buffer-stream.js +52 -0
  154. package/.output/server/node_modules/get-stream/index.js +61 -0
  155. package/.output/server/node_modules/get-stream/package.json +47 -0
  156. package/.output/server/node_modules/human-signals/build/src/core.js +273 -0
  157. package/.output/server/node_modules/human-signals/build/src/main.js +71 -0
  158. package/.output/server/node_modules/human-signals/build/src/realtime.js +19 -0
  159. package/.output/server/node_modules/human-signals/build/src/signals.js +35 -0
  160. package/.output/server/node_modules/human-signals/package.json +64 -0
  161. package/.output/server/node_modules/is-stream/index.js +28 -0
  162. package/.output/server/node_modules/is-stream/package.json +42 -0
  163. package/.output/server/node_modules/isexe/index.js +57 -0
  164. package/.output/server/node_modules/isexe/mode.js +41 -0
  165. package/.output/server/node_modules/isexe/package.json +31 -0
  166. package/.output/server/node_modules/isexe/windows.js +42 -0
  167. package/.output/server/node_modules/merge-stream/index.js +41 -0
  168. package/.output/server/node_modules/merge-stream/package.json +19 -0
  169. package/.output/server/node_modules/mimic-fn/index.js +13 -0
  170. package/.output/server/node_modules/mimic-fn/package.json +42 -0
  171. package/.output/server/node_modules/npm-run-path/index.js +47 -0
  172. package/.output/server/node_modules/npm-run-path/package.json +44 -0
  173. package/.output/server/node_modules/onetime/index.js +44 -0
  174. package/.output/server/node_modules/onetime/package.json +43 -0
  175. package/.output/server/node_modules/path-key/index.js +16 -0
  176. package/.output/server/node_modules/path-key/package.json +39 -0
  177. package/.output/server/node_modules/pg-copy-streams/copy-both.js +267 -0
  178. package/.output/server/node_modules/pg-copy-streams/copy-from.js +173 -0
  179. package/.output/server/node_modules/pg-copy-streams/copy-to.js +177 -0
  180. package/.output/server/node_modules/pg-copy-streams/index.js +17 -0
  181. package/.output/server/node_modules/pg-copy-streams/message-formats.js +27 -0
  182. package/.output/server/node_modules/pg-copy-streams/obuf.js +376 -0
  183. package/.output/server/node_modules/pg-copy-streams/package.json +51 -0
  184. package/.output/server/node_modules/pg-dump-restore/lib/common.js +33 -0
  185. package/.output/server/node_modules/pg-dump-restore/lib/index.js +9 -0
  186. package/.output/server/node_modules/pg-dump-restore/lib/pg-dump.js +95 -0
  187. package/.output/server/node_modules/pg-dump-restore/lib/pg-restore.js +87 -0
  188. package/.output/server/node_modules/pg-dump-restore/package.json +66 -0
  189. package/.output/server/node_modules/pg-query-stream/esm/index.mjs +5 -0
  190. package/.output/server/node_modules/shebang-command/index.js +19 -0
  191. package/.output/server/node_modules/shebang-command/package.json +34 -0
  192. package/.output/server/node_modules/shebang-regex/index.js +2 -0
  193. package/.output/server/node_modules/shebang-regex/package.json +35 -0
  194. package/.output/server/node_modules/signal-exit/index.js +202 -0
  195. package/.output/server/node_modules/signal-exit/package.json +38 -0
  196. package/.output/server/node_modules/signal-exit/signals.js +53 -0
  197. package/.output/server/node_modules/strip-final-newline/index.js +16 -0
  198. package/.output/server/node_modules/strip-final-newline/package.json +40 -0
  199. package/.output/server/node_modules/which/package.json +43 -0
  200. package/.output/server/node_modules/which/which.js +125 -0
  201. package/.output/server/package.json +19 -1
  202. package/package.json +1 -1
  203. package/.output/public/_nuxt/9lJACZIQ.js +0 -19
  204. package/.output/public/_nuxt/B2DnNiWd.js +0 -1
  205. package/.output/public/_nuxt/BH83_dXo.js +0 -39
  206. package/.output/public/_nuxt/BIKqrFbQ.js +0 -1
  207. package/.output/public/_nuxt/BNjPC06x.js +0 -1
  208. package/.output/public/_nuxt/BPQ-Pz1w.js +0 -39
  209. package/.output/public/_nuxt/BRpgKkVT.js +0 -51
  210. package/.output/public/_nuxt/BTCLPbPY.js +0 -4
  211. package/.output/public/_nuxt/BUV-RarV.js +0 -1
  212. package/.output/public/_nuxt/Bh6RgYlO.js +0 -1
  213. package/.output/public/_nuxt/Bq3cyzOD.js +0 -1
  214. package/.output/public/_nuxt/Bt9sU68B.js +0 -9
  215. package/.output/public/_nuxt/BwpH2ZxJ.js +0 -1
  216. package/.output/public/_nuxt/C25Tmn1m.js +0 -1
  217. package/.output/public/_nuxt/C2HlI1ss.js +0 -1
  218. package/.output/public/_nuxt/CU3ZV9iV.js +0 -1
  219. package/.output/public/_nuxt/CepyvMhE.js +0 -1
  220. package/.output/public/_nuxt/CuBKbBH_.js +0 -1
  221. package/.output/public/_nuxt/CulD8qYQ.js +0 -193
  222. package/.output/public/_nuxt/CylkLpwm.js +0 -1
  223. package/.output/public/_nuxt/D-bWLYHw.js +0 -1
  224. package/.output/public/_nuxt/D-zecHND.js +0 -1
  225. package/.output/public/_nuxt/D8vj6kFe.js +0 -160
  226. package/.output/public/_nuxt/DIETYtCL.js +0 -1
  227. package/.output/public/_nuxt/DJ4vUzxS.js +0 -1
  228. package/.output/public/_nuxt/DK-itzXx.js +0 -8
  229. package/.output/public/_nuxt/DL3T5jYo.js +0 -3867
  230. package/.output/public/_nuxt/DUsuhY9i.js +0 -1
  231. package/.output/public/_nuxt/DXV2HFBA.js +0 -224
  232. package/.output/public/_nuxt/Dh2zppOR.js +0 -1
  233. package/.output/public/_nuxt/DlAUqK2U.js +0 -1
  234. package/.output/public/_nuxt/DlmSeCnw.js +0 -5
  235. package/.output/public/_nuxt/DswTpYG4.js +0 -1
  236. package/.output/public/_nuxt/G830WtVn.js +0 -1
  237. package/.output/public/_nuxt/ICwM1E4-.js +0 -15
  238. package/.output/public/_nuxt/QZbJy9YW.js +0 -31
  239. package/.output/public/_nuxt/QuickQueryTable.DS_ON57S.css +0 -1
  240. package/.output/public/_nuxt/UXhX8z2W.js +0 -1
  241. package/.output/public/_nuxt/WrapperErdDiagram.DwhUd9Wr.css +0 -1
  242. package/.output/public/_nuxt/_tabViewId_.9Axt3zoi.css +0 -1
  243. package/.output/public/_nuxt/builds/meta/03cede5c-c45c-41b3-ac1a-73756bb8cff0.json +0 -1
  244. package/.output/public/_nuxt/default.DixIpIal.css +0 -1
  245. package/.output/public/_nuxt/entry.GqPNPe1e.css +0 -1
  246. package/.output/public/_nuxt/ivUnXl9B.js +0 -1
  247. package/.output/public/_nuxt/pAheHeBV.js +0 -36
  248. package/.output/public/_nuxt/s5fCn4j5.js +0 -1
@@ -0,0 +1,173 @@
1
+ 'use strict'
2
+
3
+ module.exports = function (txt, options) {
4
+ return new CopyStreamQuery(txt, options)
5
+ }
6
+
7
+ const { Writable } = require('stream')
8
+ const code = require('./message-formats')
9
+
10
+ class CopyStreamQuery extends Writable {
11
+ constructor(text, options) {
12
+ super(options)
13
+ this.text = text
14
+ this.rowCount = 0
15
+ this._gotCopyInResponse = false
16
+ this.chunks = []
17
+ this.cb_CopyInResponse = null
18
+ this.cb_ReadyForQuery = null
19
+ this.cb_destroy = null
20
+ this.cork()
21
+ }
22
+
23
+ submit(connection) {
24
+ this.connection = connection
25
+ connection.query(this.text)
26
+ }
27
+
28
+ callback() {
29
+ // this callback is empty but defining it allows
30
+ // `pg` to discover it and overwrite it
31
+ // with its timeout mechanism when query_timeout config is set
32
+ }
33
+
34
+ _write(chunk, enc, cb) {
35
+ this.chunks.push({ chunk: chunk, encoding: enc })
36
+ if (this._gotCopyInResponse) {
37
+ return this.flush(cb)
38
+ }
39
+ this.cb_CopyInResponse = cb
40
+ }
41
+
42
+ _writev(chunks, cb) {
43
+ // this.chunks.push(...chunks)
44
+ // => issue #136, RangeError: Maximum call stack size exceeded
45
+ // Using hybrid approach as advised on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
46
+ if (this.chunks.length == 0) {
47
+ this.chunks = chunks
48
+ } else {
49
+ // https://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept
50
+ // 100K seems to be a reasonable size for v8
51
+ const QUANTUM = 125000
52
+ for (let i = 0; i < chunks.length; i += QUANTUM) {
53
+ this.chunks.push(...chunks.slice(i, Math.min(i + QUANTUM, chunks.length)))
54
+ }
55
+ }
56
+ if (this._gotCopyInResponse) {
57
+ return this.flush(cb)
58
+ }
59
+ this.cb_CopyInResponse = cb
60
+ }
61
+
62
+ _destroy(err, cb) {
63
+ // writable.destroy([error]) was called.
64
+ // send a CopyFail message that will rollback the COPY operation.
65
+ // the cb will be called only after the ErrorResponse message is received
66
+ // from the backend
67
+ if (this.cb_ReadyForQuery) return cb(err)
68
+ this.cb_destroy = cb
69
+ const msg = err ? err.message : 'NODE-PG-COPY-STREAMS destroy() was called'
70
+ const self = this
71
+ const done = function () {
72
+ self.connection.sendCopyFail(msg)
73
+ }
74
+
75
+ this.chunks = []
76
+ if (this._gotCopyInResponse) {
77
+ return this.flush(done)
78
+ }
79
+ this.cb_CopyInResponse = done
80
+ }
81
+
82
+ _final(cb) {
83
+ this.cb_ReadyForQuery = cb
84
+ const self = this
85
+ const done = function () {
86
+ const Int32Len = 4
87
+ const finBuffer = Buffer.from([code.CopyDone, 0, 0, 0, Int32Len])
88
+ self.connection.stream.write(finBuffer)
89
+ }
90
+
91
+ if (this._gotCopyInResponse) {
92
+ return this.flush(done)
93
+ }
94
+ this.cb_CopyInResponse = done
95
+ }
96
+
97
+ flush(callback) {
98
+ let chunk
99
+ let ok = true
100
+ while (ok && (chunk = this.chunks.shift())) {
101
+ ok = this.flushChunk(chunk.chunk)
102
+ }
103
+ if (callback) {
104
+ if (ok) {
105
+ callback()
106
+ } else {
107
+ if (this.chunks.length) {
108
+ this.connection.stream.once('drain', this.flush.bind(this, callback))
109
+ } else {
110
+ this.connection.stream.once('drain', callback)
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ flushChunk(chunk) {
117
+ const Int32Len = 4
118
+ const lenBuffer = Buffer.from([code.CopyData, 0, 0, 0, 0])
119
+ lenBuffer.writeUInt32BE(chunk.length + Int32Len, 1)
120
+ this.connection.stream.write(lenBuffer)
121
+ return this.connection.stream.write(chunk)
122
+ }
123
+
124
+ handleError(e) {
125
+ // clear `pg` timeout mechanism
126
+ this.callback()
127
+
128
+ if (this.cb_destroy) {
129
+ const cb = this.cb_destroy
130
+ this.cb_destroy = null
131
+ cb(e)
132
+ } else {
133
+ this.emit('error', e)
134
+ }
135
+ this.connection = null
136
+ }
137
+
138
+ handleCopyInResponse(connection) {
139
+ this._gotCopyInResponse = true
140
+ if (!this.destroyed) {
141
+ this.uncork()
142
+ }
143
+ const cb = this.cb_CopyInResponse || function () {}
144
+ this.cb_CopyInResponse = null
145
+ this.flush(cb)
146
+ }
147
+
148
+ handleCommandComplete(msg) {
149
+ // Parse affected row count as in
150
+ // https://github.com/brianc/node-postgres/blob/35e5567f86774f808c2a8518dd312b8aa3586693/lib/result.js#L37
151
+ const match = /COPY (\d+)/.exec((msg || {}).text)
152
+ if (match) {
153
+ this.rowCount = parseInt(match[1], 10)
154
+ }
155
+ }
156
+
157
+ handleReadyForQuery() {
158
+ // triggered after ReadyForQuery
159
+ // we delay the _final callback so that the 'finish' event is
160
+ // sent only when the ingested data is visible inside postgres and
161
+ // after the postgres connection is ready for a new query
162
+
163
+ // Note: `pg` currently does not call this callback when the backend
164
+ // sends an ErrorResponse message during the query (for example during
165
+ // a CopyFail)
166
+
167
+ // clear `pg` timeout mechanism
168
+ this.callback()
169
+
170
+ this.cb_ReadyForQuery()
171
+ this.connection = null
172
+ }
173
+ }
@@ -0,0 +1,177 @@
1
+ 'use strict'
2
+
3
+ module.exports = function (txt, options) {
4
+ return new CopyStreamQuery(txt, options)
5
+ }
6
+
7
+ const { Readable } = require('stream')
8
+ const assert = require('assert')
9
+ const BufferList = require('./obuf')
10
+ const code = require('./message-formats')
11
+
12
+ // decoder states
13
+ const PG_CODE = 0
14
+ const PG_LENGTH = 1
15
+ const PG_MESSAGE = 2
16
+
17
+ class CopyStreamQuery extends Readable {
18
+ constructor(text, options) {
19
+ super(options)
20
+ this.text = text
21
+ this.rowCount = 0
22
+ this._state = PG_CODE
23
+ this._buffer = new BufferList()
24
+ this._unreadMessageContentLength = 0
25
+ this._copyDataChunks = new BufferList()
26
+ this._pgDataHandler = null
27
+ this._drained = false
28
+ this._forwarding = false
29
+ this._onReadableEvent = this._onReadable.bind(this)
30
+ }
31
+
32
+ submit(connection) {
33
+ this.connection = connection
34
+ this._attach()
35
+ connection.query(this.text)
36
+ }
37
+
38
+ _attach() {
39
+ const connectionStream = this.connection.stream
40
+ const pgDataListeners = connectionStream.listeners('data')
41
+ assert(pgDataListeners.length == 1)
42
+ this._pgDataHandler = pgDataListeners.pop()
43
+ connectionStream.removeListener('data', this._pgDataHandler)
44
+ connectionStream.pause()
45
+ this._forward()
46
+ connectionStream.on('readable', this._onReadableEvent)
47
+ }
48
+
49
+ _detach() {
50
+ const connectionStream = this.connection.stream
51
+ const unreadBuffer = this._buffer.take(this._buffer.size)
52
+ //connectionStream.unpipe(this)
53
+ connectionStream.removeListener('readable', this._onReadableEvent)
54
+ connectionStream.addListener('data', this._pgDataHandler)
55
+ this._pgDataHandler(unreadBuffer)
56
+
57
+ // unpipe can pause the stream but also underlying onData event can potentially pause the stream because of hitting
58
+ // the highWaterMark and pausing the stream, so we resume the stream in the next tick after the underlying onData
59
+ // event has finished
60
+ process.nextTick(function () {
61
+ connectionStream.resume()
62
+ })
63
+ }
64
+
65
+ _cleanup() {
66
+ this._buffer = null
67
+ this._copyDataChunks = null
68
+ this._pgDataHandler = null
69
+ this._onReadableEvent = null
70
+ }
71
+
72
+ _onReadable() {
73
+ this._forward()
74
+ }
75
+
76
+ _read() {
77
+ this._drained = true
78
+ this._forward()
79
+ }
80
+
81
+ _forward() {
82
+ if (this._forwarding || !this._drained || !this.connection) return
83
+ this._forwarding = true
84
+ const connectionStream = this.connection.stream
85
+ let chunk
86
+ while (this._drained && (chunk = connectionStream.read()) !== null) {
87
+ this._drained = this._parse(chunk)
88
+ }
89
+ this._forwarding = false
90
+ }
91
+
92
+ _parse(chunk) {
93
+ let done = false
94
+ let drained = true
95
+ this._buffer.push(chunk)
96
+
97
+ while (!done && this._buffer.size > 0) {
98
+ if (PG_CODE === this._state) {
99
+ if (!this._buffer.has(1)) break
100
+ this._code = this._buffer.peekUInt8()
101
+ if (this._code === code.ErrorResponse) {
102
+ // ErrorResponse Interception
103
+ // We must let pg parse future messages and handle their consequences on
104
+ // the ActiveQuery
105
+ this._detach()
106
+ return
107
+ }
108
+ this._buffer.readUInt8()
109
+ this._state = PG_LENGTH
110
+ }
111
+
112
+ if (PG_LENGTH === this._state) {
113
+ if (!this._buffer.has(4)) break
114
+ this._unreadMessageContentLength = this._buffer.readUInt32BE() - 4
115
+ this._state = PG_MESSAGE
116
+ }
117
+
118
+ if (PG_MESSAGE === this._state) {
119
+ if (this._unreadMessageContentLength > 0 && this._buffer.size > 0) {
120
+ const n = Math.min(this._buffer.size, this._unreadMessageContentLength)
121
+ const messageContentChunk = this._buffer.take(n)
122
+ this._unreadMessageContentLength -= n
123
+ if (this._code === code.CopyData) {
124
+ this._copyDataChunks.push(messageContentChunk)
125
+ }
126
+ }
127
+
128
+ if (this._unreadMessageContentLength === 0) {
129
+ // a full message has been captured
130
+ switch (this._code) {
131
+ case code.CopyOutResponse:
132
+ case code.CopyData:
133
+ // standard interspersed messages.
134
+ // see https://www.postgresql.org/docs/9.6/protocol-flow.html#PROTOCOL-COPY
135
+ case code.ParameterStatus:
136
+ case code.NoticeResponse:
137
+ case code.NotificationResponse:
138
+ break
139
+ case code.CopyDone:
140
+ default:
141
+ done = true
142
+ break
143
+ }
144
+ this._state = PG_CODE
145
+ }
146
+ }
147
+ }
148
+
149
+ // flush data if any data has been captured
150
+ const len = this._copyDataChunks.size
151
+ if (len > 0) {
152
+ drained = this.push(this._copyDataChunks.take(len))
153
+ }
154
+
155
+ if (done) {
156
+ this._detach()
157
+ this.push(null)
158
+ this._cleanup()
159
+ }
160
+
161
+ return drained
162
+ }
163
+
164
+ handleError(err) {
165
+ this.emit('error', err)
166
+ this._cleanup()
167
+ }
168
+
169
+ handleCommandComplete(msg) {
170
+ const match = /COPY (\d+)/.exec((msg || {}).text)
171
+ if (match) {
172
+ this.rowCount = parseInt(match[1], 10)
173
+ }
174
+ }
175
+
176
+ handleReadyForQuery() {}
177
+ }
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ const CopyToQueryStream = require('./copy-to')
4
+ const CopyFromQueryStream = require('./copy-from')
5
+ const CopyBothQueryStream = require('./copy-both')
6
+
7
+ exports.to = function copyTo(txt, options) {
8
+ return new CopyToQueryStream(txt, options)
9
+ }
10
+
11
+ exports.from = function copyFrom(txt, options) {
12
+ return new CopyFromQueryStream(txt, options)
13
+ }
14
+
15
+ exports.both = function copyBoth(txt, options) {
16
+ return new CopyBothQueryStream(txt, options)
17
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The COPY feature uses the following protocol codes.
3
+ * The codes for the most recent protocol version are documented on
4
+ * https://www.postgresql.org/docs/current/static/protocol-message-formats.html
5
+ *
6
+ * The protocol flow itself is described on
7
+ * https://www.postgresql.org/docs/current/static/protocol-flow.html
8
+ */
9
+ module.exports = {
10
+ ErrorResponse: 0x45, // E
11
+ CopyInResponse: 0x47, // G
12
+ CopyOutResponse: 0x48, // H
13
+ CopyBothResponse: 0x57, // W
14
+ CopyDone: 0x63, // c
15
+ CopyData: 0x64, // d
16
+ CopyFail: 0x66, // f
17
+ CommandComplete: 0x43, // C
18
+ ReadyForQuery: 0x5a, // Z
19
+
20
+ // It is possible for NoticeResponse and ParameterStatus messages to be interspersed between CopyData messages;
21
+ // frontends must handle these cases, and should be prepared for other asynchronous message types as well
22
+ // (see Section 50.2.6).
23
+ // Otherwise, any message type other than CopyData or CopyDone may be treated as terminating copy-out mode.
24
+ NotificationResponse: 0x41, // A
25
+ NoticeResponse: 0x4e, // N
26
+ ParameterStatus: 0x53, // S
27
+ }