orange-orm 3.10.2

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 (459) hide show
  1. package/.dockerignore +1 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.js +45 -0
  4. package/.gitattributes +3 -0
  5. package/CNAME +1 -0
  6. package/CONTRIBUTING.md +43 -0
  7. package/LICENSE +7 -0
  8. package/README.md +1969 -0
  9. package/SECURITY.md +12 -0
  10. package/bin/build.js +127 -0
  11. package/bin/compile.js +26 -0
  12. package/bin/rdb.js +4 -0
  13. package/docs/CODE_OF_CONDUCT.md +18 -0
  14. package/docs/changelog.md +461 -0
  15. package/docs/docs.md +2373 -0
  16. package/docs/orange.svg +32 -0
  17. package/docs/relations.png +0 -0
  18. package/package.json +139 -0
  19. package/src/applyPatch.js +105 -0
  20. package/src/client/axiosInterceptor.js +46 -0
  21. package/src/client/clientMap.js +72 -0
  22. package/src/client/createPatch.js +122 -0
  23. package/src/client/createProviders.js +121 -0
  24. package/src/client/index.js +997 -0
  25. package/src/client/index.mjs +6295 -0
  26. package/src/client/map.js +110 -0
  27. package/src/client/merge.js +9 -0
  28. package/src/client/netAdapter.js +133 -0
  29. package/src/client/rollup.config.js +12 -0
  30. package/src/client/self.js +4 -0
  31. package/src/client/stringify.js +22 -0
  32. package/src/client/toKeyPositionMap.js +30 -0
  33. package/src/clsTest.js +79 -0
  34. package/src/createDomain/negotiateForwardProperty.js +23 -0
  35. package/src/createDomain.js +31 -0
  36. package/src/dateToISOString.js +25 -0
  37. package/src/emitEvent.js +46 -0
  38. package/src/emptyFilter.js +35 -0
  39. package/src/flags.js +6 -0
  40. package/src/fromCompareObject.js +24 -0
  41. package/src/generic-pool.js +641 -0
  42. package/src/getManyDto/newQuery.js +18 -0
  43. package/src/getManyDto/query/newColumnSql.js +8 -0
  44. package/src/getManyDto/query/newSingleQuery.js +19 -0
  45. package/src/getManyDto/query/singleQuery/newJoinedColumnSql.js +25 -0
  46. package/src/getManyDto/query/singleQuery/newShallowColumnSql.js +25 -0
  47. package/src/getManyDto.js +255 -0
  48. package/src/getTSDefinition.js +510 -0
  49. package/src/hostExpress/executePath.js +433 -0
  50. package/src/hostExpress/getMeta.js +49 -0
  51. package/src/hostExpress.js +125 -0
  52. package/src/hostLocal.js +110 -0
  53. package/src/index.d.ts +324 -0
  54. package/src/index.js +116 -0
  55. package/src/jsconfig.json +8 -0
  56. package/src/lock/toIntKey.js +35 -0
  57. package/src/lock.js +26 -0
  58. package/src/map.d.ts +1729 -0
  59. package/src/mssql/encodeBuffer.js +7 -0
  60. package/src/mssql/newDatabase.js +129 -0
  61. package/src/mssql/newPool.js +19 -0
  62. package/src/mssql/newTransaction.js +69 -0
  63. package/src/mssql/pool/defaults.js +45 -0
  64. package/src/mssql/pool/end.js +13 -0
  65. package/src/mssql/pool/newGenericPool.js +62 -0
  66. package/src/mssql/wrapQuery.js +34 -0
  67. package/src/mySql/deleteFromSql.js +8 -0
  68. package/src/mySql/encodeBoolean.js +7 -0
  69. package/src/mySql/insert.js +21 -0
  70. package/src/mySql/insertSql.js +62 -0
  71. package/src/mySql/lastInsertedSql.js +11 -0
  72. package/src/mySql/limitAndOffset.js +18 -0
  73. package/src/mySql/newDatabase.js +127 -0
  74. package/src/mySql/newPool.js +19 -0
  75. package/src/mySql/newTransaction.js +54 -0
  76. package/src/mySql/pool/defaults.js +16 -0
  77. package/src/mySql/pool/end.js +13 -0
  78. package/src/mySql/pool/negotiatePoolOptions.js +12 -0
  79. package/src/mySql/pool/newGenericPool.js +67 -0
  80. package/src/mySql/selectForUpdateSql.js +3 -0
  81. package/src/mySql/wrapQuery.js +16 -0
  82. package/src/mySql/wrapQueryStream.js +9 -0
  83. package/src/newArray.js +3 -0
  84. package/src/newCollection.js +55 -0
  85. package/src/newId.js +1 -0
  86. package/src/newImmutable.js +22 -0
  87. package/src/newObject.js +5 -0
  88. package/src/oracle/deleteFromSql.js +8 -0
  89. package/src/oracle/encodeBoolean.js +7 -0
  90. package/src/oracle/encodeBuffer.js +7 -0
  91. package/src/oracle/encodeDate.js +7 -0
  92. package/src/oracle/formatDateIn.js +5 -0
  93. package/src/oracle/formatDateOut.js +5 -0
  94. package/src/oracle/insert.js +23 -0
  95. package/src/oracle/insertSql.js +73 -0
  96. package/src/oracle/lastInsertedSql.js +14 -0
  97. package/src/oracle/limitAndOffset.js +18 -0
  98. package/src/oracle/mergeSql.js +79 -0
  99. package/src/oracle/newDatabase.js +128 -0
  100. package/src/oracle/newInsertCommandCore.js +27 -0
  101. package/src/oracle/newPool.js +19 -0
  102. package/src/oracle/newTransaction.js +63 -0
  103. package/src/oracle/outputInsertedSql.js +5 -0
  104. package/src/oracle/pool/defaults.js +45 -0
  105. package/src/oracle/pool/end.js +13 -0
  106. package/src/oracle/pool/newGenericPool.js +64 -0
  107. package/src/oracle/replaceParamChar.js +14 -0
  108. package/src/oracle/selectForUpdateSql.js +3 -0
  109. package/src/oracle/wrapQuery.js +38 -0
  110. package/src/patchRow.js +13 -0
  111. package/src/patchTable.js +317 -0
  112. package/src/pg/deleteFromSql.js +8 -0
  113. package/src/pg/encodeBoolean.js +5 -0
  114. package/src/pg/encodeDate.js +7 -0
  115. package/src/pg/encodeJSON.js +15 -0
  116. package/src/pg/formatDateOut.js +5 -0
  117. package/src/pg/insert.js +14 -0
  118. package/src/pg/insertSql.js +70 -0
  119. package/src/pg/lastInsertedSql.js +11 -0
  120. package/src/pg/limitAndOffset.js +18 -0
  121. package/src/pg/newDatabase.js +153 -0
  122. package/src/pg/newPool.js +19 -0
  123. package/src/pg/newStreamableQuery.js +7 -0
  124. package/src/pg/newTransaction.js +58 -0
  125. package/src/pg/pool/defaults.js +45 -0
  126. package/src/pg/pool/end.js +13 -0
  127. package/src/pg/pool/newPgPool.js +82 -0
  128. package/src/pg/replaceParamChar.js +14 -0
  129. package/src/pg/schema.js +11 -0
  130. package/src/pg/selectForUpdateSql.js +3 -0
  131. package/src/pg/wrapQuery.js +33 -0
  132. package/src/pg/wrapQueryStream.js +20 -0
  133. package/src/pools.js +17 -0
  134. package/src/query/negotiateParameters.js +10 -0
  135. package/src/query/negotiateSql.js +14 -0
  136. package/src/query/wrapQuery.js +17 -0
  137. package/src/query.js +13 -0
  138. package/src/sap/deleteFromSql.js +8 -0
  139. package/src/sap/encodeBoolean.js +7 -0
  140. package/src/sap/encodeBuffer.js +7 -0
  141. package/src/sap/formatDateOut.js +5 -0
  142. package/src/sap/insert.js +21 -0
  143. package/src/sap/insertSql.js +64 -0
  144. package/src/sap/lastInsertedSql.js +12 -0
  145. package/src/sap/limitAndOffset.js +16 -0
  146. package/src/sap/mergeSql.js +73 -0
  147. package/src/sap/newDatabase.js +129 -0
  148. package/src/sap/newPool.js +19 -0
  149. package/src/sap/newTransaction.js +69 -0
  150. package/src/sap/pool/end.js +13 -0
  151. package/src/sap/selectForUpdateSql.js +3 -0
  152. package/src/sqlite/deleteFromSql.js +8 -0
  153. package/src/sqlite/encodeBoolean.js +7 -0
  154. package/src/sqlite/encodeBuffer.js +7 -0
  155. package/src/sqlite/insert.js +21 -0
  156. package/src/sqlite/insertSql.js +64 -0
  157. package/src/sqlite/lastInsertedSql.js +12 -0
  158. package/src/sqlite/limitAndOffset.js +18 -0
  159. package/src/sqlite/newDatabase.js +128 -0
  160. package/src/sqlite/newPool.js +19 -0
  161. package/src/sqlite/newTransaction.js +58 -0
  162. package/src/sqlite/pool/defaults.js +45 -0
  163. package/src/sqlite/pool/end.js +13 -0
  164. package/src/sqlite/pool/newGenericPool.js +59 -0
  165. package/src/sqlite/selectForUpdateSql.js +3 -0
  166. package/src/sqlite/wrapQuery.js +24 -0
  167. package/src/table/aggregate.js +9 -0
  168. package/src/table/begin.js +10 -0
  169. package/src/table/cascadeDelete.js +11 -0
  170. package/src/table/cloneStrategy.js +18 -0
  171. package/src/table/column/binary/newDecode.js +15 -0
  172. package/src/table/column/binary/newEncode.js +23 -0
  173. package/src/table/column/binary/purify.js +12 -0
  174. package/src/table/column/binary.js +12 -0
  175. package/src/table/column/boolean/newDecode.js +12 -0
  176. package/src/table/column/boolean/newEncode.js +36 -0
  177. package/src/table/column/boolean/purify.js +7 -0
  178. package/src/table/column/boolean.js +14 -0
  179. package/src/table/column/date/formatOut.js +11 -0
  180. package/src/table/column/date/newDecode.js +17 -0
  181. package/src/table/column/date/newEncode.js +47 -0
  182. package/src/table/column/date/purify.js +17 -0
  183. package/src/table/column/date/toISOString.js +25 -0
  184. package/src/table/column/date/tryParseISO.js +14 -0
  185. package/src/table/column/date.js +14 -0
  186. package/src/table/column/dateWithTimeZone/newEncode.js +41 -0
  187. package/src/table/column/dateWithTimeZone.js +14 -0
  188. package/src/table/column/encodeFilterArg.js +8 -0
  189. package/src/table/column/equal.js +15 -0
  190. package/src/table/column/extractAlias.js +7 -0
  191. package/src/table/column/greaterThan.js +12 -0
  192. package/src/table/column/greaterThanOrEqual.js +12 -0
  193. package/src/table/column/guid/newDecode.js +10 -0
  194. package/src/table/column/guid/newEncode.js +30 -0
  195. package/src/table/column/guid/purify.js +10 -0
  196. package/src/table/column/guid.js +12 -0
  197. package/src/table/column/in.js +24 -0
  198. package/src/table/column/json/formatOut.js +11 -0
  199. package/src/table/column/json/newDecode.js +21 -0
  200. package/src/table/column/json/newEncode.js +41 -0
  201. package/src/table/column/json/purify.js +7 -0
  202. package/src/table/column/json.js +22 -0
  203. package/src/table/column/lessThan.js +12 -0
  204. package/src/table/column/lessThanOrEqual.js +12 -0
  205. package/src/table/column/negotiateNextAndFilter.js +7 -0
  206. package/src/table/column/negotiateNextOrFilter.js +7 -0
  207. package/src/table/column/negotiateRawSqlFilter.js +74 -0
  208. package/src/table/column/newBoolean.js +54 -0
  209. package/src/table/column/newColumn.js +89 -0
  210. package/src/table/column/newDecodeCore.js +10 -0
  211. package/src/table/column/notEqual.js +15 -0
  212. package/src/table/column/numeric/negotiateDefault.js +5 -0
  213. package/src/table/column/numeric/newDecode.js +16 -0
  214. package/src/table/column/numeric/newEncode.js +25 -0
  215. package/src/table/column/numeric/purify.js +12 -0
  216. package/src/table/column/numeric.js +15 -0
  217. package/src/table/column/string/contains.js +3 -0
  218. package/src/table/column/string/containsCore.js +16 -0
  219. package/src/table/column/string/endsWith.js +3 -0
  220. package/src/table/column/string/endsWithCore.js +16 -0
  221. package/src/table/column/string/iContains.js +3 -0
  222. package/src/table/column/string/iEndsWith.js +3 -0
  223. package/src/table/column/string/iEqual.js +15 -0
  224. package/src/table/column/string/iStartsWith.js +3 -0
  225. package/src/table/column/string/newEncode.js +31 -0
  226. package/src/table/column/string/purify.js +7 -0
  227. package/src/table/column/string/startsWith.js +3 -0
  228. package/src/table/column/string/startsWithCore.js +16 -0
  229. package/src/table/column/string.js +55 -0
  230. package/src/table/column.js +154 -0
  231. package/src/table/commands/beginCommand.js +13 -0
  232. package/src/table/commands/commitCommand.js +9 -0
  233. package/src/table/commands/compressChanges.js +25 -0
  234. package/src/table/commands/delete/createAlias.js +6 -0
  235. package/src/table/commands/delete/newSingleCommand.js +17 -0
  236. package/src/table/commands/delete/singleCommand/joinSql.js +26 -0
  237. package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +19 -0
  238. package/src/table/commands/delete/singleCommand/selectSql.js +11 -0
  239. package/src/table/commands/delete/singleCommand/subFilter.js +19 -0
  240. package/src/table/commands/delete/singleCommand/whereSql.js +25 -0
  241. package/src/table/commands/getChangeSet.js +6 -0
  242. package/src/table/commands/insert/getSqlTemplate.js +68 -0
  243. package/src/table/commands/lastCommandMatches.js +11 -0
  244. package/src/table/commands/negotiateEndEdit.js +7 -0
  245. package/src/table/commands/newDeleteCommand.js +23 -0
  246. package/src/table/commands/newGetLastInsertedCommand.js +49 -0
  247. package/src/table/commands/newGetLastInsertedCommandCore.js +42 -0
  248. package/src/table/commands/newInsertAndForgetCommand.js +55 -0
  249. package/src/table/commands/newInsertCommand.js +56 -0
  250. package/src/table/commands/newInsertCommandCore.js +27 -0
  251. package/src/table/commands/newRow.js +51 -0
  252. package/src/table/commands/newUpdateCommand.js +62 -0
  253. package/src/table/commands/newUpdateCommandCore.js +45 -0
  254. package/src/table/commands/pushCommand.js +10 -0
  255. package/src/table/commands/rollbackCommand.js +13 -0
  256. package/src/table/commit.js +30 -0
  257. package/src/table/count.js +29 -0
  258. package/src/table/createJSONReadStream.js +7 -0
  259. package/src/table/createJSONReadStreamDefault.js +33 -0
  260. package/src/table/createJSONReadStreamNative.js +31 -0
  261. package/src/table/createReadStream.js +24 -0
  262. package/src/table/createReadStreamCoreNative.js +40 -0
  263. package/src/table/createReadStreamDefault.js +102 -0
  264. package/src/table/createReadStreamNative.js +17 -0
  265. package/src/table/delete.js +20 -0
  266. package/src/table/deleteSessionContext.js +17 -0
  267. package/src/table/encodeDbSpecific.js +10 -0
  268. package/src/table/executeQueries/executeChanges.js +35 -0
  269. package/src/table/executeQueries/executeQueriesCore.js +12 -0
  270. package/src/table/executeQueries/executeQuery.js +8 -0
  271. package/src/table/executeQueries/resolveExecuteQuery.js +57 -0
  272. package/src/table/executeQueries.js +15 -0
  273. package/src/table/extractDeleteStrategy.js +9 -0
  274. package/src/table/fuzzyPromise.js +18 -0
  275. package/src/table/getById.js +33 -0
  276. package/src/table/getFirstFromDb.js +10 -0
  277. package/src/table/getFromDbById.js +17 -0
  278. package/src/table/getIdArgs.js +14 -0
  279. package/src/table/getMany.js +26 -0
  280. package/src/table/getManyDto/newQuery.js +32 -0
  281. package/src/table/getManyDto/pg/newQuery.js +8 -0
  282. package/src/table/getManyDto.js +10 -0
  283. package/src/table/getManyDtoFast/getSubRows.js +172 -0
  284. package/src/table/getManyDtoFast/newQuery.js +8 -0
  285. package/src/table/getManyDtoFast/newQueryCore.js +18 -0
  286. package/src/table/getManyDtoFast/query/newSingleQuery.js +20 -0
  287. package/src/table/getManyDtoFast/query/newSubQueries/joinLegToQuery.js +18 -0
  288. package/src/table/getManyDtoFast/query/newSubQueries/manyLegToQuery.js +20 -0
  289. package/src/table/getManyDtoFast/query/newSubQueries/oneLegToQuery.js +21 -0
  290. package/src/table/getManyDtoFast/query/newSubQueries.js +47 -0
  291. package/src/table/getManyDtoFast/query/singleQuery/newShallowColumnSql.js +21 -0
  292. package/src/table/getSessionContext.js +10 -0
  293. package/src/table/getSessionSingleton.js +5 -0
  294. package/src/table/groupBy/newQuery.js +25 -0
  295. package/src/table/groupBy.js +65 -0
  296. package/src/table/hasMany.js +33 -0
  297. package/src/table/hasOne.js +33 -0
  298. package/src/table/insert.js +91 -0
  299. package/src/table/insertDefault.js +88 -0
  300. package/src/table/join.js +42 -0
  301. package/src/table/joinRelation/getRelatives.js +64 -0
  302. package/src/table/log.js +39 -0
  303. package/src/table/negotiateAddStrategy.js +20 -0
  304. package/src/table/negotiateExpandInverse.js +13 -0
  305. package/src/table/newCache.js +96 -0
  306. package/src/table/newCascadeDeleteStrategy.js +30 -0
  307. package/src/table/newGetRelated.js +21 -0
  308. package/src/table/newJoinRelation.js +117 -0
  309. package/src/table/newManyRelation.js +61 -0
  310. package/src/table/newOneRelation.js +61 -0
  311. package/src/table/newPrimaryKeyFilter.js +13 -0
  312. package/src/table/newQuery.js +18 -0
  313. package/src/table/newRelatedTable.js +100 -0
  314. package/src/table/newRowCache.js +106 -0
  315. package/src/table/newThrow.js +11 -0
  316. package/src/table/nullPromise.js +1 -0
  317. package/src/table/objectToCallback.js +7 -0
  318. package/src/table/oneRelation/getRelatives.js +45 -0
  319. package/src/table/popChanges.js +19 -0
  320. package/src/table/promise.js +14 -0
  321. package/src/table/purifyStrategy.js +49 -0
  322. package/src/table/query/extractFilter.js +9 -0
  323. package/src/table/query/extractLimit.js +11 -0
  324. package/src/table/query/extractLimitQuery.js +23 -0
  325. package/src/table/query/extractOffset.js +11 -0
  326. package/src/table/query/extractOrderBy.js +57 -0
  327. package/src/table/query/extractSql.js +10 -0
  328. package/src/table/query/newParameterized.js +38 -0
  329. package/src/table/query/newSingleQuery.js +23 -0
  330. package/src/table/query/parameterized/extractParameters.js +8 -0
  331. package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +16 -0
  332. package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +27 -0
  333. package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +37 -0
  334. package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +13 -0
  335. package/src/table/query/singleQuery/joinSql/joinLegToShallowJoinSql.js +9 -0
  336. package/src/table/query/singleQuery/joinSql/newDiscriminatorSql.js +11 -0
  337. package/src/table/query/singleQuery/joinSql/newShallowJoinSql.js +9 -0
  338. package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +25 -0
  339. package/src/table/query/singleQuery/joinSql/oneLegToJoinSql.js +13 -0
  340. package/src/table/query/singleQuery/joinSql/oneLegToShallowJoinSql.js +10 -0
  341. package/src/table/query/singleQuery/negotiateExclusive.js +11 -0
  342. package/src/table/query/singleQuery/negotiateLimit.js +10 -0
  343. package/src/table/query/singleQuery/newColumnSql.js +8 -0
  344. package/src/table/query/singleQuery/newDiscriminatorSql.js +33 -0
  345. package/src/table/query/singleQuery/newJoinSql.js +41 -0
  346. package/src/table/query/singleQuery/newQueryContext.js +20 -0
  347. package/src/table/query/singleQuery/newWhereSql.js +19 -0
  348. package/src/table/readStream/extractLimit.js +7 -0
  349. package/src/table/readStream/extractOrderBy.js +55 -0
  350. package/src/table/readStream/mySql/newQuery.js +16 -0
  351. package/src/table/readStream/mySql/query/newSingleQuery.js +21 -0
  352. package/src/table/readStream/mySql/query/newSubQueries/joinLegToQuery.js +19 -0
  353. package/src/table/readStream/mySql/query/newSubQueries/manyLegToQuery.js +22 -0
  354. package/src/table/readStream/mySql/query/newSubQueries/newQueryCore.js +9 -0
  355. package/src/table/readStream/mySql/query/newSubQueries/newSingleQueryCore.js +18 -0
  356. package/src/table/readStream/mySql/query/newSubQueries/oneLegToQuery.js +22 -0
  357. package/src/table/readStream/mySql/query/newSubQueries.js +47 -0
  358. package/src/table/readStream/mySql/query/singleQuery/newShallowColumnSql.js +17 -0
  359. package/src/table/readStream/newQuery.js +32 -0
  360. package/src/table/readStream/newQueryStream.js +8 -0
  361. package/src/table/readStream/pg/newQuery.js +8 -0
  362. package/src/table/readStream/pg/newQueryCore.js +17 -0
  363. package/src/table/readStream/pg/query/newSingleQuery.js +19 -0
  364. package/src/table/readStream/pg/query/newSubQueries/joinLegToQuery.js +19 -0
  365. package/src/table/readStream/pg/query/newSubQueries/manyLegToQuery.js +22 -0
  366. package/src/table/readStream/pg/query/newSubQueries/oneLegToQuery.js +19 -0
  367. package/src/table/readStream/pg/query/newSubQueries.js +47 -0
  368. package/src/table/readStream/pg/query/singleQuery/newShallowColumnSql.js +19 -0
  369. package/src/table/readStreamDefault/createBatchFilter.js +39 -0
  370. package/src/table/relatedTable/aggregate/aggregateJoinSql.js +37 -0
  371. package/src/table/relatedTable/aggregate/joinSql.js +38 -0
  372. package/src/table/relatedTable/aggregate.js +48 -0
  373. package/src/table/relatedTable/all.js +24 -0
  374. package/src/table/relatedTable/any.js +70 -0
  375. package/src/table/relatedTable/childColumn.js +61 -0
  376. package/src/table/relatedTable/columnAggregate.js +16 -0
  377. package/src/table/relatedTable/columnAggregateGroup.js +59 -0
  378. package/src/table/relatedTable/joinSql.js +40 -0
  379. package/src/table/relatedTable/joinSqlArray.js +32 -0
  380. package/src/table/relatedTable/none.js +22 -0
  381. package/src/table/relatedTable/relatedColumn.js +49 -0
  382. package/src/table/relatedTable/relationFilter.js +16 -0
  383. package/src/table/relatedTable/selectSql.js +11 -0
  384. package/src/table/relatedTable/subFilter.js +16 -0
  385. package/src/table/relatedTable/where.js +50 -0
  386. package/src/table/relatedTable/whereSql.js +41 -0
  387. package/src/table/relation/manyCache/extractParentKey.js +17 -0
  388. package/src/table/relation/manyCache/synchronizeAdded.js +13 -0
  389. package/src/table/relation/manyCache/synchronizeChanged.js +31 -0
  390. package/src/table/relation/manyCache/synchronizeRemoved.js +13 -0
  391. package/src/table/relation/newExpanderCache.js +7 -0
  392. package/src/table/relation/newForeignKeyFilter.js +20 -0
  393. package/src/table/relation/newJoinLeg.js +23 -0
  394. package/src/table/relation/newManyCache.js +57 -0
  395. package/src/table/relation/newManyCacheCore.js +53 -0
  396. package/src/table/relation/newManyLeg.js +15 -0
  397. package/src/table/relation/newOneCache.js +28 -0
  398. package/src/table/relation/newOneLeg.js +25 -0
  399. package/src/table/releaseDbClient.js +15 -0
  400. package/src/table/resultToPromise.js +8 -0
  401. package/src/table/resultToRows/dbRowToRow.js +51 -0
  402. package/src/table/resultToRows/dbRowsToRows.js +13 -0
  403. package/src/table/resultToRows/decodeDbRow.js +25 -0
  404. package/src/table/resultToRows/delete/removeFromCache.js +33 -0
  405. package/src/table/resultToRows/delete.js +31 -0
  406. package/src/table/resultToRows/negotiateQueryContext.js +6 -0
  407. package/src/table/resultToRows/newDecodeDbRow.js +262 -0
  408. package/src/table/resultToRows/toDto/createDto.js +20 -0
  409. package/src/table/resultToRows/toDto/extractStrategy.js +41 -0
  410. package/src/table/resultToRows/toDto.js +92 -0
  411. package/src/table/resultToRows.js +37 -0
  412. package/src/table/rollback.js +31 -0
  413. package/src/table/rowArray/negotiateNextTick.js +11 -0
  414. package/src/table/rowArray/orderBy.js +51 -0
  415. package/src/table/rowArray.js +62 -0
  416. package/src/table/setSessionSingleton.js +5 -0
  417. package/src/table/strategyToSpan.js +49 -0
  418. package/src/table/tryGetById.js +13 -0
  419. package/src/table/tryGetFirstFromDb.js +23 -0
  420. package/src/table/tryGetFromCacheById.js +12 -0
  421. package/src/table/tryGetFromDbById/extractStrategy.js +9 -0
  422. package/src/table/tryGetFromDbById.js +19 -0
  423. package/src/table/tryGetSessionContext.js +16 -0
  424. package/src/table/tryReleaseDbClient.js +14 -0
  425. package/src/table/updateField.js +12 -0
  426. package/src/table/where.js +12 -0
  427. package/src/table.js +174 -0
  428. package/src/tedious/deleteFromSql.js +8 -0
  429. package/src/tedious/encodeBoolean.js +7 -0
  430. package/src/tedious/encodeBuffer.js +7 -0
  431. package/src/tedious/formatDateOut.js +5 -0
  432. package/src/tedious/formatJSONOut.js +5 -0
  433. package/src/tedious/getManyDto/newQuery.js +8 -0
  434. package/src/tedious/getManyDto/newQueryCore.js +18 -0
  435. package/src/tedious/getManyDto/query/newSingleQuery.js +29 -0
  436. package/src/tedious/getManyDto/query/newSubQueries/joinLegToQuery.js +16 -0
  437. package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +16 -0
  438. package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +19 -0
  439. package/src/tedious/getManyDto/query/newSubQueries.js +48 -0
  440. package/src/tedious/getManyDto/query/singleQuery/newShallowColumnSql.js +34 -0
  441. package/src/tedious/getManyDto.js +27 -0
  442. package/src/tedious/insert.js +13 -0
  443. package/src/tedious/insertSql.js +70 -0
  444. package/src/tedious/limitAndOffset.js +16 -0
  445. package/src/tedious/mergeSql.js +76 -0
  446. package/src/tedious/newDatabase.js +129 -0
  447. package/src/tedious/newPool.js +19 -0
  448. package/src/tedious/newTransaction.js +72 -0
  449. package/src/tedious/outputInsertedSql.js +11 -0
  450. package/src/tedious/pool/defaults.js +45 -0
  451. package/src/tedious/pool/end.js +13 -0
  452. package/src/tedious/pool/newGenericPool.js +71 -0
  453. package/src/tedious/pool/parseConnectionString.js +40 -0
  454. package/src/tedious/selectForUpdateSql.js +3 -0
  455. package/src/tedious/wrapQuery.js +112 -0
  456. package/src/toCompareObject.js +41 -0
  457. package/src/useHook.js +9 -0
  458. package/src/validateDeleteAllowed.js +49 -0
  459. package/src/validateDeleteConflict.js +92 -0
