@nshiab/simple-data-analysis-core 2.0.4 → 2.0.6

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 (280) hide show
  1. package/README.md +118 -12
  2. package/esm/class/Simple.d.ts +8 -2
  3. package/esm/class/Simple.d.ts.map +1 -1
  4. package/esm/class/Simple.js +9 -3
  5. package/esm/class/SimpleDB.d.ts +72 -1
  6. package/esm/class/SimpleDB.d.ts.map +1 -1
  7. package/esm/class/SimpleDB.js +81 -1
  8. package/esm/class/SimpleTable.d.ts +434 -263
  9. package/esm/class/SimpleTable.d.ts.map +1 -1
  10. package/esm/class/SimpleTable.js +441 -316
  11. package/esm/helpers/LogValue.d.ts +8 -0
  12. package/esm/helpers/LogValue.d.ts.map +1 -0
  13. package/esm/helpers/LogValue.js +23 -0
  14. package/esm/helpers/cacheTableDependencies.d.ts +9 -0
  15. package/esm/helpers/cacheTableDependencies.d.ts.map +1 -1
  16. package/esm/helpers/cacheTableDependencies.js +131 -21
  17. package/esm/helpers/cleanSQL.d.ts +1 -1
  18. package/esm/helpers/cleanSQL.d.ts.map +1 -1
  19. package/esm/helpers/cleanSQL.js +268 -23
  20. package/esm/helpers/flushAllTables.d.ts.map +1 -1
  21. package/esm/helpers/flushAllTables.js +23 -28
  22. package/esm/helpers/foldIdentifier.d.ts +3 -0
  23. package/esm/helpers/foldIdentifier.d.ts.map +1 -0
  24. package/esm/helpers/foldIdentifier.js +4 -0
  25. package/esm/helpers/geometryFromJSON.d.ts +3 -0
  26. package/esm/helpers/geometryFromJSON.d.ts.map +1 -0
  27. package/esm/helpers/geometryFromJSON.js +4 -0
  28. package/esm/helpers/index.d.ts +1 -0
  29. package/esm/helpers/index.d.ts.map +1 -1
  30. package/esm/helpers/index.js +1 -0
  31. package/esm/helpers/logData.d.ts.map +1 -1
  32. package/esm/helpers/logData.js +45 -44
  33. package/esm/helpers/makeLogConverter.d.ts +5 -0
  34. package/esm/helpers/makeLogConverter.d.ts.map +1 -0
  35. package/esm/helpers/makeLogConverter.js +64 -0
  36. package/esm/helpers/osmFiles.d.ts.map +1 -1
  37. package/esm/helpers/parseTypes.d.ts +1 -1
  38. package/esm/helpers/parseTypes.d.ts.map +1 -1
  39. package/esm/helpers/parseTypes.js +4 -0
  40. package/esm/helpers/pendingOps.d.ts +4 -2
  41. package/esm/helpers/pendingOps.d.ts.map +1 -1
  42. package/esm/helpers/prepareGeometry.d.ts +3 -0
  43. package/esm/helpers/prepareGeometry.d.ts.map +1 -0
  44. package/esm/helpers/prepareGeometry.js +99 -0
  45. package/esm/helpers/prepareJSON.d.ts +3 -0
  46. package/esm/helpers/prepareJSON.d.ts.map +1 -0
  47. package/esm/helpers/prepareJSON.js +50 -0
  48. package/esm/helpers/printTable.d.ts +5 -4
  49. package/esm/helpers/printTable.d.ts.map +1 -1
  50. package/esm/helpers/printTable.js +32 -36
  51. package/esm/helpers/queryDB.js +1 -1
  52. package/esm/helpers/queueAsyncBarrier.d.ts +4 -0
  53. package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
  54. package/esm/helpers/queueAsyncBarrier.js +4 -0
  55. package/esm/helpers/queueOp.d.ts.map +1 -1
  56. package/esm/helpers/queueOp.js +5 -3
  57. package/esm/helpers/readMutationRows.d.ts +9 -0
  58. package/esm/helpers/readMutationRows.d.ts.map +1 -0
  59. package/esm/helpers/readMutationRows.js +94 -0
  60. package/esm/helpers/referencedTables.d.ts +9 -0
  61. package/esm/helpers/referencedTables.d.ts.map +1 -0
  62. package/esm/helpers/referencedTables.js +22 -0
  63. package/esm/helpers/runQuery.d.ts.map +1 -1
  64. package/esm/helpers/runQuery.js +11 -13
  65. package/esm/helpers/scanSQL.d.ts +7 -0
  66. package/esm/helpers/scanSQL.d.ts.map +1 -0
  67. package/esm/helpers/scanSQL.js +71 -0
  68. package/esm/helpers/tableRegistry.d.ts +2 -0
  69. package/esm/helpers/tableRegistry.d.ts.map +1 -1
  70. package/esm/helpers/tableRegistry.js +12 -4
  71. package/esm/helpers/updateColumnsWithJS.d.ts +52 -0
  72. package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -0
  73. package/esm/helpers/updateColumnsWithJS.js +139 -0
  74. package/esm/methods/addCharacterCount.d.ts +3 -0
  75. package/esm/methods/addCharacterCount.d.ts.map +1 -0
  76. package/esm/methods/addCharacterCount.js +15 -0
  77. package/esm/methods/addColumn.d.ts +1 -1
  78. package/esm/methods/addColumn.d.ts.map +1 -1
  79. package/esm/methods/addGeoNoise.d.ts +7 -0
  80. package/esm/methods/addGeoNoise.d.ts.map +1 -0
  81. package/esm/methods/addGeoNoise.js +135 -0
  82. package/esm/methods/addNoise.d.ts +5 -0
  83. package/esm/methods/addNoise.d.ts.map +1 -0
  84. package/esm/methods/addNoise.js +53 -0
  85. package/esm/methods/addWordCount.d.ts +3 -0
  86. package/esm/methods/addWordCount.d.ts.map +1 -0
  87. package/esm/methods/addWordCount.js +15 -0
  88. package/esm/methods/bm25.d.ts.map +1 -1
  89. package/esm/methods/bm25.js +1 -2
  90. package/esm/methods/cache.d.ts.map +1 -1
  91. package/esm/methods/cache.js +4 -6
  92. package/esm/methods/columnProportions.d.ts +1 -0
  93. package/esm/methods/columnProportions.d.ts.map +1 -1
  94. package/esm/methods/columnProportions.js +7 -2
  95. package/esm/methods/convert.d.ts +2 -2
  96. package/esm/methods/convert.d.ts.map +1 -1
  97. package/esm/methods/convert.js +5 -0
  98. package/esm/methods/getBottom.d.ts +1 -1
  99. package/esm/methods/getBottom.d.ts.map +1 -1
  100. package/esm/methods/getBottom.js +2 -2
  101. package/esm/methods/getData.d.ts +1 -1
  102. package/esm/methods/getData.d.ts.map +1 -1
  103. package/esm/methods/getData.js +2 -2
  104. package/esm/methods/join.d.ts.map +1 -1
  105. package/esm/methods/join.js +8 -16
  106. package/esm/methods/joinGeo.d.ts.map +1 -1
  107. package/esm/methods/joinGeo.js +10 -19
  108. package/esm/methods/loadArray.d.ts +4 -2
  109. package/esm/methods/loadArray.d.ts.map +1 -1
  110. package/esm/methods/loadArray.js +182 -18
  111. package/esm/methods/loadData.js +3 -0
  112. package/esm/methods/loadYahooFinanceData.d.ts +10 -0
  113. package/esm/methods/loadYahooFinanceData.d.ts.map +1 -0
  114. package/esm/methods/loadYahooFinanceData.js +133 -0
  115. package/esm/methods/log.d.ts +7 -0
  116. package/esm/methods/log.d.ts.map +1 -0
  117. package/esm/methods/log.js +58 -0
  118. package/esm/methods/logBottom.d.ts +5 -0
  119. package/esm/methods/logBottom.d.ts.map +1 -0
  120. package/esm/methods/logBottom.js +9 -0
  121. package/esm/methods/removeTable.d.ts.map +1 -1
  122. package/esm/methods/removeTable.js +2 -0
  123. package/esm/methods/removeTables.d.ts.map +1 -1
  124. package/esm/methods/removeTables.js +7 -0
  125. package/esm/methods/renameTable.d.ts.map +1 -1
  126. package/esm/methods/renameTable.js +4 -0
  127. package/esm/methods/rowProportions.d.ts +1 -0
  128. package/esm/methods/rowProportions.d.ts.map +1 -1
  129. package/esm/methods/rowProportions.js +5 -1
  130. package/esm/methods/rowToText.js +2 -2
  131. package/esm/methods/selectTables.d.ts.map +1 -1
  132. package/esm/methods/selectTables.js +6 -0
  133. package/esm/methods/setTypes.d.ts +1 -1
  134. package/esm/methods/setTypes.d.ts.map +1 -1
  135. package/esm/methods/stream.d.ts.map +1 -1
  136. package/esm/methods/stream.js +2 -1
  137. package/esm/methods/updateWithJS.d.ts +1 -3
  138. package/esm/methods/updateWithJS.d.ts.map +1 -1
  139. package/esm/methods/updateWithJS.js +123 -37
  140. package/llm.md +600 -430
  141. package/llms.txt +1 -1
  142. package/package.json +1 -1
  143. package/script/class/Simple.d.ts +8 -2
  144. package/script/class/Simple.d.ts.map +1 -1
  145. package/script/class/Simple.js +9 -3
  146. package/script/class/SimpleDB.d.ts +72 -1
  147. package/script/class/SimpleDB.d.ts.map +1 -1
  148. package/script/class/SimpleDB.js +81 -1
  149. package/script/class/SimpleTable.d.ts +434 -263
  150. package/script/class/SimpleTable.d.ts.map +1 -1
  151. package/script/class/SimpleTable.js +441 -316
  152. package/script/helpers/LogValue.d.ts +8 -0
  153. package/script/helpers/LogValue.d.ts.map +1 -0
  154. package/script/helpers/LogValue.js +26 -0
  155. package/script/helpers/cacheTableDependencies.d.ts +9 -0
  156. package/script/helpers/cacheTableDependencies.d.ts.map +1 -1
  157. package/script/helpers/cacheTableDependencies.js +170 -20
  158. package/script/helpers/cleanSQL.d.ts +1 -1
  159. package/script/helpers/cleanSQL.d.ts.map +1 -1
  160. package/script/helpers/cleanSQL.js +271 -23
  161. package/script/helpers/flushAllTables.d.ts.map +1 -1
  162. package/script/helpers/flushAllTables.js +24 -29
  163. package/script/helpers/foldIdentifier.d.ts +3 -0
  164. package/script/helpers/foldIdentifier.d.ts.map +1 -0
  165. package/script/helpers/foldIdentifier.js +7 -0
  166. package/script/helpers/geometryFromJSON.d.ts +3 -0
  167. package/script/helpers/geometryFromJSON.d.ts.map +1 -0
  168. package/script/helpers/geometryFromJSON.js +7 -0
  169. package/script/helpers/index.d.ts +1 -0
  170. package/script/helpers/index.d.ts.map +1 -1
  171. package/script/helpers/index.js +3 -1
  172. package/script/helpers/logData.d.ts.map +1 -1
  173. package/script/helpers/logData.js +45 -44
  174. package/script/helpers/makeLogConverter.d.ts +5 -0
  175. package/script/helpers/makeLogConverter.d.ts.map +1 -0
  176. package/script/helpers/makeLogConverter.js +70 -0
  177. package/script/helpers/osmFiles.d.ts.map +1 -1
  178. package/script/helpers/parseTypes.d.ts +1 -1
  179. package/script/helpers/parseTypes.d.ts.map +1 -1
  180. package/script/helpers/parseTypes.js +4 -0
  181. package/script/helpers/pendingOps.d.ts +4 -2
  182. package/script/helpers/pendingOps.d.ts.map +1 -1
  183. package/script/helpers/prepareGeometry.d.ts +3 -0
  184. package/script/helpers/prepareGeometry.d.ts.map +1 -0
  185. package/script/helpers/prepareGeometry.js +102 -0
  186. package/script/helpers/prepareJSON.d.ts +3 -0
  187. package/script/helpers/prepareJSON.d.ts.map +1 -0
  188. package/script/helpers/prepareJSON.js +53 -0
  189. package/script/helpers/printTable.d.ts +5 -4
  190. package/script/helpers/printTable.d.ts.map +1 -1
  191. package/script/helpers/printTable.js +32 -36
  192. package/script/helpers/queryDB.js +1 -1
  193. package/script/helpers/queueAsyncBarrier.d.ts +4 -0
  194. package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
  195. package/script/helpers/queueAsyncBarrier.js +4 -0
  196. package/script/helpers/queueOp.d.ts.map +1 -1
  197. package/script/helpers/queueOp.js +4 -2
  198. package/script/helpers/readMutationRows.d.ts +9 -0
  199. package/script/helpers/readMutationRows.d.ts.map +1 -0
  200. package/script/helpers/readMutationRows.js +97 -0
  201. package/script/helpers/referencedTables.d.ts +9 -0
  202. package/script/helpers/referencedTables.d.ts.map +1 -0
  203. package/script/helpers/referencedTables.js +28 -0
  204. package/script/helpers/runQuery.d.ts.map +1 -1
  205. package/script/helpers/runQuery.js +11 -13
  206. package/script/helpers/scanSQL.d.ts +7 -0
  207. package/script/helpers/scanSQL.d.ts.map +1 -0
  208. package/script/helpers/scanSQL.js +74 -0
  209. package/script/helpers/tableRegistry.d.ts +2 -0
  210. package/script/helpers/tableRegistry.d.ts.map +1 -1
  211. package/script/helpers/tableRegistry.js +16 -4
  212. package/script/helpers/updateColumnsWithJS.d.ts +52 -0
  213. package/script/helpers/updateColumnsWithJS.d.ts.map +1 -0
  214. package/script/helpers/updateColumnsWithJS.js +145 -0
  215. package/script/methods/addCharacterCount.d.ts +3 -0
  216. package/script/methods/addCharacterCount.d.ts.map +1 -0
  217. package/script/methods/addCharacterCount.js +21 -0
  218. package/script/methods/addColumn.d.ts +1 -1
  219. package/script/methods/addColumn.d.ts.map +1 -1
  220. package/script/methods/addGeoNoise.d.ts +7 -0
  221. package/script/methods/addGeoNoise.d.ts.map +1 -0
  222. package/script/methods/addGeoNoise.js +141 -0
  223. package/script/methods/addNoise.d.ts +5 -0
  224. package/script/methods/addNoise.d.ts.map +1 -0
  225. package/script/methods/addNoise.js +59 -0
  226. package/script/methods/addWordCount.d.ts +3 -0
  227. package/script/methods/addWordCount.d.ts.map +1 -0
  228. package/script/methods/addWordCount.js +21 -0
  229. package/script/methods/bm25.d.ts.map +1 -1
  230. package/script/methods/bm25.js +1 -2
  231. package/script/methods/cache.d.ts.map +1 -1
  232. package/script/methods/cache.js +3 -5
  233. package/script/methods/columnProportions.d.ts +1 -0
  234. package/script/methods/columnProportions.d.ts.map +1 -1
  235. package/script/methods/columnProportions.js +7 -2
  236. package/script/methods/convert.d.ts +2 -2
  237. package/script/methods/convert.d.ts.map +1 -1
  238. package/script/methods/convert.js +5 -0
  239. package/script/methods/getBottom.d.ts +1 -1
  240. package/script/methods/getBottom.d.ts.map +1 -1
  241. package/script/methods/getBottom.js +2 -2
  242. package/script/methods/getData.d.ts +1 -1
  243. package/script/methods/getData.d.ts.map +1 -1
  244. package/script/methods/getData.js +2 -2
  245. package/script/methods/join.d.ts.map +1 -1
  246. package/script/methods/join.js +8 -16
  247. package/script/methods/joinGeo.d.ts.map +1 -1
  248. package/script/methods/joinGeo.js +10 -19
  249. package/script/methods/loadArray.d.ts +4 -2
  250. package/script/methods/loadArray.d.ts.map +1 -1
  251. package/script/methods/loadArray.js +181 -17
  252. package/script/methods/loadData.js +3 -0
  253. package/script/methods/loadYahooFinanceData.d.ts +10 -0
  254. package/script/methods/loadYahooFinanceData.d.ts.map +1 -0
  255. package/script/methods/loadYahooFinanceData.js +139 -0
  256. package/script/methods/log.d.ts +7 -0
  257. package/script/methods/log.d.ts.map +1 -0
  258. package/script/methods/log.js +64 -0
  259. package/script/methods/logBottom.d.ts +5 -0
  260. package/script/methods/logBottom.d.ts.map +1 -0
  261. package/script/methods/logBottom.js +15 -0
  262. package/script/methods/removeTable.d.ts.map +1 -1
  263. package/script/methods/removeTable.js +2 -0
  264. package/script/methods/removeTables.d.ts.map +1 -1
  265. package/script/methods/removeTables.js +7 -0
  266. package/script/methods/renameTable.d.ts.map +1 -1
  267. package/script/methods/renameTable.js +4 -0
  268. package/script/methods/rowProportions.d.ts +1 -0
  269. package/script/methods/rowProportions.d.ts.map +1 -1
  270. package/script/methods/rowProportions.js +5 -1
  271. package/script/methods/rowToText.js +2 -2
  272. package/script/methods/selectTables.d.ts.map +1 -1
  273. package/script/methods/selectTables.js +6 -0
  274. package/script/methods/setTypes.d.ts +1 -1
  275. package/script/methods/setTypes.d.ts.map +1 -1
  276. package/script/methods/stream.d.ts.map +1 -1
  277. package/script/methods/stream.js +2 -1
  278. package/script/methods/updateWithJS.d.ts +1 -3
  279. package/script/methods/updateWithJS.d.ts.map +1 -1
  280. package/script/methods/updateWithJS.js +122 -36
