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,27 @@
1
+ var newParameterized = require('../table/query/newParameterized');
2
+ var insertSql = require('./insertSql');
3
+ var util = require('util');
4
+
5
+ function newInsertCommandCore(table, row, options = {}) {
6
+ var parameters = [];
7
+ var values = [insertSql(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,19 @@
1
+ var pools = require('../pools');
2
+ var promise = require('../table/promise');
3
+ var end = require('./pool/end');
4
+ var newGenericPool = require('./pool/newGenericPool');
5
+ var newId = require('../newId');
6
+
7
+ function newPool(connectionString, poolOptions) {
8
+ var pool = newGenericPool(connectionString, poolOptions);
9
+ var id = newId();
10
+ var boundEnd = end.bind(null, pool, id);
11
+ var c = {};
12
+
13
+ c.connect = pool.connect;
14
+ c.end = promise.denodeify(boundEnd);
15
+ pools[id] = c;
16
+ return c;
17
+ }
18
+
19
+ module.exports = newPool;
@@ -0,0 +1,63 @@
1
+ const wrapQuery = require('./wrapQuery');
2
+ const encodeBoolean = require('./encodeBoolean');
3
+ const deleteFromSql = require('./deleteFromSql');
4
+ const selectForUpdateSql = require('./selectForUpdateSql');
5
+ const lastInsertedSql = require('./lastInsertedSql');
6
+ const limitAndOffset = require('./limitAndOffset');
7
+ const insertSql = require('./insertSql');
8
+ const insert = require('./insert');
9
+ const formatDateOut = require('./formatDateOut');
10
+ const formatDateIn = require('./formatDateIn');
11
+
12
+ function newResolveTransaction(domain, pool) {
13
+ var rdb = {poolFactory: pool};
14
+ if (!pool.connect) {
15
+ pool = pool();
16
+ rdb.pool = pool;
17
+ }
18
+
19
+ return function(onSuccess, onError) {
20
+ pool.connect(onConnected);
21
+
22
+ function onConnected(err, client, done) {
23
+ try {
24
+ if (err) {
25
+ onError(err);
26
+ return;
27
+ }
28
+ client.executeQuery = wrapQuery(client);
29
+ rdb.begin = 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED';
30
+ rdb.engine = 'oracle';
31
+ rdb.dbClient = client;
32
+ rdb.dbClientDone = done;
33
+ rdb.encodeBoolean = encodeBoolean;
34
+ rdb.decodeJSON = decodeJSON;
35
+ rdb.encodeJSON = JSON.stringify;
36
+ rdb.formatDateOut = formatDateOut;
37
+ rdb.formatDateIn = formatDateIn;
38
+ rdb.deleteFromSql = deleteFromSql;
39
+ rdb.selectForUpdateSql = selectForUpdateSql;
40
+ rdb.lastInsertedSql = lastInsertedSql;
41
+ rdb.insertSql = insertSql;
42
+ rdb.insert = insert;
43
+ rdb.lastInsertedIsSeparate = true;
44
+ rdb.multipleStatements = false;
45
+ rdb.limitAndOffset = limitAndOffset;
46
+ rdb.accept = function(caller) {
47
+ caller.visitSqlite();
48
+ };
49
+ rdb.aggregateCount = 0;
50
+ domain.rdb = rdb;
51
+ onSuccess();
52
+ } catch (e) {
53
+ onError(e);
54
+ }
55
+ }
56
+ };
57
+ }
58
+
59
+ function decodeJSON(value) {
60
+ return JSON.parse(value);
61
+ }
62
+
63
+ module.exports = newResolveTransaction;
@@ -0,0 +1,5 @@
1
+ function outputInsertedSql(_table) {
2
+ return '';
3
+ }
4
+
5
+ module.exports = outputInsertedSql;
@@ -0,0 +1,45 @@
1
+ module.exports = {
2
+ // database host defaults to localhost
3
+ host: 'localhost',
4
+
5
+ //database user's name
6
+ user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
7
+
8
+ //name of database to connect
9
+ database: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
10
+
11
+ //database user's password
12
+ password: null,
13
+
14
+ //database port
15
+ port: 5432,
16
+
17
+ //number of rows to return at a time from a prepared statement's
18
+ //portal. 0 will return all rows at once
19
+ rows: 0,
20
+
21
+ // binary result mode
22
+ binary: false,
23
+
24
+ //Connection pool options - see https://github.com/coopernurse/node-pool
25
+ //number of connections to use in connection pool
26
+ //0 will disable connection pooling
27
+ poolSize: 0,
28
+
29
+ //max milliseconds a client can go unused before it is removed
30
+ //from the pool and destroyed
31
+ poolIdleTimeout: 30000,
32
+
33
+ //frequeny to check for idle clients within the client pool
34
+ reapIntervalMillis: 1000,
35
+
36
+ //pool log function / boolean
37
+ poolLog: false,
38
+
39
+ client_encoding: '',
40
+
41
+ ssl: false,
42
+
43
+ application_name : undefined,
44
+ fallback_application_name: undefined
45
+ };
@@ -0,0 +1,13 @@
1
+ var pools = require('../../pools');
2
+
3
+ function endPool(genericPool, id, done) {
4
+ genericPool.drain(onDrained);
5
+
6
+ function onDrained() {
7
+ genericPool.destroyAllNow();
8
+ delete pools[id];
9
+ done();
10
+ }
11
+ }
12
+
13
+ module.exports = endPool;
@@ -0,0 +1,64 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable no-prototype-builtins */
3
+ var EventEmitter = require('events').EventEmitter;
4
+
5
+ var defaults = require('./defaults');
6
+ var genericPool = require('../../generic-pool');
7
+ var oracle = require('oracledb');
8
+
9
+ oracle.outFormat = oracle.OUT_FORMAT_OBJECT;
10
+ oracle.fetchAsBuffer = [ oracle.BLOB ];
11
+
12
+ function newGenericPool(connectionString, poolOptions) {
13
+ poolOptions = poolOptions || {};
14
+ var pool = genericPool.Pool({
15
+ max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
16
+ idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
17
+ reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
18
+ log: poolOptions.log || defaults.poolLog,
19
+ create: function(cb) {
20
+ var client;
21
+ oracle.getConnection(connectionString, onConnected);
22
+ function onConnected(err, _client) {
23
+ client = _client;
24
+ if (err)
25
+ return cb(err, null);
26
+ client.poolCount = 0;
27
+ return cb(null, client);
28
+ }
29
+ },
30
+
31
+ destroy: function(client) {
32
+ client.poolCount = undefined;
33
+ client.close();
34
+ }
35
+ });
36
+ //mixin EventEmitter to pool
37
+ EventEmitter.call(pool);
38
+ for (var key in EventEmitter.prototype) {
39
+ if (EventEmitter.prototype.hasOwnProperty(key)) {
40
+ pool[key] = EventEmitter.prototype[key];
41
+ }
42
+ }
43
+ //monkey-patch with connect method
44
+ pool.connect = function(cb) {
45
+ var domain = process.domain;
46
+ pool.acquire(function(err, client) {
47
+ if (domain) {
48
+ cb = domain.bind(cb);
49
+ }
50
+ if (err) return cb(err, null, function() {/*NOOP*/ });
51
+ client.poolCount++;
52
+ cb(null, client, function(err) {
53
+ if (err) {
54
+ pool.destroy(client);
55
+ } else {
56
+ pool.release(client);
57
+ }
58
+ });
59
+ });
60
+ };
61
+ return pool;
62
+ }
63
+
64
+ module.exports = newGenericPool;
@@ -0,0 +1,14 @@
1
+ function replaceParamChar(query, params) {
2
+ if (params.length === 0)
3
+ return query.sql();
4
+ var splitted = query.sql().split('?');
5
+ var sql = '';
6
+ var lastIndex = splitted.length - 1;
7
+ for (var i = 0; i < lastIndex; i++) {
8
+ sql += splitted[i] + ':p' + (i + 1);
9
+ }
10
+ sql += splitted[lastIndex];
11
+ return sql;
12
+ }
13
+
14
+ module.exports = replaceParamChar;
@@ -0,0 +1,3 @@
1
+ module.exports = function(alias) {
2
+ return ' FOR UPDATE OF ' + alias;
3
+ };
@@ -0,0 +1,38 @@
1
+ var log = require('../table/log');
2
+ var replaceParamChar = require('./replaceParamChar');
3
+
4
+ function wrapQuery(connection) {
5
+ var runOriginalQuery = connection.execute;
6
+ return runQuery;
7
+
8
+ function runQuery(query, onCompleted) {
9
+ var params = query.parameters;
10
+ var sql = replaceParamChar(query, params);
11
+ log.emitQuery({ sql, parameters: params });
12
+
13
+
14
+
15
+
16
+ runOriginalQuery.call(connection, sql, params, {
17
+ fetchTypeHandler: function(metaData) {
18
+ // Tells the database to return column names in lowercase
19
+ metaData.name = metaData.name.toLowerCase();
20
+ }
21
+ }, onInnerCompleted);
22
+
23
+ function onInnerCompleted(err, rows) {
24
+ if (err)
25
+ onCompleted(err);
26
+ else {
27
+ if (rows.rows)
28
+ rows = rows.rows;
29
+ else
30
+ rows = [rows];
31
+ onCompleted(null, rows);
32
+ }
33
+ }
34
+ }
35
+
36
+ }
37
+
38
+ module.exports = wrapQuery;
@@ -0,0 +1,13 @@
1
+ let patchTable = require('./patchTable');
2
+
3
+ function patchRow(table, row, patches, options) {
4
+ patches = JSON.parse(JSON.stringify(patches));
5
+ let pkName = table._primaryColumns[0].alias;
6
+ let id = row[pkName];
7
+ for (let i = 0; i < patches.length; i++) {
8
+ patches[i].path = '/' + id + patches[i].path;
9
+ }
10
+ return patchTable(table, patches, options);
11
+ }
12
+
13
+ module.exports = patchRow;
@@ -0,0 +1,317 @@
1
+ /* eslint-disable require-atomic-updates */
2
+ let applyPatch = require('./applyPatch');
3
+ let fromCompareObject = require('./fromCompareObject');
4
+ let validateDeleteConflict = require('./validateDeleteConflict');
5
+ let validateDeleteAllowed = require('./validateDeleteAllowed');
6
+
7
+ async function patchTable() {
8
+ // const dryrun = true;
9
+ //traverse all rows you want to update before updatinng or inserting anything.
10
+ //this is to avoid page locks in ms sql
11
+ // await patchTableCore.apply(null, [...arguments, dryrun]);
12
+ return patchTableCore.apply(null, arguments);
13
+ }
14
+
15
+ async function patchTableCore(table, patches, { strategy = undefined, deduceStrategy = false, ...options } = {}, dryrun) {
16
+ options = cleanOptions(options);
17
+ strategy = JSON.parse(JSON.stringify(strategy || {}));
18
+ let changed = new Set();
19
+ for (let i = 0; i < patches.length; i++) {
20
+ let patch = { path: undefined, value: undefined, op: undefined };
21
+ Object.assign(patch, patches[i]);
22
+ patch.path = patches[i].path.split('/').slice(1);
23
+ let result;
24
+ if (patch.op === 'add' || patch.op === 'replace') {
25
+ result = await add({ path: patch.path, value: patch.value, op: patch.op, oldValue: patch.oldValue, strategy: deduceStrategy ? strategy : {}, options }, table);
26
+ }
27
+ else if (patch.op === 'remove')
28
+ result = await remove({ path: patch.path, op: patch.op, oldValue: patch.oldValue, options }, table);
29
+
30
+ if (result.inserted)
31
+ changed.add(result.inserted);
32
+ else if (result.updated)
33
+ changed.add(result.updated);
34
+ }
35
+ if (strategy['insertAndForget'])
36
+ return {
37
+ changed: [], strategy
38
+ };
39
+ return { changed: await toDtos(changed), strategy };
40
+
41
+
42
+ async function toDtos(set) {
43
+ set = [...set];
44
+ return table.getManyDto(set, strategy);
45
+ }
46
+
47
+ function toKey(property) {
48
+ if (typeof property === 'string' && property.charAt(0) === '[')
49
+ return JSON.parse(property);
50
+ else
51
+ return [property];
52
+ }
53
+
54
+ async function add({ path, value, op, oldValue, strategy, options }, table, row, parentRow, relation) {
55
+ let property = path[0];
56
+ path = path.slice(1);
57
+ if (!row && path.length > 0) {
58
+ const key = toKey(property);
59
+ row = await table.tryGetById.apply(null, toKey(property), strategy);
60
+ if (!row)
61
+ throw new Error(`Row ${table._dbName} with id ${key} was not found.`);
62
+ }
63
+
64
+ if (path.length === 0 && value === null) {
65
+ return remove({ path, op, oldValue, options }, table, row);
66
+ }
67
+ if (path.length === 0) {
68
+ if (dryrun) {
69
+ return {};
70
+ }
71
+ let childInserts = [];
72
+ for (let name in value) {
73
+ if (isColumn(name, table))
74
+ value[name] = fromCompareObject(value[name]);
75
+ else if (isJoinRelation(name, table)) {
76
+ strategy[name] = strategy[name] || {};
77
+ value[name] && updateJoinedColumns(name, value, table, value);
78
+ }
79
+ else if (isManyRelation(name, table))
80
+ value[name] && childInserts.push(insertManyRelation.bind(null, name, value, op, oldValue, table, strategy, options));
81
+ else if (isOneRelation(name, table) && value)
82
+ value[name] && childInserts.push(insertOneRelation.bind(null, name, value, op, oldValue, table, strategy, options));
83
+ }
84
+ for (let i = 0; i < table._primaryColumns.length; i++) {
85
+ let pkName = table._primaryColumns[i].alias;
86
+ let keyValue = value[pkName];
87
+ if (keyValue && typeof (keyValue) === 'string' && keyValue.indexOf('~') === 0)
88
+ value[pkName] = undefined;
89
+ }
90
+
91
+ if (relation && relation.joinRelation) {
92
+ for (let i = 0; i < relation.joinRelation.columns.length; i++) {
93
+ let column = relation.joinRelation.columns[i];
94
+ let fkName = column.alias;
95
+ let parentPk = relation.joinRelation.childTable._primaryColumns[i].alias;
96
+ if (!value[fkName]) {
97
+ value[fkName] = parentRow[parentPk];
98
+ }
99
+ }
100
+ }
101
+ let row = table.insertWithConcurrency.apply(null, [options, value]);
102
+ row = await row;
103
+
104
+ for (let i = 0; i < childInserts.length; i++) {
105
+ await childInserts[i](row);
106
+ }
107
+ return { inserted: row };
108
+ }
109
+ property = path[0];
110
+ if (isColumn(property, table)) {
111
+ if (dryrun)
112
+ return { updated: row };
113
+ let dto = {};
114
+ dto[property] = row[property];
115
+ let result = applyPatch({ options }, dto, [{ path: '/' + path.join('/'), op, value, oldValue }], table[property]);
116
+ row[property] = result[property];
117
+ return { updated: row };
118
+ }
119
+ else if (isOneRelation(property, table)) {
120
+ let relation = table[property]._relation;
121
+ let subRow = await row[property];
122
+ strategy[property] = strategy[property] || {};
123
+ options[property] = inferOptions(options, property);
124
+
125
+ await add({ path, value, op, oldValue, strategy: strategy[property], options: options[property] }, relation.childTable, subRow, row, relation);
126
+ return { updated: row };
127
+ }
128
+ else if (isManyRelation(property, table)) {
129
+ let relation = table[property]._relation;
130
+ strategy[property] = strategy[property] || {};
131
+ options[property] = inferOptions(options, property);
132
+
133
+
134
+ if (path.length === 1) {
135
+ for (let id in value) {
136
+ if (id === '__patchType')
137
+ continue;
138
+ await add({ path: [id], value: value[id], op, oldValue, strategy: strategy[property], options: options[property] }, relation.childTable, undefined, row, relation);
139
+ }
140
+ }
141
+ else {
142
+ await add({ path: path.slice(1), value, oldValue, op, strategy: strategy[property], options: options[property] }, relation.childTable, undefined, row, relation);
143
+ }
144
+ return { updated: row };
145
+ }
146
+ else if (isJoinRelation(property, table) && path.length === 1) {
147
+ let dto = toJoinedColumns(property, { [property]: value }, table);
148
+ oldValue = toJoinedColumns(property, { [property]: oldValue }, table);
149
+ let result;
150
+ for (let p in dto) {
151
+ result = await add({ path: ['dummy', p], value: dto[p], oldValue: (oldValue || {})[p], op, strategy: strategy, options: options }, table, row, parentRow, relation) || result;
152
+ }
153
+ return result || {};
154
+ }
155
+ else if (isJoinRelation(property, table) && path.length === 2) {
156
+ let dto = toJoinedColumns(property, { [property]: { [path[1]]: value } }, table);
157
+ oldValue = toJoinedColumns(property, { [property]: { [path[1]]: oldValue } }, table);
158
+ let result;
159
+ for (let p in dto) {
160
+ result = await add({ path: ['dummy', p], value: dto[p], oldValue: (oldValue || {})[p], op, strategy: strategy, options: options }, table, row, parentRow, relation) || result;
161
+ }
162
+ return result || {};
163
+ }
164
+ return {};
165
+ }
166
+
167
+ async function insertManyRelation(name, value, op, oldValue, table, strategy, options, row) {
168
+ let relation = table[name]._relation;
169
+ for (let childKey in value[name]) {
170
+ if (childKey != '__patchType') {
171
+ let child = value[name][childKey];
172
+ strategy[name] = strategy[name] || {};
173
+ options[name] = inferOptions(options, name);
174
+
175
+ await add({ path: [childKey], value: child, op, oldValue, strategy: strategy[name], options: options[name] }, relation.childTable, {}, row, relation);
176
+ }
177
+ }
178
+ }
179
+
180
+ async function insertOneRelation(name, value, op, oldValue, table, strategy, options, row) {
181
+ let relation = table[name]._relation;
182
+ let child = value[name];
183
+ strategy[name] = strategy[name] || {};
184
+ options[name] = inferOptions(options, name);
185
+
186
+ await add({ path: [name], value: child, op, oldValue, strategy: strategy[name], options: options[name] }, relation.childTable, {}, row, relation);
187
+ }
188
+
189
+ function updateJoinedColumns(name, value, table, row) {
190
+ let relation = table[name]._relation;
191
+ for (let i = 0; i < relation.columns.length; i++) {
192
+ let parentKey = relation.columns[i].alias;
193
+ let childKey = relation.childTable._primaryColumns[i].alias;
194
+ if (childKey in value[name])
195
+ row[parentKey] = fromCompareObject(value[name][childKey]);
196
+ }
197
+ }
198
+ function toJoinedColumns(name, valueObject, table) {
199
+ let relation = table[name]._relation;
200
+ let dto = {};
201
+ for (let i = 0; i < relation.columns.length; i++) {
202
+ let parentKey = relation.columns[i].alias;
203
+ let childKey = relation.childTable._primaryColumns[i].alias;
204
+ if (valueObject && valueObject[name] && childKey in valueObject[name])
205
+ dto[parentKey] = fromCompareObject(valueObject[name][childKey]);
206
+ else
207
+ dto[parentKey] = null;
208
+ }
209
+ return dto;
210
+ }
211
+
212
+ async function remove({ path, op, oldValue, options }, table, row) {
213
+ let property = path[0];
214
+ path = path.slice(1);
215
+ row = row || await table.getById.apply(null, toKey(property));
216
+ if (path.length === 0) {
217
+ await validateDeleteAllowed({ row, options, table });
218
+ if (await validateDeleteConflict({ row, oldValue, options, table }))
219
+ await row.deleteCascade();
220
+ }
221
+ property = path[0];
222
+ if (isColumn(property, table)) {
223
+ let dto = {};
224
+ dto[property] = row[property];
225
+ let result = applyPatch({ options }, dto, [{ path: '/' + path.join('/'), op, oldValue }], table[property]);
226
+
227
+ row[property] = result[property];
228
+ return { updated: row };
229
+ }
230
+ else if (isJoinRelation(property, table) && path.length === 1) {
231
+ oldValue = toJoinedColumns(property, { [property]: oldValue }, table);
232
+ let relation = table[property]._relation;
233
+ let result;
234
+ for (let i = 0; i < relation.columns.length; i++) {
235
+ let p = relation.columns[i].alias;
236
+ let dto = {};
237
+ dto[p] = row[p];
238
+ result = await remove({ path: ['dummy', p], oldValue: (oldValue || {})[p], op, options: options }, table, row) || result;
239
+ }
240
+ return result || {};
241
+ }
242
+ else if (isJoinRelation(property, table) && path.length === 2) {
243
+ let relation = table[property]._relation;
244
+ oldValue = toJoinedColumns(property, { [property]: { [path[1]]: oldValue } }, table);
245
+ let result;
246
+ for (let i = 0; i < relation.columns.length; i++) {
247
+ let p = relation.columns[i].alias;
248
+ let childKey = relation.childTable._primaryColumns[i].alias;
249
+ if (path[1] === childKey) {
250
+ let dto = {};
251
+ dto[p] = row[p];
252
+ result = await remove({ path: ['dummy', p], oldValue: (oldValue || {})[p], op, options: options }, table, row) || result;
253
+ break;
254
+ }
255
+ }
256
+ return result || {};
257
+ }
258
+ else if (isOneRelation(property, table)) {
259
+ let child = await row[property];
260
+ if (!child)
261
+ throw new Error(property + ' does not exist');
262
+ options[property] = inferOptions(options, property);
263
+
264
+ await remove({ path, op, oldValue, options: options[property] }, table[property], child);
265
+ return { updated: row };
266
+ }
267
+ else if (isManyRelation(property, table)) {
268
+ let relation = table[property]._relation;
269
+ options[property] = inferOptions(options, property);
270
+ if (path.length === 1) {
271
+ let children = (await row[property]).slice(0);
272
+ for (let i = 0; i < children.length; i++) {
273
+ let child = children[i];
274
+ await remove({ path: path.slice(1), op, oldValue, options: options[property] }, table[property], child);
275
+ }
276
+ }
277
+ else {
278
+ await remove({ path: path.slice(1), op, oldValue, options: options[property] }, relation.childTable);
279
+ }
280
+ return { updated: row };
281
+ }
282
+ return {};
283
+ }
284
+
285
+ function isColumn(name, table) {
286
+ return table[name] && table[name].equal;
287
+ }
288
+
289
+ function isManyRelation(name, table) {
290
+ return table[name] && table[name]._relation.isMany;
291
+ }
292
+
293
+ function isOneRelation(name, table) {
294
+ return table[name] && table[name]._relation.isOne;
295
+
296
+ }
297
+
298
+ function isJoinRelation(name, table) {
299
+ return table[name] && table[name]._relation.columns;
300
+ }
301
+
302
+ function inferOptions(defaults, property) {
303
+ const parent = {};
304
+ if ('readonly' in defaults)
305
+ parent.readonly = defaults.readonly;
306
+ if ('concurrency' in defaults)
307
+ parent.concurrency = defaults.concurrency;
308
+ return { ...parent, ...(defaults[property] || {}) };
309
+ }
310
+
311
+ function cleanOptions(options) {
312
+ const { table, transaction, db, ..._options } = options;
313
+ return _options;
314
+ }
315
+ }
316
+
317
+ module.exports = patchTable;
@@ -0,0 +1,8 @@
1
+ var format = 'delete from %s %s%s';
2
+ var util = require('util');
3
+
4
+ function deleteFromSql(table, alias, whereSql) {
5
+ var name = table._dbName;
6
+ return util.format(format, name, alias, whereSql);
7
+ }
8
+ module.exports = deleteFromSql;
@@ -0,0 +1,5 @@
1
+ function encodeBoolean(bool) {
2
+ return bool.toString();
3
+ }
4
+
5
+ module.exports = encodeBoolean;
@@ -0,0 +1,7 @@
1
+ function encodeDate(date) {
2
+ if (date.toISOString)
3
+ return '\'' + date.toISOString() + '\'';
4
+ return '\'' + date + '\'';
5
+ }
6
+
7
+ module.exports = encodeDate;
@@ -0,0 +1,15 @@
1
+ function encode(arg) {
2
+ if (Array.isArray(arg))
3
+ return new JsonBArrayParam(arg);
4
+ else
5
+ return arg;
6
+ }
7
+
8
+ class JsonBArrayParam {
9
+ constructor(actualArray) { this.actualArray = actualArray; }
10
+ toPostgres() {
11
+ return JSON.stringify(this.actualArray);
12
+ }
13
+ }
14
+
15
+ module.exports = encode;
@@ -0,0 +1,5 @@
1
+ function formatDateOut(column, alias) {
2
+ return `${alias}.${column._dbName}::text`;
3
+ }
4
+
5
+ module.exports = formatDateOut;