@@ -0,0 +1,7 @@
1
+ function negotiateEndEdit(changes) {
2
+ var last = changes[changes.length - 1];
3
+ if (last && last.endEdit)
4
+ last.endEdit();
5
+ }
6
+
7
+ module.exports = negotiateEndEdit;
@@ -0,0 +1,23 @@
1
+ var newSingleCommand = require('./delete/newSingleCommand');
2
+
3
+ var nextCommand = function() {
4
+ nextCommand = require('./newDeleteCommand');
5
+ nextCommand.apply(null, arguments);
6
+ };
7
+
8
+ function newCommand(queries,table,filter,strategy,relations) {
9
+ var singleCommand = newSingleCommand(table,filter,relations);
10
+ for(var name in strategy) {
11
+ if (!(strategy[name] === null || strategy[name]))
12
+ continue;
13
+ var childStrategy = strategy[name];
14
+ var childRelation = table._relations[name];
15
+ var joinRelation = childRelation.joinRelation;
16
+ var childRelations = [joinRelation].concat(relations);
17
+ nextCommand(queries,childRelation.childTable,filter,childStrategy,childRelations);
18
+ }
19
+ queries.push(singleCommand);
20
+ return queries;
21
+ }
22
+
23
+ module.exports = newCommand;
@@ -0,0 +1,49 @@
1
+ var newGetLastInsertedCommandCore = require('./newGetLastInsertedCommandCore');
2
+ var newImmutable = require('../../newImmutable');
3
+
4
+ function newGetLastInsertedCommand(table, row, insertCommand) {
5
+ let cmd = new InsertCommand(table, row, insertCommand);
6
+ insertCommand.endEdit = () => {};
7
+ return cmd;
8
+ }
9
+
10
+ function InsertCommand(table, row, insertCommand) {
11
+ this._insertCommand = insertCommand;
12
+ this.__getCoreCommand = newImmutable(newGetLastInsertedCommandCore);
13
+ this._table = table;
14
+ this._row = row;
15
+ }
16
+
17
+ InsertCommand.prototype._getCoreCommand = function() {
18
+ return this.__getCoreCommand(this._table, this._row);
19
+ };
20
+
21
+ InsertCommand.prototype.sql = function() {
22
+ return this._getCoreCommand().sql();
23
+ };
24
+
25
+ InsertCommand.prototype.matches = function(otherRow) {
26
+ return this._row === otherRow;
27
+ };
28
+
29
+
30
+ InsertCommand.prototype.endEdit = function() {
31
+ this._insertCommand.endEdit();
32
+ this.sql();
33
+ };
34
+
35
+ Object.defineProperty(InsertCommand.prototype, 'parameters', {
36
+ get: function() {
37
+ return this._getCoreCommand().parameters;
38
+
39
+ }
40
+ });
41
+
42
+ Object.defineProperty(InsertCommand.prototype, 'disallowCompress', {
43
+ get: function() {
44
+ return true;
45
+ }
46
+ });
47
+
48
+
49
+ module.exports = newGetLastInsertedCommand;
@@ -0,0 +1,42 @@
1
+ let newParameterized = require('../query/newParameterized');
2
+ let getSessionContext = require('../getSessionContext');
3
+
4
+ function newGetLastInsertedCommandCore(table, row) {
5
+ let parameters = [];
6
+ let keyValues = table._primaryColumns.map(column => row['__' + column.alias]);
7
+ let sql = `SELECT ${columnNames()} FROM ${table._dbName} WHERE ${whereSql()}`;
8
+ return newParameterized(sql, parameters);
9
+
10
+ function columnNames() {
11
+ return table._columns.map(col => col._dbName).join(',');
12
+ }
13
+
14
+ function whereSql() {
15
+ let parameterized;
16
+ let filter = getSessionContext().lastInsertedSql(table, keyValues);
17
+ if (Array.isArray(filter)) {
18
+ for (let i = 0; i < filter.length; i++) {
19
+ const sep = i === 0 ? '' : ' AND ';
20
+ if (!filter[i].sql) {
21
+ const sql = filter[i];
22
+ filter[i] = {sql : () => sql};
23
+ }
24
+ let next = newParameterized(sep + filter[i].sql(), filter[i].parameters);
25
+ if (parameterized)
26
+ parameterized = parameterized.append(next);
27
+ else
28
+ parameterized = next;
29
+ }
30
+ }
31
+ else
32
+ parameterized = newParameterized(filter);
33
+ parameters = parameters.concat(parameterized.parameters);
34
+ return [discriminators(), parameterized.sql()].filter(x => x).join(' AND ');
35
+ }
36
+
37
+ function discriminators() {
38
+ return table._columnDiscriminators.join(',');
39
+ }
40
+ }
41
+
42
+ module.exports = newGetLastInsertedCommandCore;
@@ -0,0 +1,55 @@
1
+ var newInsertCommandCore = require('./newInsertCommandCore');
2
+ var newImmutable = require('../../newImmutable');
3
+ var createPatch = require('../../client/createPatch');
4
+ var createDto = require('../resultToRows/toDto/createDto');
5
+
6
+ function newInsertCommand(table, row, options) {
7
+ return new InsertCommand(table, row, options);
8
+ }
9
+
10
+ function InsertCommand(table, row) {
11
+ this.__getCoreCommand = newImmutable(newInsertCommandCore);
12
+ this._table = table;
13
+ this._row = row;
14
+ }
15
+
16
+ InsertCommand.prototype._getCoreCommand = function() {
17
+ return this.__getCoreCommand(this._table, this._row);
18
+ };
19
+
20
+ InsertCommand.prototype.sql = function() {
21
+ return this._getCoreCommand().sql();
22
+ };
23
+
24
+ InsertCommand.prototype.matches = function(otherRow) {
25
+ return this._row === otherRow;
26
+ };
27
+
28
+
29
+ InsertCommand.prototype.endEdit = function() {
30
+ this.sql();
31
+ var dto = createDto(this._table, this._row);
32
+ if (this._table._emitChanged.callbacks.length > 0)
33
+ this._patch = createPatch([], [dto]);
34
+ };
35
+
36
+ InsertCommand.prototype.emitChanged = function() {
37
+ return this._table._emitChanged({row: this._row, patch: this._patch});
38
+ };
39
+
40
+ Object.defineProperty(InsertCommand.prototype, 'parameters', {
41
+ get: function() {
42
+ return this._getCoreCommand().parameters;
43
+
44
+ }
45
+ });
46
+
47
+ Object.defineProperty(InsertCommand.prototype, 'disallowCompress', {
48
+ get: function() {
49
+ return this._table._emitChanged.callbacks.length > 0;
50
+
51
+ }
52
+ });
53
+
54
+
55
+ module.exports = newInsertCommand;
@@ -0,0 +1,56 @@
1
+ // var newInsertCommandCore = require('./newInsertCommandCore');
2
+ var newImmutable = require('../../newImmutable');
3
+ var createPatch = require('../../client/createPatch');
4
+ var createDto = require('../resultToRows/toDto/createDto');
5
+
6
+ function newInsertCommand(newInsertCommandCore, table, row, options) {
7
+ return new InsertCommand(newInsertCommandCore, table, row, options);
8
+ }
9
+
10
+ function InsertCommand(newInsertCommandCore, table, row, options) {
11
+ this.__getCoreCommand = newImmutable(newInsertCommandCore);
12
+ this._table = table;
13
+ this._row = row;
14
+ this._options = options;
15
+ }
16
+
17
+ InsertCommand.prototype._getCoreCommand = function() {
18
+ return this.__getCoreCommand(this._table, this._row, this._options);
19
+ };
20
+
21
+ InsertCommand.prototype.sql = function() {
22
+ return this._getCoreCommand().sql();
23
+ };
24
+
25
+ InsertCommand.prototype.matches = function(otherRow) {
26
+ return this._row === otherRow;
27
+ };
28
+
29
+
30
+ InsertCommand.prototype.endEdit = function() {
31
+ this.sql();
32
+ var dto = createDto(this._table, this._row);
33
+ if (this._table._emitChanged.callbacks.length > 0)
34
+ this._patch = createPatch([], [dto]);
35
+ };
36
+
37
+ InsertCommand.prototype.emitChanged = function() {
38
+ return this._table._emitChanged({row: this._row, patch: this._patch});
39
+ };
40
+
41
+ Object.defineProperty(InsertCommand.prototype, 'parameters', {
42
+ get: function() {
43
+ return this._getCoreCommand().parameters;
44
+
45
+ }
46
+ });
47
+
48
+ Object.defineProperty(InsertCommand.prototype, 'disallowCompress', {
49
+ get: function() {
50
+ return this._table._emitChanged.callbacks.length > 0;
51
+
52
+ }
53
+ });
54
+
55
+
56
+ module.exports = newInsertCommand;
@@ -0,0 +1,27 @@
1
+ var newParameterized = require('../query/newParameterized');
2
+ var getSqlTemplate = require('./insert/getSqlTemplate');
3
+ var util = require('util');
4
+
5
+ function newInsertCommandCore(table, row, options = {}) {
6
+ var parameters = [];
7
+ var values = [getSqlTemplate(table, row, options)];
8
+
9
+ var columns = table._columns;
10
+ for (var i = 0; i < columns.length; i++) {
11
+ var column = columns[i];
12
+ var alias = column.alias;
13
+ if (row['__' + column.alias] !== undefined) {
14
+ var encoded = column.encode(row[alias]);
15
+ if (encoded.parameters.length > 0) {
16
+ values.push('?');
17
+ parameters.push(encoded.parameters[0]);
18
+ } else
19
+ values.push(encoded.sql());
20
+ }
21
+ }
22
+
23
+ var sql = util.format.apply(null, values);
24
+ return newParameterized(sql, parameters);
25
+ }
26
+
27
+ module.exports = newInsertCommandCore;
@@ -0,0 +1,51 @@
1
+ var decodeDbRow = require('../resultToRows/decodeDbRow');
2
+ var flags = require('../../flags');
3
+
4
+ function newRow({table, _options}) {
5
+ var dto = {};
6
+ table._columns.forEach(addColumn);
7
+
8
+ function addColumn(column) {
9
+ var alias = column.alias;
10
+ if ('default' in column) {
11
+ if (typeof column.default === 'function')
12
+ dto[alias] = column.default();
13
+ else if (column.toDto)
14
+ dto[alias] = column.toDto(column.default);
15
+ else
16
+ dto[alias] = column.default;
17
+ }
18
+ else if (flags.useLazyDefaults && 'lazyDefault' in column && !column.isPrimary) {
19
+ if (typeof column.lazyDefault === 'function')
20
+ dto[alias] = column.lazyDefault();
21
+ else if (column.toDto)
22
+ dto[alias] = column.toDto(column.lazyDefault);
23
+ else
24
+ dto[alias] = column.lazyDefault;
25
+ }
26
+ else if (column.dbNull !== null)
27
+ dto[alias] = null;
28
+ else
29
+ dto[alias] = undefined;
30
+ }
31
+ const arg = arguments[1];
32
+ if (isObject(arg))
33
+ for (let name in arg) {
34
+ if (table[name] && table[name].equal)
35
+ dto[name] = arg[name];
36
+ }
37
+ else
38
+ for (var i = 1; i < arguments.length; i++) {
39
+ var pkValue = arguments[i];
40
+ var column = table._primaryColumns[i - 1];
41
+ dto[column.alias] = pkValue;
42
+ }
43
+
44
+ return decodeDbRow(table, table, dto, true, true);
45
+ }
46
+
47
+ function isObject(object) {
48
+ return (object === Object(object) && !Array.isArray(object) && !(object instanceof Date));
49
+ }
50
+
51
+ module.exports = newRow;
@@ -0,0 +1,62 @@
1
+ let newUpdateCommandCore = require('./newUpdateCommandCore');
2
+ let newImmutable = require('../../newImmutable');
3
+ let newColumnList = require('../../newObject');
4
+ var createPatch = require('../../client/createPatch');
5
+ let createDto = require('../resultToRows/toDto/createDto');
6
+
7
+ function newUpdateCommand(table, column, row) {
8
+ return new UpdateCommand(table, column, row);
9
+ }
10
+
11
+ function UpdateCommand(table, column, row) {
12
+ this._table = table;
13
+ this._row = row;
14
+ this.__getCoreCommand = newImmutable(newUpdateCommandCore);
15
+ this._columnList = newColumnList();
16
+ this._columnList[column.alias] = column;
17
+ this.onFieldChanged = this.onFieldChanged.bind(this);
18
+ row.subscribeChanged(this.onFieldChanged);
19
+ }
20
+
21
+ UpdateCommand.prototype.onFieldChanged = function(_row, column) {
22
+ this._columnList[column.alias] = column;
23
+ };
24
+
25
+ UpdateCommand.prototype.sql = function() {
26
+ return this._getCoreCommand().sql();
27
+ };
28
+
29
+ Object.defineProperty(UpdateCommand.prototype, 'parameters', {
30
+ get: function() {
31
+ return this._getCoreCommand().parameters;
32
+ }
33
+ });
34
+
35
+ UpdateCommand.prototype._getCoreCommand = function() {
36
+ return this.__getCoreCommand(this._table, this._columnList, this._row);
37
+ };
38
+
39
+ UpdateCommand.prototype.endEdit = function() {
40
+ this._getCoreCommand();
41
+ this._row.unsubscribeChanged(this.onFieldChanged);
42
+ let dto = JSON.parse(JSON.stringify(createDto(this._table, this._row)));
43
+ this._patch = createPatch([JSON.parse(this._row._oldValues)],[dto]);
44
+ this._row._oldValues = JSON.stringify(dto);
45
+ };
46
+
47
+ UpdateCommand.prototype.emitChanged = function() {
48
+ return this._table._emitChanged({row: this._row, patch: this._patch});
49
+ };
50
+
51
+ UpdateCommand.prototype.matches = function(otherRow) {
52
+ return this._row === otherRow;
53
+ };
54
+
55
+ Object.defineProperty(UpdateCommand.prototype, 'disallowCompress', {
56
+ get: function() {
57
+ return this._table._emitChanged.callbacks.length > 0;
58
+
59
+ }
60
+ });
61
+
62
+ module.exports = newUpdateCommand;
@@ -0,0 +1,45 @@
1
+ var newParameterized = require('../query/newParameterized');
2
+
3
+ function newUpdateCommandCore(table, columns, row) {
4
+ var command = newParameterized('UPDATE ' + table._dbName + ' SET');
5
+ var separator = ' ';
6
+
7
+ addColumns();
8
+ addWhereId();
9
+ addDiscriminators();
10
+
11
+ function addColumns() {
12
+ for (var alias in columns) {
13
+ var column = columns[alias];
14
+ var encoded = column.encode(row[alias]);
15
+ command = command.append(separator + column._dbName + '=').append(encoded);
16
+ separator = ',';
17
+ }
18
+ }
19
+
20
+ function addWhereId() {
21
+ separator = ' WHERE ';
22
+ var columns = table._primaryColumns;
23
+ for (var i = 0; i < columns.length; i++) {
24
+ var column = columns[i];
25
+ var value = row[column.alias];
26
+ var encoded = column.encode(value);
27
+ command = command.append(separator + column._dbName + '=').append(encoded);
28
+ separator = ' AND ';
29
+ }
30
+ }
31
+
32
+ function addDiscriminators() {
33
+ var discriminators = table._columnDiscriminators;
34
+ if (discriminators.length === 0)
35
+ return;
36
+ discriminators = separator + discriminators.join(' AND ');
37
+ command = command.append(discriminators);
38
+ }
39
+
40
+ return command;
41
+
42
+
43
+ }
44
+
45
+ module.exports = newUpdateCommandCore;
@@ -0,0 +1,10 @@
1
+ var getChangeSet = require('./getChangeSet');
2
+ var negotiateEndEdit = require('./negotiateEndEdit');
3
+
4
+ function pushCommand(command) {
5
+ var changes = getChangeSet();
6
+ negotiateEndEdit(changes);
7
+ changes.push(command);
8
+ }
9
+
10
+ module.exports = pushCommand;
@@ -0,0 +1,13 @@
1
+ var newParameterized = require('../query/newParameterized');
2
+
3
+ var command = newParameterized('ROLLBACK');
4
+ function empty() {}
5
+
6
+ // @ts-ignore
7
+ command.endEdit = empty;
8
+ // @ts-ignore
9
+ command.matches = empty;
10
+
11
+ module.exports = command;
12
+
13
+
@@ -0,0 +1,30 @@
1
+ let commitCommand = require('./commands/commitCommand');
2
+ let pushCommand = require('./commands/pushCommand');
3
+ let executeChanges = require('./executeQueries/executeChanges');
4
+ let releaseDbClient = require('./releaseDbClient');
5
+ let popChanges = require('./popChanges');
6
+
7
+ function commit(result) {
8
+ return popAndPushChanges()
9
+ .then(releaseDbClient)
10
+ .then(onReleased);
11
+
12
+ function onReleased() {
13
+ return result;
14
+ }
15
+
16
+ async function popAndPushChanges() {
17
+ let changes = popChanges();
18
+ while (changes.length > 0) {
19
+ await executeChanges(changes);
20
+ changes = popChanges();
21
+ }
22
+ pushCommand(commitCommand);
23
+ return executeChanges(popChanges());
24
+ }
25
+ }
26
+
27
+ module.exports = function(result) {
28
+ return Promise.resolve()
29
+ .then(() => commit(result));
30
+ };
@@ -0,0 +1,29 @@
1
+ const executeQueries = require('./executeQueries');
2
+ const negotiateRawSqlFilter = require('./column/negotiateRawSqlFilter');
3
+ const extractFilter = require('./query/extractFilter');
4
+ const newWhereSql = require('./query/singleQuery/newWhereSql');
5
+
6
+ async function count(table, filter) {
7
+ let alias = table._dbName;
8
+ filter = negotiateRawSqlFilter(filter, table);
9
+ let query = newQuery(table, filter, alias);
10
+ let allResults = await executeQueries([query]);
11
+ let count = await allResults[0].then((rows) => {
12
+
13
+ const count = Number.parseInt(rows[0]._count);
14
+ return count;
15
+ });
16
+ return count;
17
+ }
18
+
19
+ function newQuery(table, filter, alias) {
20
+ filter = extractFilter(filter);
21
+ var name = table._dbName;
22
+ var whereSql = newWhereSql(table, filter, alias);
23
+
24
+ return whereSql.prepend('select count(*) "_count" from ' + name + ' ' + alias);
25
+
26
+
27
+ }
28
+
29
+ module.exports = count;
@@ -0,0 +1,7 @@
1
+ var createJSONReadStreamDefault = require('./createJSONReadStreamDefault');
2
+
3
+ function createJSONReadStream(table, db, filter, strategy, streamOptions) {
4
+ return createJSONReadStreamDefault(table, db, filter, strategy, streamOptions);
5
+ }
6
+
7
+ module.exports = createJSONReadStream;
@@ -0,0 +1,33 @@
1
+ var createReadStreamCore = require('./createReadStreamDefault');
2
+ var Stream = require('stream');
3
+
4
+ function createJSONReadStream(table, db, filter, strategy, streamOptions) {
5
+ var transformer = Stream.Transform({ objectMode: true });
6
+ var started;
7
+ transformer._transform = function(obj, enc, cb) {
8
+ var data = JSON.stringify(obj);
9
+ if (started)
10
+ transformer.push(',' + data);
11
+ else {
12
+ transformer.push('[');
13
+ transformer.push(data);
14
+ started = true;
15
+ }
16
+ cb();
17
+ };
18
+
19
+ transformer._flush = function(cb) {
20
+ transformer.push(']');
21
+ cb();
22
+ };
23
+
24
+ var objectStream = createReadStreamCore(table, db, filter, strategy, streamOptions);
25
+ objectStream.on('error', onError);
26
+ return objectStream.pipe(transformer);
27
+
28
+ function onError(e) {
29
+ transformer.emit('error', e);
30
+ }
31
+ }
32
+
33
+ module.exports = createJSONReadStream;
@@ -0,0 +1,31 @@
1
+ var createReadStreamCore = require('./createReadStreamCoreNative');
2
+ var Stream = require('stream');
3
+
4
+ function createJSONReadStream(table, db, filter, strategy, streamOptions) {
5
+ var transformer = Stream.Transform({
6
+ objectMode: true
7
+ });
8
+ var started;
9
+ transformer._transform = function(chunk, enc, cb) {
10
+ if (started)
11
+ transformer.push(',' + chunk.result);
12
+ else {
13
+ transformer.push('[');
14
+ let result = chunk.result;
15
+ if (typeof result === 'object')
16
+ result = JSON.stringify(result);
17
+ transformer.push(result);
18
+ started = true;
19
+ }
20
+ cb();
21
+ };
22
+
23
+ transformer._flush = function(cb) {
24
+ transformer.push(']');
25
+ cb();
26
+ };
27
+
28
+ return createReadStreamCore(table, db, filter, strategy, transformer, streamOptions);
29
+ }
30
+
31
+ module.exports = createJSONReadStream;
@@ -0,0 +1,24 @@
1
+ var createReadStreamNative = require('./createReadStreamNative');
2
+ var createReadStreamDefault = require('./createReadStreamDefault');
3
+
4
+ function createReadStream(table, db, filter, strategy, streamOptions) {
5
+ var create;
6
+ var c = {};
7
+
8
+ c.visitPg = function() {
9
+ create = createReadStreamNative;
10
+ };
11
+
12
+ c.visitMySql = c.visitPg;
13
+
14
+ c.visitSqlite = function() {
15
+ create = createReadStreamDefault;
16
+ };
17
+ c.visitSap = c.visitSqlite;
18
+
19
+ db.accept(c);
20
+
21
+ return create(table, db, filter, strategy, streamOptions);
22
+ }
23
+
24
+ module.exports = createReadStream;
@@ -0,0 +1,40 @@
1
+ var newQuery = require('./readStream/newQuery');
2
+ var strategyToSpan = require('./strategyToSpan');
3
+ var negotiateRawSqlFilter = require('./column/negotiateRawSqlFilter');
4
+ var newQueryStream = require('./readStream/newQueryStream');
5
+
6
+ function createReadStreamCoreNative(table, db, filter, strategy, transformer, streamOptions) {
7
+ var alias = table._dbName;
8
+ filter = negotiateRawSqlFilter(filter, table);
9
+ var span = strategyToSpan(table, strategy);
10
+
11
+ if (process.domain)
12
+ process.domain.add(transformer);
13
+
14
+ db.transaction(async () => {
15
+ await start();
16
+ }).then(null, onError);
17
+
18
+ function start() {
19
+ return new Promise((resolve, reject) => {
20
+ var query = newQuery(db, table, filter, span, alias);
21
+ var queryStream = newQueryStream(query, streamOptions);
22
+ queryStream.on('end', resolve);
23
+ queryStream.on('error', onStreamError);
24
+ queryStream.pipe(transformer);
25
+
26
+ function onStreamError(e) {
27
+ reject(e);
28
+ }
29
+ });
30
+
31
+ }
32
+
33
+ function onError(e) {
34
+ transformer.emit('error', e);
35
+ }
36
+
37
+ return transformer;
38
+ }
39
+
40
+ module.exports = createReadStreamCoreNative;