@@ -7,14 +7,14 @@ exports.default = getBottom;
7
7
  const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
8
8
  const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
9
9
  const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
10
- async function getBottom(simpleTable, count, options = {}) {
10
+ async function getBottom(simpleTable, count, options = {}, method = "getBottom()") {
11
11
  const queryResult = await (0, queryDB_js_1.default)(simpleTable, `WITH "numberedRowsForGetBottom" AS (
12
12
  SELECT *, row_number() OVER () as "rowNumberForGetBottom" FROM ${(0, quoteIdentifier_js_1.default)(simpleTable.name)}${options.conditions ? ` WHERE ${options.conditions}` : ""}
13
13
  )
14
14
  SELECT * FROM "numberedRowsForGetBottom" ORDER BY "rowNumberForGetBottom" DESC LIMIT ${count};`, (0, mergeOptions_js_1.default)(simpleTable, {
15
15
  table: simpleTable.name,
16
16
  returnData: true,
17
- method: "getBottom()",
17
+ method,
18
18
  parameters: { count, options },
19
19
  }));
20
20
  if (!queryResult) {
@@ -3,7 +3,7 @@ export default function getData(simpleTable: SimpleTable, options?: {
3
3
  columns?: string | string[];
4
4
  conditions?: string;
5
5
  limit?: number;
6
- }): Promise<{
6
+ }, method?: "getData()" | "log()"): Promise<{
7
7
  [key: string]: unknown;
8
8
  }[]>;
9
9
  //# sourceMappingURL=getData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../src/methods/getData.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAIvD,wBAA8B,OAAO,CACnC,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX;;KAmCP"}
1
+ {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../src/methods/getData.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAIvD,wBAA8B,OAAO,CACnC,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX,EACN,MAAM,GAAE,WAAW,GAAG,OAAqB;;KAmC5C"}
@@ -8,7 +8,7 @@ const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"))
8
8
  const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
9
9
  const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
10
10
  const quoteQualifiedIdentifier_js_1 = __importDefault(require("../helpers/quoteQualifiedIdentifier.js"));
11
- async function getData(simpleTable, options = {}) {
11
+ async function getData(simpleTable, options = {}, method = "getData()") {
12
12
  if (options.limit !== undefined &&
13
13
  (!Number.isInteger(options.limit) || options.limit < 0)) {
14
14
  throw new Error("getData() limit must be an integer greater than or equal to 0.");
@@ -23,7 +23,7 @@ async function getData(simpleTable, options = {}) {
23
23
  : "*"} from ${(0, quoteIdentifier_js_1.default)(simpleTable.name)}${options.conditions ? ` WHERE ${options.conditions}` : ""}${options.limit === undefined ? "" : ` LIMIT ${options.limit}`}`, (0, mergeOptions_js_1.default)(simpleTable, {
24
24
  returnData: true,
25
25
  table: simpleTable.name,
26
- method: "getData()",
26
+ method,
27
27
  parameters: { options },
28
28
  })));
29
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/methods/join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAOvD,MAAM,CAAC,OAAO,UAAU,IAAI,CAC1B,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,GACL,WAAW,CAiBb"}
1
+ {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/methods/join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAKvD,MAAM,CAAC,OAAO,UAAU,IAAI,CAC1B,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,GACL,WAAW,CAkBb"}
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = join;
7
7
  const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
8
8
  const getIdenticalColumns_js_1 = __importDefault(require("../helpers/getIdenticalColumns.js"));
9
- const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
10
- const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
11
9
  const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
12
10
  const assertSameDatabase_js_1 = __importDefault(require("../helpers/assertSameDatabase.js"));
13
11
  function join(leftTable, rightTable, options = {}) {
@@ -19,14 +17,15 @@ function join(leftTable, rightTable, options = {}) {
19
17
  ? leftTable.sdb.newTable(options.outputTable)
20
18
  : leftTable;
21
19
  (0, queueOp_js_1.default)(outputTable, {
22
- kind: "barrier",
20
+ kind: "source",
21
+ rawSQL: [(0, quoteIdentifier_js_1.default)(leftTable.name), (0, quoteIdentifier_js_1.default)(rightTable.name)],
23
22
  method: "join()",
24
23
  parameters: { rightTable: rightTable.name, options },
25
- execute: () => executeJoin(leftTable, rightTable, outputTable, options),
24
+ buildSelect: () => buildJoinSelect(leftTable, rightTable, options),
26
25
  });
27
26
  return outputTable;
28
27
  }
29
- async function executeJoin(leftTable, rightTable, outputTable, options) {
28
+ async function buildJoinSelect(leftTable, rightTable, options) {
30
29
  const leftTableColumns = await leftTable.getColumns();
31
30
  const rightTableColumns = await rightTable.getColumns();
32
31
  const identicalColumns = (0, getIdenticalColumns_js_1.default)(leftTableColumns, rightTableColumns);
@@ -80,17 +79,10 @@ async function executeJoin(leftTable, rightTable, outputTable, options) {
80
79
  .filter((d) => !on.includes(d))
81
80
  .map((d) => `${(0, quoteIdentifier_js_1.default)(rightTable.name)}.${(0, quoteIdentifier_js_1.default)(d)}`),
82
81
  ].join(", ");
83
- await (0, queryDB_js_1.default)(leftTable, joinQuery(leftTable.name, rightTable.name, on, type, outputTable.name, selectList), (0, mergeOptions_js_1.default)(leftTable, {
84
- table: outputTable.name,
85
- method: "join()",
86
- parameters: {
87
- rightTable: rightTable.name,
88
- options,
89
- },
90
- }));
82
+ return joinQuery(leftTable.name, rightTable.name, on, type, selectList);
91
83
  }
92
- function joinQuery(leftTable, rightTable, on, join, outputTable, selectList) {
93
- let query = `CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(outputTable)} AS SELECT ${selectList}`;
84
+ function joinQuery(leftTable, rightTable, on, join, selectList) {
85
+ let query = `SELECT ${selectList}`;
94
86
  if (join === "inner") {
95
87
  query += ` FROM ${(0, quoteIdentifier_js_1.default)(leftTable)} JOIN ${(0, quoteIdentifier_js_1.default)(rightTable)}`;
96
88
  }
@@ -107,6 +99,6 @@ function joinQuery(leftTable, rightTable, on, join, outputTable, selectList) {
107
99
  throw new Error(`Unknown ${join} join.`);
108
100
  }
109
101
  query += ` ON (${on.map((d) => `${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(d)} = ${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(d)}`)
110
- .join(" AND ")});\n`;
102
+ .join(" AND ")})`;
111
103
  return query;
112
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"joinGeo.d.ts","sourceRoot":"","sources":["../../src/methods/joinGeo.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAQvD,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,gBAAgB,EACjD,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,UAAU,CAAC;IAClD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,GACL,WAAW,CAmBb"}
1
+ {"version":3,"file":"joinGeo.d.ts","sourceRoot":"","sources":["../../src/methods/joinGeo.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,gBAAgB,EACjD,UAAU,EAAE,WAAW,EACvB,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,UAAU,CAAC;IAClD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,GACL,WAAW,CAqBb"}
@@ -8,8 +8,6 @@ const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier
8
8
  const capitalize_js_1 = __importDefault(require("../helpers/capitalize.js"));
9
9
  const findGeoColumnFromSchema_js_1 = __importDefault(require("../helpers/findGeoColumnFromSchema.js"));
10
10
  const getIdenticalColumns_js_1 = __importDefault(require("../helpers/getIdenticalColumns.js"));
11
- const mergeOptions_js_1 = __importDefault(require("../helpers/mergeOptions.js"));
12
- const queryDB_js_1 = __importDefault(require("../helpers/queryDB.js"));
13
11
  const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
14
12
  const assertSameDatabase_js_1 = __importDefault(require("../helpers/assertSameDatabase.js"));
15
13
  function joinGeo(leftTable, method, rightTable, options = {}) {
@@ -22,10 +20,12 @@ function joinGeo(leftTable, method, rightTable, options = {}) {
22
20
  ? leftTable.sdb.newTable(options.outputTable)
23
21
  : leftTable;
24
22
  (0, queueOp_js_1.default)(outputTable, {
25
- kind: "barrier",
23
+ kind: "source",
24
+ rawSQL: [(0, quoteIdentifier_js_1.default)(leftTable.name), (0, quoteIdentifier_js_1.default)(rightTable.name)],
25
+ needsSpatial: true,
26
26
  method: "joinGeo()",
27
27
  parameters: { method, rightTable: rightTable.name, options },
28
- execute: () => executeJoinGeo(leftTable, method, rightTable, outputTable, options),
28
+ buildSelect: () => buildJoinGeoSelect(leftTable, method, rightTable, options),
29
29
  });
30
30
  return outputTable;
31
31
  }
@@ -49,7 +49,7 @@ function validateJoinGeoOptions(method, options) {
49
49
  function formatReceivedValue(value) {
50
50
  return JSON.stringify(value) ?? String(value);
51
51
  }
52
- async function executeJoinGeo(leftTable, method, rightTable, outputTable, options) {
52
+ async function buildJoinGeoSelect(leftTable, method, rightTable, options) {
53
53
  const leftTypes = await leftTable.getTypes();
54
54
  const rightTypes = await rightTable.getTypes();
55
55
  const leftColumn = options.leftColumn ??
@@ -89,19 +89,10 @@ async function executeJoinGeo(leftTable, method, rightTable, outputTable, option
89
89
  ]),
90
90
  ].join(", ");
91
91
  const type = options.type ?? "left";
92
- await (0, queryDB_js_1.default)(leftTable, joinGeoQuery(leftTable.name, leftColumn, method, rightTable.name, rightColumn, type, outputTable.name, selectList, options.distance, options.distanceMethod), (0, mergeOptions_js_1.default)(leftTable, {
93
- table: outputTable.name,
94
- method: "joinGeo()",
95
- parameters: {
96
- leftTable: leftTable.name,
97
- method,
98
- rightTable: rightTable.name,
99
- options,
100
- },
101
- }));
92
+ return joinGeoQuery(leftTable.name, leftColumn, method, rightTable.name, rightColumn, type, selectList, options.distance, options.distanceMethod);
102
93
  }
103
- function joinGeoQuery(leftTable, leftColumn, method, rightTable, rightColumn, join, outputTable, selectList, distance, distanceMethod) {
104
- let query = `CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(outputTable)} AS SELECT ${selectList}`;
94
+ function joinGeoQuery(leftTable, leftColumn, method, rightTable, rightColumn, join, selectList, distance, distanceMethod) {
95
+ let query = `SELECT ${selectList}`;
105
96
  if (join === "inner") {
106
97
  query += ` FROM ${(0, quoteIdentifier_js_1.default)(leftTable)} JOIN ${(0, quoteIdentifier_js_1.default)(rightTable)}`;
107
98
  }
@@ -118,11 +109,11 @@ function joinGeoQuery(leftTable, leftColumn, method, rightTable, rightColumn, jo
118
109
  throw new Error(`Unknown ${join} join.`);
119
110
  }
120
111
  if (method === "intersect") {
121
- query += ` ON ST_Intersects(${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)}, ${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)});`;
112
+ query += ` ON ST_Intersects(${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)}, ${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)})`;
122
113
  }
123
114
  else if (method === "inside") {
124
115
  // Order is important
125
- query += ` ON ST_Covers(${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)}, ${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)});`;
116
+ query += ` ON ST_Covers(${(0, quoteIdentifier_js_1.default)(rightTable)}.${(0, quoteIdentifier_js_1.default)(rightColumn)}, ${(0, quoteIdentifier_js_1.default)(leftTable)}.${(0, quoteIdentifier_js_1.default)(leftColumn)})`;
126
117
  }
127
118
  else if (method === "withinDistance") {
128
119
  if (typeof distance === "number") {
@@ -2,7 +2,7 @@ import { type DuckDBValue } from "@duckdb/node-api";
2
2
  import type SimpleTable from "../class/SimpleTable.js";
3
3
  export default function loadArray(simpleTable: SimpleTable, rows: {
4
4
  [key: string]: unknown;
5
- }[]): void;
5
+ }[], options?: NonNullable<Parameters<SimpleTable["loadArray"]>[1]>): void;
6
6
  type PreparedArray = {
7
7
  keys: string[];
8
8
  types: string[];
@@ -11,7 +11,9 @@ type PreparedArray = {
11
11
  };
12
12
  export declare function prepareArray(rows: {
13
13
  [key: string]: unknown;
14
- }[]): PreparedArray;
14
+ }[], columnTypes?: {
15
+ [key: string]: string;
16
+ }, requireExplicitNestedTypes?: boolean): PreparedArray;
15
17
  export declare function executePreparedArray(simpleTable: SimpleTable, prepared: PreparedArray): Promise<void>;
16
18
  export {};
17
19
  //# sourceMappingURL=loadArray.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadArray.d.ts","sourceRoot":"","sources":["../../src/methods/loadArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAKvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,QAiBnC;AAED,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,WAAW,EAAE,EAAE,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAC1B,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,GACjC,aAAa,CA8Df;AAED,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,aAAa,iBA+BxB"}
1
+ {"version":3,"file":"loadArray.d.ts","sourceRoot":"","sources":["../../src/methods/loadArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAKvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,EAClC,OAAO,GAAE,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAM,QAiBnE;AAED,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,WAAW,EAAE,EAAE,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAC1B,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,EAClC,WAAW,GAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAO,EAC3C,0BAA0B,UAAQ,GACjC,aAAa,CAsHf;AAED,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,aAAa,iBA4ExB"}
@@ -7,16 +7,19 @@ exports.default = loadArray;
7
7
  exports.prepareArray = prepareArray;
8
8
  exports.executePreparedArray = executePreparedArray;
9
9
  const node_api_1 = require("@duckdb/node-api");
10
+ const prepareGeometry_js_1 = __importDefault(require("../helpers/prepareGeometry.js"));
11
+ const prepareJSON_js_1 = __importDefault(require("../helpers/prepareJSON.js"));
12
+ const geometryFromJSON_js_1 = __importDefault(require("../helpers/geometryFromJSON.js"));
10
13
  const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
11
14
  const parseTypes_js_1 = __importDefault(require("../helpers/parseTypes.js"));
12
15
  const parseDuckDBType_js_1 = __importDefault(require("../helpers/parseDuckDBType.js"));
13
16
  const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
14
- function loadArray(simpleTable, rows) {
17
+ function loadArray(simpleTable, rows, options = {}) {
15
18
  // This validation doesn't need the database, so it stays at call time.
16
19
  if (rows.length === 0) {
17
20
  throw new Error("The array is empty. loadArray needs at least one object to infer the column types.");
18
21
  }
19
- const prepared = prepareArray(rows);
22
+ const prepared = prepareArray(rows, options.columnTypes, true);
20
23
  (0, queueOp_js_1.default)(simpleTable, {
21
24
  kind: "barrier",
22
25
  method: "loadArray()",
@@ -24,14 +27,55 @@ function loadArray(simpleTable, rows) {
24
27
  execute: () => executePreparedArray(simpleTable, prepared),
25
28
  });
26
29
  }
27
- function prepareArray(rows) {
30
+ function prepareArray(rows, columnTypes = {}, requireExplicitNestedTypes = false) {
28
31
  const keys = Object.keys(rows[0]);
32
+ const overrides = new Map();
33
+ for (const [key, type] of Object.entries(columnTypes)) {
34
+ if (!keys.includes(key)) {
35
+ throw new Error(`Unknown column ${JSON.stringify(key)} in loadArray columnTypes.`);
36
+ }
37
+ if (type.toUpperCase() === "JSON") {
38
+ overrides.set(key, "JSON");
39
+ continue;
40
+ }
41
+ if (/^geometry/i.test(type)) {
42
+ if (!/^geometry\('EPSG:4326'\)$/i.test(type)) {
43
+ throw new Error(`Unsupported type ${JSON.stringify(type)} for column ${JSON.stringify(key)}. GeoJSON ingestion requires GEOMETRY('EPSG:4326'); reproject input to WGS84 first.`);
44
+ }
45
+ overrides.set(key, "GEOMETRY('EPSG:4326')");
46
+ continue;
47
+ }
48
+ try {
49
+ const normalized = (0, parseTypes_js_1.default)(type);
50
+ (0, parseDuckDBType_js_1.default)(normalized);
51
+ overrides.set(key, normalized);
52
+ }
53
+ catch {
54
+ throw new Error(`Unsupported type ${JSON.stringify(type)} for column ${JSON.stringify(key)}.`);
55
+ }
56
+ }
29
57
  const firstNonNullValue = keys.map((key) => rows.find((obj) => obj[key] !== null && obj[key] !== undefined)?.[key]);
30
58
  const types = [];
31
59
  const columnsData = keys.map(() => new Array(rows.length));
32
60
  for (let i = 0; i < keys.length; i++) {
33
61
  const key = keys[i];
34
62
  const columnData = columnsData[i];
63
+ const override = overrides.get(key);
64
+ if (override !== undefined) {
65
+ types[i] = override;
66
+ for (let j = 0; j < rows.length; j++) {
67
+ columnData[j] = prepareTypedValue(rows[j][key], override, key, j + 1);
68
+ }
69
+ continue;
70
+ }
71
+ if (requireExplicitNestedTypes) {
72
+ for (let j = 0; j < rows.length; j++) {
73
+ const cell = rows[j][key];
74
+ if (cell !== null && typeof cell === "object" && !(cell instanceof Date)) {
75
+ throw new Error(`Column ${JSON.stringify(key)}, row ${j + 1}: array and object cells require an explicit columnTypes entry. Use JSON for nested data, FLOAT[n] for fixed-size vectors, or GEOMETRY('EPSG:4326') for GeoJSON geometries.`);
76
+ }
77
+ }
78
+ }
35
79
  const value = firstNonNullValue[i];
36
80
  const type = typeof value;
37
81
  if (type === "symbol" || type === "function") {
@@ -88,19 +132,139 @@ async function executePreparedArray(simpleTable, prepared) {
88
132
  simpleTable.connection = simpleTable.sdb.connection;
89
133
  }
90
134
  const { keys, types, columnsData, rowCount } = prepared;
91
- await simpleTable.sdb.customQuery(`CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(simpleTable.name)}(${keys.map((key, i) => `${(0, quoteIdentifier_js_1.default)(key)} ${types[i]}`).join(", ")})`);
92
- const appender = await simpleTable.connection
93
- .createAppender(simpleTable.name);
94
- const duckDBTypes = types.map((d) => (0, parseDuckDBType_js_1.default)(d));
95
- // The maximum capacity of a DuckDB data chunk is 2048 rows.
96
- const chunkSize = 2000;
97
- for (let start = 0; start < rowCount; start += chunkSize) {
98
- const end = Math.min(start + chunkSize, rowCount);
99
- const dataChunk = node_api_1.DuckDBDataChunk.create(duckDBTypes, end - start);
100
- for (let i = 0; i < keys.length; i++) {
101
- dataChunk.setColumnValues(i, columnsData[i].slice(start, end));
102
- }
103
- appender.appendDataChunk(dataChunk);
135
+ const hasGeometry = types.includes("GEOMETRY('EPSG:4326')");
136
+ const needsConversion = hasGeometry || types.includes("JSON");
137
+ const staged = needsConversion
138
+ ? `__sda_array_${crypto.randomUUID().replaceAll("-", "")}`
139
+ : simpleTable.name;
140
+ const storageTypes = types.map((type) => type.startsWith("GEOMETRY") || type === "JSON" ? "VARCHAR" : type);
141
+ if (hasGeometry && !simpleTable.sdb.spatialLoaded) {
142
+ await simpleTable.sdb.customQuery("INSTALL spatial; LOAD spatial; SET geometry_always_xy = true;");
143
+ simpleTable.sdb.spatialLoaded = true;
144
+ }
145
+ try {
146
+ await simpleTable.sdb.customQuery(`CREATE ${needsConversion ? "TEMP" : "OR REPLACE"} TABLE ${(0, quoteIdentifier_js_1.default)(staged)}(${keys.map((key, i) => `${(0, quoteIdentifier_js_1.default)(key)} ${storageTypes[i]}`).join(", ")})`);
147
+ const appender = await simpleTable.connection
148
+ .createAppender(staged);
149
+ try {
150
+ const duckDBTypes = storageTypes.map((d) => (0, parseDuckDBType_js_1.default)(d));
151
+ // The maximum capacity of a DuckDB data chunk is 2048 rows.
152
+ const chunkSize = 2000;
153
+ for (let start = 0; start < rowCount; start += chunkSize) {
154
+ const end = Math.min(start + chunkSize, rowCount);
155
+ const dataChunk = node_api_1.DuckDBDataChunk.create(duckDBTypes, end - start);
156
+ for (let i = 0; i < keys.length; i++) {
157
+ dataChunk.setColumnValues(i, columnsData[i].slice(start, end));
158
+ }
159
+ appender.appendDataChunk(dataChunk);
160
+ }
161
+ appender.flushSync();
162
+ }
163
+ finally {
164
+ appender.closeSync();
165
+ }
166
+ if (!needsConversion)
167
+ return;
168
+ // CTAS is atomic: conversion must finish before the destination is replaced.
169
+ await simpleTable.sdb.customQuery(`CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(simpleTable.name)} AS SELECT ${keys.map((key, i) => types[i].startsWith("GEOMETRY")
170
+ ? `${(0, geometryFromJSON_js_1.default)((0, quoteIdentifier_js_1.default)(key))} AS ${(0, quoteIdentifier_js_1.default)(key)}`
171
+ : types[i] === "JSON"
172
+ ? `${(0, quoteIdentifier_js_1.default)(key)}::JSON AS ${(0, quoteIdentifier_js_1.default)(key)}`
173
+ : (0, quoteIdentifier_js_1.default)(key)).join(", ")} FROM ${(0, quoteIdentifier_js_1.default)(staged)}`);
174
+ }
175
+ finally {
176
+ if (needsConversion) {
177
+ await simpleTable.sdb.customQuery(`DROP TABLE IF EXISTS ${(0, quoteIdentifier_js_1.default)(staged)}`);
178
+ }
179
+ }
180
+ }
181
+ /** Validates and snapshots a value for an explicitly declared destination type. */
182
+ function prepareTypedValue(value, type, column, row) {
183
+ if (type === "JSON")
184
+ return (0, prepareJSON_js_1.default)(value, column, row);
185
+ if (type === "GEOMETRY('EPSG:4326')") {
186
+ return (0, prepareGeometry_js_1.default)(value, column, row);
187
+ }
188
+ if (value === null || value === undefined || Number.isNaN(value))
189
+ return null;
190
+ let compatible = false;
191
+ if (type === "VARCHAR" && typeof value === "string")
192
+ return value;
193
+ if (type === "BOOLEAN" && typeof value === "boolean")
194
+ return value;
195
+ if (type === "DOUBLE") {
196
+ if (typeof value === "number")
197
+ return value;
198
+ compatible = typeof value === "bigint";
199
+ if (typeof value === "bigint") {
200
+ const number = Number(value);
201
+ if (Number.isFinite(number) && BigInt(number) === value)
202
+ return number;
203
+ }
204
+ }
205
+ else if (type === "INTEGER") {
206
+ compatible = typeof value === "number" || typeof value === "bigint";
207
+ if (typeof value === "number") {
208
+ if (Number.isInteger(value) && value >= -2147483648 && value <= 2147483647) {
209
+ return value;
210
+ }
211
+ }
212
+ else if (typeof value === "bigint" && value >= -2147483648n && value <= 2147483647n) {
213
+ return Number(value);
214
+ }
215
+ }
216
+ else if (type === "BIGINT") {
217
+ compatible = typeof value === "number" || typeof value === "bigint";
218
+ if (typeof value === "bigint") {
219
+ if (value >= -9223372036854775808n && value <= 9223372036854775807n) {
220
+ return value;
221
+ }
222
+ }
223
+ else if (typeof value === "number" && Number.isInteger(value) &&
224
+ value >= -(2 ** 63) && value < 2 ** 63) {
225
+ // The upper bound is exclusive: 2 ** 63 - 1 rounds up as a JS number.
226
+ return BigInt(value);
227
+ }
228
+ }
229
+ else if (["DATE", "TIME", "TIMESTAMP", "TIMESTAMP WITH TIME ZONE"].includes(type)) {
230
+ if (type === "TIME" && value instanceof node_api_1.DuckDBTimeValue) {
231
+ if (value.micros >= 0n && value.micros <= 86400000000n) {
232
+ return new node_api_1.DuckDBTimeValue(value.micros);
233
+ }
234
+ compatible = true;
235
+ }
236
+ else if (value instanceof Date) {
237
+ const millis = value.getTime();
238
+ compatible = Number.isFinite(millis);
239
+ if (compatible) {
240
+ if (type === "DATE" && millis % 86400000 === 0) {
241
+ return new node_api_1.DuckDBDateValue(millis / 86400000);
242
+ }
243
+ const micros = BigInt(millis) * 1000n;
244
+ if (type === "TIMESTAMP")
245
+ return new node_api_1.DuckDBTimestampValue(micros);
246
+ if (type === "TIMESTAMP WITH TIME ZONE") {
247
+ return new node_api_1.DuckDBTimestampTZValue(micros);
248
+ }
249
+ }
250
+ }
251
+ }
252
+ else if (type.startsWith("FLOAT[") && Array.isArray(value)) {
253
+ compatible = true;
254
+ const size = Number(type.slice(6, -1));
255
+ if (value.length === size &&
256
+ value.every((item) => item === null || item === undefined ||
257
+ (typeof item === "number" &&
258
+ (Number.isNaN(item) || Math.fround(item) === item)))) {
259
+ return (0, node_api_1.arrayValue)(value.map((item) => item === undefined || Number.isNaN(item)
260
+ ? null
261
+ : item));
262
+ }
104
263
  }
105
- appender.flushSync();
264
+ const displayed = typeof value === "string"
265
+ ? JSON.stringify(value)
266
+ : String(value);
267
+ throw new Error(`Column ${JSON.stringify(column)}, row ${row}: value ${displayed} ${compatible
268
+ ? `cannot be stored as ${type} without losing information`
269
+ : `is incompatible with ${type}`}. Select a type compatible with this value.`);
106
270
  }
@@ -54,6 +54,9 @@ function loadDataQuery(table, files, options = {}) {
54
54
  return `CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(table)} AS ${loadDataSelect(files, options)};`;
55
55
  }
56
56
  function loadDataSelect(files, options = {}) {
57
+ if (Object.values(options.columnTypes ?? {}).some((type) => /^\s*geometry\b/i.test(type))) {
58
+ throw new Error("Geometry column types are not supported by loadData(). Use loadGeoData() instead.");
59
+ }
57
60
  const fileExtension = (0, getExtension_js_1.default)(files[0]);
58
61
  if (options.fileType !== undefined &&
59
62
  !["csv", "dsv", "json", "parquet", "excel"].includes(options.fileType)) {
@@ -0,0 +1,10 @@
1
+ import type SimpleTable from "../class/SimpleTable.js";
2
+ declare const INTERVAL_SECONDS: {
3
+ readonly "1d": number;
4
+ readonly "1h": number;
5
+ readonly "1m": 60;
6
+ };
7
+ type YahooInterval = keyof typeof INTERVAL_SECONDS;
8
+ export default function loadYahooFinanceData(table: SimpleTable, symbol: string, startDate: Date, endDate: Date, interval: YahooInterval): void;
9
+ export {};
10
+ //# sourceMappingURL=loadYahooFinanceData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadYahooFinanceData.d.ts","sourceRoot":"","sources":["../../src/methods/loadYahooFinanceData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAKvD,QAAA,MAAM,gBAAgB;;;;CAIZ,CAAC;AAeX,KAAK,aAAa,GAAG,MAAM,OAAO,gBAAgB,CAAC;AA6BnD,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,QAAQ,EAAE,aAAa,GACtB,IAAI,CAeN"}
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = loadYahooFinanceData;
7
+ const SDAError_js_1 = __importDefault(require("../class/SDAError.js"));
8
+ const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
9
+ const loadArray_js_1 = require("./loadArray.js");
10
+ const INTERVAL_SECONDS = {
11
+ "1d": 24 * 60 * 60,
12
+ "1h": 60 * 60,
13
+ "1m": 60,
14
+ };
15
+ const COLUMN_TYPES = {
16
+ datetime: "TIMESTAMP",
17
+ open: "DOUBLE",
18
+ high: "DOUBLE",
19
+ low: "DOUBLE",
20
+ close: "DOUBLE",
21
+ adjustedClose: "DOUBLE",
22
+ volume: "DOUBLE",
23
+ };
24
+ const USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36";
25
+ function loadYahooFinanceData(table, symbol, startDate, endDate, interval) {
26
+ assertArguments(symbol, startDate, endDate, interval);
27
+ const request = {
28
+ symbol,
29
+ startDate: new Date(startDate),
30
+ endDate: new Date(endDate),
31
+ interval,
32
+ };
33
+ (0, queueOp_js_1.default)(table, {
34
+ kind: "barrier",
35
+ method: "loadYahooFinanceData()",
36
+ parameters: request,
37
+ execute: () => executeLoadYahooFinanceData(table, request),
38
+ });
39
+ }
40
+ async function executeLoadYahooFinanceData(table, request) {
41
+ try {
42
+ const rows = await getYahooFinanceData(request);
43
+ await (0, loadArray_js_1.executePreparedArray)(table, (0, loadArray_js_1.prepareArray)(rows, COLUMN_TYPES));
44
+ }
45
+ catch (error) {
46
+ if (error instanceof SDAError_js_1.default) {
47
+ throw error;
48
+ }
49
+ throw new SDAError_js_1.default({
50
+ method: "loadYahooFinanceData()",
51
+ parameters: request,
52
+ query: "",
53
+ cause: error,
54
+ });
55
+ }
56
+ }
57
+ async function getYahooFinanceData(request) {
58
+ const { symbol, startDate, endDate, interval } = request;
59
+ const startTime = startDate.getTime();
60
+ const exclusiveEndTime = getExclusiveEndTime(endDate, interval);
61
+ const url = new URL(`https://query1.finance.yahoo.com/v8/finance/chart/${encodeURIComponent(symbol)}`);
62
+ url.search = new URLSearchParams({
63
+ includeAdjustedClose: "true",
64
+ interval,
65
+ period1: String(Math.floor(startTime / 1000)),
66
+ period2: String(Math.ceil(exclusiveEndTime / 1000)),
67
+ }).toString();
68
+ const response = await fetch(url, {
69
+ headers: { "User-Agent": USER_AGENT },
70
+ });
71
+ if (!response.ok) {
72
+ const text = (await response.text()).slice(0, 500).trim();
73
+ throw new Error(`Failed to fetch Yahoo Finance data: ${response.status} ${response.statusText}${text.length > 0 ? `. ${text}` : ""}. Yahoo may have changed, rate-limited, or disabled this undocumented endpoint.`);
74
+ }
75
+ const data = await response.json();
76
+ if (data.chart?.error) {
77
+ throw new Error(data.chart.error.description ??
78
+ "Yahoo Finance returned an unknown error.");
79
+ }
80
+ const result = data.chart?.result?.[0];
81
+ const timestamps = result?.timestamp;
82
+ if (!result || !timestamps?.length) {
83
+ throw new Error("No Yahoo Finance data found.");
84
+ }
85
+ const quote = result.indicators?.quote?.[0];
86
+ const adjustedClose = result.indicators?.adjclose?.[0]?.adjclose;
87
+ const rows = [];
88
+ for (let index = 0; index < timestamps.length; index++) {
89
+ const timestamp = timestamps[index] * 1000;
90
+ if (Number.isFinite(timestamp) && timestamp >= startTime &&
91
+ timestamp < exclusiveEndTime) {
92
+ rows.push({
93
+ datetime: new Date(timestamp),
94
+ open: getFiniteValue(quote?.open, index),
95
+ high: getFiniteValue(quote?.high, index),
96
+ low: getFiniteValue(quote?.low, index),
97
+ close: getFiniteValue(quote?.close, index),
98
+ adjustedClose: getFiniteValue(adjustedClose, index),
99
+ volume: getFiniteValue(quote?.volume, index),
100
+ });
101
+ }
102
+ }
103
+ if (rows.length === 0) {
104
+ throw new Error(`No Yahoo Finance data found for ${symbol}.`);
105
+ }
106
+ return rows;
107
+ }
108
+ function getFiniteValue(values, index) {
109
+ const value = values?.[index];
110
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
111
+ }
112
+ function getExclusiveEndTime(endDate, interval) {
113
+ const end = new Date(endDate);
114
+ if (interval === "1d") {
115
+ end.setUTCHours(0, 0, 0, 0);
116
+ }
117
+ else if (interval === "1h") {
118
+ end.setUTCMinutes(0, 0, 0);
119
+ }
120
+ else {
121
+ end.setUTCSeconds(0, 0);
122
+ }
123
+ return end.getTime() + INTERVAL_SECONDS[interval] * 1000;
124
+ }
125
+ function assertArguments(symbol, startDate, endDate, interval) {
126
+ if (typeof symbol !== "string" || symbol.trim().length === 0) {
127
+ throw new TypeError("loadYahooFinanceData() symbol must be a non-empty string.");
128
+ }
129
+ if (!(startDate instanceof Date) || !(endDate instanceof Date) ||
130
+ !Number.isFinite(startDate.getTime()) || !Number.isFinite(endDate.getTime())) {
131
+ throw new RangeError("loadYahooFinanceData() startDate and endDate must be valid dates.");
132
+ }
133
+ if (endDate.getTime() < startDate.getTime()) {
134
+ throw new RangeError("loadYahooFinanceData() endDate must be equal to or later than startDate.");
135
+ }
136
+ if (interval !== "1d" && interval !== "1h" && interval !== "1m") {
137
+ throw new Error('loadYahooFinanceData() interval must be "1d", "1h", or "1m".');
138
+ }
139
+ }
@@ -0,0 +1,7 @@
1
+ import type SimpleTable from "../class/SimpleTable.js";
2
+ export default function log(simpleTable: SimpleTable, options?: "all" | number | {
3
+ count?: number | "all";
4
+ types?: boolean;
5
+ conditions?: string;
6
+ }): Promise<void>;
7
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/methods/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAMvD,wBAA8B,GAAG,CAC/B,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE,KAAK,GAAG,MAAM,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB,iBAyEP"}