@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
@@ -111,7 +111,7 @@ export default class SimpleTable extends Simple {
111
111
  * @param simpleDB - The SimpleDB instance that this table belongs to.
112
112
  * @param options - An optional object with configuration options:
113
113
  * @param options.rowsToLog - The number of rows to log when displaying table data.
114
- * @param options.charsToLog - The maximum number of characters to log for strings. Useful to avoid logging large text content.
114
+ * @param options.charsToLog - The maximum characters to display for text and stringified nested cells, including truncation markers (default: 75). Independent of column width. Use Infinity for unlimited text.
115
115
  * @param options.typesToLog - A boolean indicating whether to include data types when logging a table.
116
116
  * @category Constructor
117
117
  */
@@ -148,6 +148,7 @@ export default class SimpleTable extends Simple {
148
148
  run(): Promise<this>;
149
149
  /**
150
150
  * Renames the current table.
151
+ * The new name must not belong to another registered table, ignoring ASCII letter case.
151
152
  *
152
153
  * @param name - The new name for the table.
153
154
  * @returns A promise that resolves to the renamed table.
@@ -165,9 +166,7 @@ export default class SimpleTable extends Simple {
165
166
  * Sets the data types for columns in a new table. If the table already exists, it will be replaced.
166
167
  * To convert the types of an existing table, use the `.convert()` method instead.
167
168
  *
168
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
169
- *
170
- * @param types - An object specifying the column names and their target data types (JavaScript or SQL types).
169
+ * @param types - An object specifying the column names and their target data types (JavaScript or SQL types), including JSON, FLOAT[n] vectors, and GEOMETRY with a CRS.
171
170
  * @returns The table, so methods can be chained.
172
171
  * @category Table Management
173
172
  *
@@ -180,25 +179,42 @@ export default class SimpleTable extends Simple {
180
179
  * raise: "float",
181
180
  * }).log();
182
181
  * ```
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * // Create an empty table with JSON, embedding, and geometry columns.
186
+ * await table.setTypes({
187
+ * details: "JSON",
188
+ * embedding: "FLOAT[3]",
189
+ * geom: "GEOMETRY('EPSG:4326')",
190
+ * }).log();
191
+ * ```
183
192
  */
184
193
  setTypes(types: {
185
- [key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | `geometry('${string}')` | `GEOMETRY('${string}')`;
194
+ [key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`;
186
195
  }): this;
187
196
  /**
188
- * Loads an array of JavaScript objects into the table. This method queues the load; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
197
+ * Loads an array of JavaScript objects into the table. Types are inferred for
198
+ * numbers, bigints, strings, booleans, and Date values. Array and object cells
199
+ * require an explicit supported type in columnTypes. Types can also be
200
+ * specified for scalar columns instead of inferred from their values.
189
201
  *
190
202
  * JavaScript `Date` values are inferred as DuckDB `TIMESTAMP` values. Their
191
203
  * instant is preserved, but JavaScript `Date` does not retain the timezone or
192
- * offset originally used to construct it. String values remain `VARCHAR`;
193
- * use `convert()` to parse them as temporal values.
204
+ * offset originally used to construct it.
205
+ *
206
+ * Declare `JSON` for general nested data, `FLOAT[n]` for a fixed-size float
207
+ * vector, or `GEOMETRY('EPSG:4326')` for GeoJSON geometries in WGS84.
194
208
  *
195
209
  * @param rows - An array of objects, where each object represents a row and its properties represent columns.
210
+ * @param options - Options for loading the array, captured when called.
211
+ * @param options.columnTypes - Types for specific columns. Required for array and object cells; omitted scalar columns are inferred, and all-null columns default to VARCHAR. Values must be compatible with the selected type without losing information.
196
212
  * @returns The table, so methods can be chained.
197
213
  * @category Importing Data
198
214
  *
199
215
  * @example
200
216
  * ```ts
201
- * // Load data from an array of objects
217
+ * // Load scalar columns without columnTypes; strings and numbers are inferred.
202
218
  * const data = [
203
219
  * { letter: "a", number: 1 },
204
220
  * { letter: "b", number: 2 }
@@ -208,30 +224,71 @@ export default class SimpleTable extends Simple {
208
224
  *
209
225
  * @example
210
226
  * ```ts
211
- * // The offset determines the instant; the loaded TIMESTAMP is returned as
212
- * // the equivalent UTC JavaScript Date.
227
+ * // Choose a numeric type when all-null values provide nothing to infer.
228
+ * await table.loadArray(
229
+ * [{ name: "A", value: null }, { name: "B", value: null }],
230
+ * { columnTypes: { value: "DOUBLE" } },
231
+ * ).log();
232
+ * ```
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * // Store the Date as a UTC timestamp with JavaScript's millisecond precision.
237
+ * // The original -04:00 offset is not retained.
213
238
  * await table.loadArray([{
214
239
  * observedAt: new Date("2024-04-07T13:00:00-04:00"),
215
240
  * }]).log();
216
241
  * ```
242
+ *
243
+ * @example
244
+ * ```ts
245
+ * // Declare JSON to load nested objects and variable-length arrays directly.
246
+ * await table.loadArray([{
247
+ * name: "Station",
248
+ * metadata: { active: true, tags: ["weather", "urban"] },
249
+ * measurements: [1, 2.5, null],
250
+ * }], { columnTypes: { metadata: "JSON", measurements: "JSON" } }).log();
251
+ * ```
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * // Declare FLOAT[3] to store each three-element array as a fixed-size vector.
256
+ * await table.loadArray([{ vector: [1, 2, 3] }], {
257
+ * columnTypes: { vector: "FLOAT[3]" },
258
+ * }).log();
259
+ * ```
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * // Declare a geometry type to store WGS84 GeoJSON as a spatial column.
264
+ * await table.loadArray([{
265
+ * name: "Montreal",
266
+ * geom: { type: "Point", coordinates: [-73.57, 45.50] },
267
+ * }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
268
+ * ```
217
269
  */
218
270
  loadArray(rows: {
219
271
  [key: string]: unknown;
220
- }[]): this;
272
+ }[], options?: {
273
+ columnTypes?: {
274
+ [key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "INTEGER" | "BIGINT" | "DOUBLE" | "VARCHAR" | "BOOLEAN" | "DATE" | "TIME" | "TIMESTAMP" | "TIMESTAMP WITH TIME ZONE" | "GEOMETRY('EPSG:4326')" | "geometry('EPSG:4326')" | "JSON" | "json" | `FLOAT[${number}]` | `float[${number}]`;
275
+ };
276
+ }): this;
221
277
  /**
222
278
  * Loads data from one or more local or remote files into the table.
223
279
  * Supported file formats include CSV, JSON, Parquet, and Excel.
224
- * This method queues the load; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
280
+ *
281
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
225
282
  *
226
283
  * @param files - The path(s) or URL(s) of the file(s) containing the data to be loaded.
227
284
  * @param options - An optional object with configuration options:
228
285
  * @param options.fileType - The type of file to load ("csv", "dsv", "json", "parquet", "excel"). Defaults to being inferred from the file extension.
229
286
  * @param options.autoDetect - A boolean indicating whether to automatically detect the data format. Defaults to `true`.
230
- * @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before applying `limit`. Uses the same syntax as `filter()`, including JavaScript operators. Can reference source columns excluded from `columns`. Defaults to no filtering; an empty string behaves the same as omitting this option.
287
+ * @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before applying `limit`. Can reference source columns excluded from `columns`.
231
288
  * @param options.limit - A number indicating the maximum number of matching rows to load, after applying `conditions` if provided. Defaults to all matching rows.
232
289
  * @param options.includeFilename - A boolean indicating whether to include the filename as a new column in the loaded data. Defaults to `false`.
233
290
  * @param options.unifyColumns - A boolean indicating whether to unify columns across multiple files when their structures differ. Missing columns will be filled with `NULL` values. Defaults to `false`.
234
- * @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred.
291
+ * @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred. Geometry types are not supported; use loadGeoData() instead.
235
292
  * @param options.columns - An array of column names to load. When provided, only the specified columns are loaded, reducing memory usage and improving load times. Not supported for Excel files — combining `columns` with Excel files throws an error. If an invalid column name is provided, DuckDB will throw its native error. An empty array behaves the same as omitting the option (loads all columns). Defaults to loading all columns.
236
293
  * @param options.header - A boolean indicating whether the file has a header row. Applicable to CSV files. Defaults to `true`.
237
294
  * @param options.allText - A boolean indicating whether all columns should be treated as text. Applicable to CSV files. Defaults to `false`.
@@ -328,8 +385,6 @@ export default class SimpleTable extends Simple {
328
385
  }): this;
329
386
  /**
330
387
  * Downloads a complete Statistics Canada table and loads it into this table.
331
- * The method queues the download and load; they run when an async observer
332
- * method (like `getData()` or `log()`) is awaited, or when `run()` is called.
333
388
  *
334
389
  * Results are cached as Parquet files in `.sda-cache/statcan` by default.
335
390
  * Cached data does not expire unless a TTL is provided.
@@ -368,15 +423,72 @@ export default class SimpleTable extends Simple {
368
423
  ttl?: number;
369
424
  }): this;
370
425
  /**
371
- * Loads geospatial data from an external file or URL into the table.
426
+ * Downloads historical market data from Yahoo Finance and loads it into this
427
+ * table as `datetime`, `open`, `high`, `low`, `close`, `adjustedClose`, and
428
+ * `volume` columns. `datetime` contains Yahoo's timestamps as JavaScript
429
+ * `Date` values. Unavailable values are preserved as `null`.
430
+ *
431
+ * All range boundaries are evaluated in UTC. Use ISO date-time strings ending
432
+ * in `Z`. Yahoo trading sessions may occur on a different UTC date from their
433
+ * exchange-local date, so choose the range appropriate for the market and
434
+ * interval. Avoid numeric constructors such as `new Date(2025, 2, 15)`, which
435
+ * use the runtime's local timezone.
436
+ *
437
+ * This method uses an undocumented Yahoo Finance endpoint and is not
438
+ * affiliated with or endorsed by Yahoo. It is provided for educational,
439
+ * research, and journalistic purposes. Before using it, review Yahoo's terms
440
+ * and any applicable data-provider restrictions.
441
+ *
442
+ * @param symbol - The stock or index symbol, such as `"AAPL"` or `"^GSPTSE"`.
443
+ * @param startDate - The inclusive UTC start of the requested range.
444
+ * @param endDate - The inclusive UTC end of the requested range. The UTC day,
445
+ * hour, or minute containing this instant is included, according to
446
+ * `interval`.
447
+ * @param interval - The interval between observations: daily, hourly, or every
448
+ * minute.
449
+ * @returns The table, so methods can be chained.
450
+ * @throws {RangeError} If either date is invalid or `endDate` is before `startDate`.
451
+ * @throws {Error} If Yahoo rejects the request or returns no data.
452
+ * @see https://legal.yahoo.com/us/en/yahoo/terms/otos/index.html
453
+ * @see https://help.yahoo.com/kb/finance/SLN2310.html
454
+ * @category Importing Data
372
455
  *
373
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
456
+ * @example
457
+ * ```ts
458
+ * // Request daily observations using explicit UTC boundaries.
459
+ * await table
460
+ * .loadYahooFinanceData(
461
+ * "^GSPTSE",
462
+ * new Date("2025-03-01T00:00:00Z"),
463
+ * new Date("2025-03-15T00:00:00Z"),
464
+ * "1d",
465
+ * )
466
+ * .log();
467
+ * ```
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * // Include the UTC hours from 13:00 through 16:00.
472
+ * await table
473
+ * .loadYahooFinanceData(
474
+ * "AAPL",
475
+ * new Date("2025-03-14T13:00:00Z"),
476
+ * new Date("2025-03-14T16:00:00Z"),
477
+ * "1h",
478
+ * )
479
+ * .log();
480
+ * ```
481
+ */
482
+ loadYahooFinanceData(symbol: string, startDate: Date, endDate: Date, interval: "1d" | "1h" | "1m"): this;
483
+ /**
484
+ * Loads geospatial data from an external file or URL into the table.
485
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
374
486
  *
375
487
  * @param file - The path or URL of the external file containing the geospatial data.
376
488
  * @param options - An optional object with configuration options:
377
489
  * @param options.toEPSG4326 - If `true`, the method will attempt to reproject the data to EPSG:4326 (WGS84).
378
490
  * @param options.columns - The columns to load. Include the geometry column that should remain in the resulting table, usually `"geom"`. By default, all columns are loaded.
379
- * @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before materialization and reprojection. Uses the same syntax as `filter()`, including JavaScript operators. Can reference source columns excluded from `columns`. Geometry conditions use the source coordinate system. Defaults to no filtering; an empty string behaves the same as omitting this option.
491
+ * @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before materialization and reprojection. Can reference source columns excluded from `columns`. Geometry conditions use the source coordinate system.
380
492
  * @returns The table, so methods can be chained.
381
493
  * @category Geospatial
382
494
  *
@@ -431,7 +543,7 @@ export default class SimpleTable extends Simple {
431
543
  conditions?: string;
432
544
  }): this;
433
545
  /**
434
- * Loads OpenStreetMap data into the table from a local `.osm` or `.osm.pbf` file, a remote file URL, or an Overpass bounding-box query. Pass a path or URL string to load an existing file, or pass a bounding box with `filters` to download matching features. The method queues the load; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
546
+ * Loads OpenStreetMap data into the table from a local `.osm` or `.osm.pbf` file, a remote file URL, or an Overpass bounding-box query. Pass a path or URL string to load an existing file, or pass a bounding box with `filters` to download matching features.
435
547
  *
436
548
  * DuckDB's [Osmium community extension](https://duckdb.org/community_extensions/extensions/osmium) materializes the complete result and reconstructs `geom` as EPSG:4326. By default, that canonical result is cached as GeoParquet in `.sda-cache/osm`. Distinct paths, local file fingerprints, normalized URLs, endpoints, queries, and bounding boxes retain independent entries. The cache has no expiration unless `ttl` is set and can be cleared by removing `.sda-cache/osm`. Immutable URLs can safely use the default indefinite cache; mutable URLs should set a TTL.
437
549
  *
@@ -529,8 +641,6 @@ export default class SimpleTable extends Simple {
529
641
  * DuckDB FTS indexes do not update automatically when the table changes; use
530
642
  * `overwrite: true` to rebuild the index after modifying the table.
531
643
  *
532
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
533
- *
534
644
  * @param idColumn - The column containing the document identifiers.
535
645
  * @param textColumn - The column containing the text to search.
536
646
  * @param options - An optional object with configuration options:
@@ -594,8 +704,6 @@ export default class SimpleTable extends Simple {
594
704
  * If a VSS index already exists on the table, this method will skip creation and log a message (when verbose is enabled), unless the `overwrite` option is set to `true`.
595
705
  * The index definition is recorded in {@link indexes}.
596
706
  *
597
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
598
- *
599
707
  * @param column - The name of the column containing vector embeddings (must be FLOAT array type).
600
708
  * @param options - An optional object with configuration options:
601
709
  * @param options.overwrite - If `true`, drops and recreates the index even if it already exists. Defaults to `false`.
@@ -659,8 +767,6 @@ export default class SimpleTable extends Simple {
659
767
  * changes; use `overwriteIndex: true` to rebuild the index after modifying
660
768
  * the table.
661
769
  *
662
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
663
- *
664
770
  * @param text - The search query text to match against the text column.
665
771
  * @param idColumn - The name of the column containing unique identifiers for each row.
666
772
  * @param textColumn - The name of the column containing the text to search.
@@ -774,8 +880,6 @@ export default class SimpleTable extends Simple {
774
880
  /**
775
881
  * Inserts rows, provided as an array of JavaScript objects, into the table.
776
882
  *
777
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
778
- *
779
883
  * @param rows - An array of objects, where each object represents a row to be inserted and its properties correspond to column names.
780
884
  * @returns The table, so methods can be chained.
781
885
  * @category Importing Data
@@ -794,7 +898,7 @@ export default class SimpleTable extends Simple {
794
898
  [key: string]: unknown;
795
899
  }[]): this;
796
900
  /**
797
- * Inserts all rows from one or more other tables into this table. If tables do not have the same columns, an error will be thrown unless the `unifyColumns` option is set to `true`. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
901
+ * Inserts all rows from one or more other tables into this table. If tables do not have the same columns, an error will be thrown unless the `unifyColumns` option is set to `true`.
798
902
  *
799
903
  * @param tables - The name(s) of the table(s) or SimpleTable instance(s) from which rows will be inserted.
800
904
  * @param options - An optional object with configuration options:
@@ -826,8 +930,6 @@ export default class SimpleTable extends Simple {
826
930
  /**
827
931
  * Fetches sample data from the simple-data-analysis-core GitHub repository.
828
932
  *
829
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
830
- *
831
933
  * @param sample - The name of the sample to load.
832
934
  *
833
935
  * Tabular data:
@@ -851,13 +953,12 @@ export default class SimpleTable extends Simple {
851
953
  loadSample(sample: "fires" | "recipes" | "temperatures" | "temperaturesCities" | "canada" | "firesGeo"): this;
852
954
  /**
853
955
  * Returns a new table with the same structure and data as this table. The data can be optionally filtered, limited to a specific number of rows, and offset.
956
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
854
957
  *
855
958
  * If `conditions`, `limit`, and `offset` are all used, they are applied in this order: `conditions` (WHERE clause) first, then `offset`, and finally `limit` (LIMIT).
856
959
  *
857
960
  * Note that cloning large tables can be a slow operation.
858
961
  *
859
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
860
- *
861
962
  * @param nameOrOptions - Either a string specifying the name of the new table, or an optional object with configuration options. If not provided, a default name (e.g., "table1", "table2") will be generated.
862
963
  * @param nameOrOptions.name - The name of the new table to be created in the database. If not provided, a default name (e.g., "table1", "table2") will be generated.
863
964
  * @param nameOrOptions.conditions - A SQL `WHERE` clause condition to filter the data during cloning. Defaults to no condition (clones all rows).
@@ -930,8 +1031,6 @@ export default class SimpleTable extends Simple {
930
1031
  /**
931
1032
  * Clones an existing column in this table, creating a new column with identical values.
932
1033
  *
933
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
934
- *
935
1034
  * @param column - The name of the original column to clone.
936
1035
  * @param newColumn - The name of the new column to be created.
937
1036
  * @returns The table, so methods can be chained.
@@ -950,8 +1049,6 @@ export default class SimpleTable extends Simple {
950
1049
  *
951
1050
  * **Important:** The offset is applied based on the current row order in the table. For meaningful results, ensure your data is sorted appropriately (e.g., by date/time for time-series analysis) before calling this method.
952
1051
  *
953
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
954
- *
955
1052
  * @param column - The name of the original column.
956
1053
  * @param newColumn - The name of the new column to be created with offset values.
957
1054
  * @param options - An optional object with configuration options:
@@ -997,8 +1094,6 @@ export default class SimpleTable extends Simple {
997
1094
  /**
998
1095
  * Fills `NULL` values in specified columns. By default, each `NULL` is replaced with the last non-`NULL` value from the preceding row. When `interpolate` is `true`, `NULL` values are replaced using linear interpolation (or extrapolation at the ends). Pass `interpolateBy` with a real numeric or date column name to use it as the X-axis, so that interpolated values are proportional to the actual distances between X-axis values rather than treating every row as equidistant. When `interpolateBy` is set, `interpolate` is automatically assumed `true`.
999
1096
  *
1000
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1001
- *
1002
1097
  * @param columns - The column(s) for which to fill `NULL` values.
1003
1098
  * @param options - An optional object with configuration options:
1004
1099
  * @param options.by - A column name or an array of column names to partition by. The fill is applied independently within each group.
@@ -1058,7 +1153,7 @@ export default class SimpleTable extends Simple {
1058
1153
  * Sorts the rows of the table based on specified column(s) and order(s).
1059
1154
  * If no columns are specified, all columns are sorted from left to right in ascending order.
1060
1155
  *
1061
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. Order-preserving transformations queued after a sort retain that order. Operations such as joins, grouping, aggregation, and sampling do not guarantee input order; chain `sort()` after them when deterministic output order matters.
1156
+ * Order-preserving transformations after a sort retain that order. Operations such as joins, grouping, aggregation, and sampling do not guarantee input order; chain `sort()` after them when deterministic output order matters.
1062
1157
  *
1063
1158
  * @param order - An object mapping column names to their sorting order: `"asc"` for ascending or `"desc"` for descending. If `null`, all columns are sorted ascendingly.
1064
1159
  * @param options - An optional object with configuration options:
@@ -1098,7 +1193,7 @@ export default class SimpleTable extends Simple {
1098
1193
  };
1099
1194
  }): this;
1100
1195
  /**
1101
- * Selects specific columns in the table, removing all others. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1196
+ * Selects specific columns in the table, removing all others.
1102
1197
  *
1103
1198
  * @param columns - The name or an array of names of the columns to be selected.
1104
1199
  * @returns The table, so methods can be chained.
@@ -1120,8 +1215,6 @@ export default class SimpleTable extends Simple {
1120
1215
  /**
1121
1216
  * Skips the first `n` rows of the table, effectively removing them.
1122
1217
  *
1123
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1124
- *
1125
1218
  * @param count - The number of rows to skip from the beginning of the table.
1126
1219
  * @returns The table, so methods can be chained.
1127
1220
  * @category Selecting or Filtering Data
@@ -1151,8 +1244,6 @@ export default class SimpleTable extends Simple {
1151
1244
  /**
1152
1245
  * Selects random rows from the table, removing all others. You can optionally specify a seed to ensure repeatable sampling.
1153
1246
  *
1154
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1155
- *
1156
1247
  * @param count - The number of rows to select (e.g., `100`) or a percentage string (e.g., `"10%"`) specifying the sampling size.
1157
1248
  * @param options - An optional object with configuration options:
1158
1249
  * @param options.seed - A number specifying the seed for repeatable sampling. Using the same seed will always yield the same random rows. Defaults to a random seed.
@@ -1183,8 +1274,6 @@ export default class SimpleTable extends Simple {
1183
1274
  /**
1184
1275
  * Selects a specified number of rows from this table. An offset can be applied to skip initial rows, and the results can be output to a new table.
1185
1276
  *
1186
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1187
- *
1188
1277
  * @param count - The number of rows to select.
1189
1278
  * @param options - An optional object with configuration options:
1190
1279
  * @param options.offset - The number of rows to skip from the beginning of the table before selecting. Defaults to `0`.
@@ -1224,8 +1313,6 @@ export default class SimpleTable extends Simple {
1224
1313
  * Removes duplicate rows from this table, keeping only unique rows.
1225
1314
  * Note that the resulting data order might differ from the original.
1226
1315
  *
1227
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1228
- *
1229
1316
  * @param options - An optional object with configuration options:
1230
1317
  * @param options.on - A column name or an array of column names to consider when identifying duplicates. If specified, duplicates are determined based only on the values in these columns. If omitted, all columns are considered.
1231
1318
  * @returns The table, so methods can be chained.
@@ -1255,7 +1342,6 @@ export default class SimpleTable extends Simple {
1255
1342
  /**
1256
1343
  * Removes rows with missing values from this table.
1257
1344
  * By default, missing values include SQL `NULL`, as well as string representations like `"NULL"`, `"null"`, `"NaN"`, `"undefined"`, and empty strings `""`.
1258
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1259
1345
  *
1260
1346
  * @param options - An optional object with configuration options:
1261
1347
  * @param options.columns - A string or an array of strings specifying the columns to consider for missing values. If omitted, all columns are considered.
@@ -1294,7 +1380,7 @@ export default class SimpleTable extends Simple {
1294
1380
  invert?: boolean;
1295
1381
  }): this;
1296
1382
  /**
1297
- * Trims specified characters from the beginning, end, or both sides of string values in the given columns. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1383
+ * Trims specified characters from the beginning, end, or both sides of string values in the given columns.
1298
1384
  *
1299
1385
  * @param columns - The column name or an array of column names to trim.
1300
1386
  * @param options - An optional object with configuration options:
@@ -1327,8 +1413,7 @@ export default class SimpleTable extends Simple {
1327
1413
  }): this;
1328
1414
  /**
1329
1415
  * Filters rows from this table based on SQL conditions. Note that it's often faster to use the `removeRows` method for simple removals.
1330
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
1331
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1416
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
1332
1417
  *
1333
1418
  * @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"column1 > 10 AND column2 = 'value'"`).
1334
1419
  * @returns The table, so methods can be chained.
@@ -1362,8 +1447,6 @@ export default class SimpleTable extends Simple {
1362
1447
  /**
1363
1448
  * Keeps rows in this table that have specific values in specified columns, removing all other rows.
1364
1449
  *
1365
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1366
- *
1367
1450
  * @param columnsAndValues - An object where keys are column names and values are the specific values (or an array of values) to keep in those columns. Use `null` to keep rows where a column is `NULL`.
1368
1451
  * @returns The table, so methods can be chained.
1369
1452
  * @category Selecting or Filtering Data
@@ -1392,8 +1475,6 @@ export default class SimpleTable extends Simple {
1392
1475
  /**
1393
1476
  * Removes rows from this table that have specific values in specified columns.
1394
1477
  *
1395
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1396
- *
1397
1478
  * @param columnsAndValues - An object where keys are column names and values are the specific values (or an array of values) to remove from those columns. Use `null` to remove rows where a column is `NULL`; otherwise, `NULL` rows are retained.
1398
1479
  * @returns The table, so methods can be chained.
1399
1480
  * @category Selecting or Filtering Data
@@ -1421,9 +1502,7 @@ export default class SimpleTable extends Simple {
1421
1502
  }): this;
1422
1503
  /**
1423
1504
  * Removes rows from this table based on SQL conditions. This method is similar to `filter()`, but removes rows instead of keeping them.
1424
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
1425
- *
1426
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1505
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
1427
1506
  *
1428
1507
  * @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"fruit = 'apple'"`).
1429
1508
  * @returns The table, so methods can be chained.
@@ -1458,8 +1537,6 @@ export default class SimpleTable extends Simple {
1458
1537
  * Renames one or more columns in the table. Throws if a source column does
1459
1538
  * not exist, so a typo fails loudly instead of being silently ignored.
1460
1539
  *
1461
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1462
- *
1463
1540
  * @param names - An object mapping old column names to their new column names (e.g., `{ "oldName": "newName", "anotherOld": "anotherNew" }`).
1464
1541
  * @param options - Configuration options.
1465
1542
  * @param options.strict - Whether to verify the source columns exist before renaming. Defaults to `true`. Set to `false` to skip the check and its schema lookup when you know the columns exist and are renaming across many tables where the extra round-trip adds up.
@@ -1492,8 +1569,6 @@ export default class SimpleTable extends Simple {
1492
1569
  /**
1493
1570
  * Cleans column names by removing non-alphanumeric characters and formatting them to camel case.
1494
1571
  *
1495
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1496
- *
1497
1572
  * @returns The table, so methods can be chained.
1498
1573
  * @category Column Operations
1499
1574
  *
@@ -1534,8 +1609,6 @@ export default class SimpleTable extends Simple {
1534
1609
  * | Sales | 2022 | 75 |
1535
1610
  * | Sales | 2023 | 98 |
1536
1611
  *
1537
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1538
- *
1539
1612
  * @param columns - An array of strings representing the names of the columns to be stacked (unpivoted).
1540
1613
  * @param namesTo - The name of the new column that will contain the original column names (e.g., "Year").
1541
1614
  * @param valuesTo - The name of the new column that will contain the values from the stacked columns (e.g., "Employees").
@@ -1574,8 +1647,6 @@ export default class SimpleTable extends Simple {
1574
1647
  *
1575
1648
  * When multiple rows share the same `namesFrom`/grouping combination, their `valuesFrom` values are combined with the `options.stat` function (`"sum"` by default).
1576
1649
  *
1577
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1578
- *
1579
1650
  * @param namesFrom - The name of the column containing the values that will be transformed into new column headers (e.g., "Year").
1580
1651
  * @param valuesFrom - The name of the column containing the values to be spread across the new columns (e.g., "Employees").
1581
1652
  * @param options - An optional object with configuration options:
@@ -1599,9 +1670,7 @@ export default class SimpleTable extends Simple {
1599
1670
  *
1600
1671
  * When converting strings to numbers, commas (often used as thousand separators) will be automatically removed before conversion.
1601
1672
  *
1602
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. If a column doesn't exist, the error is thrown at that point too.
1603
- *
1604
- * @param types - An object mapping column names to their target data types for conversion.
1673
+ * @param types - An object mapping column names to their target data types for conversion, including JSON, FLOAT[n] vectors, and GEOMETRY with a CRS.
1605
1674
  * @param options - An optional object with configuration options:
1606
1675
  * @param options.strict - If `false`, values that cannot be converted will be replaced by `NULL` instead of throwing an error. Defaults to `true`.
1607
1676
  * @param options.datetimeFormat - A string specifying the format for date and time conversions. Uses `strftime` and `strptime` functions from DuckDB. For format specifiers, see [DuckDB's documentation](https://duckdb.org/docs/sql/functions/dateformat).
@@ -1648,9 +1717,21 @@ export default class SimpleTable extends Simple {
1648
1717
  * // Convert 'amount' to float, replacing unconvertible values with NULL
1649
1718
  * await table.convert({ amount: "float" }, { strict: false }).log();
1650
1719
  * ```
1720
+ *
1721
+ * @example
1722
+ * ```ts
1723
+ * // Parse JSON, a fixed-size float vector, and WKT geometry from text.
1724
+ * await table.loadArray([{
1725
+ * details: '{"count":3}',
1726
+ * embedding: "[0.25,0.5,0.75]",
1727
+ * geom: "POINT (-73 45)",
1728
+ * }])
1729
+ * .convert({ details: "JSON", embedding: "FLOAT[3]", geom: "GEOMETRY('EPSG:4326')" })
1730
+ * .log();
1731
+ * ```
1651
1732
  */
1652
1733
  convert(types: {
1653
- [key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean";
1734
+ [key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`;
1654
1735
  }, options?: {
1655
1736
  strict?: boolean;
1656
1737
  datetimeFormat?: string;
@@ -1669,7 +1750,7 @@ export default class SimpleTable extends Simple {
1669
1750
  */
1670
1751
  removeTable(): Promise<this>;
1671
1752
  /**
1672
- * Removes one or more columns from this table. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1753
+ * Removes one or more columns from this table.
1673
1754
  *
1674
1755
  * @param columns - The name or an array of names of the columns to be removed.
1675
1756
  * @returns The table, so methods can be chained.
@@ -1689,10 +1770,11 @@ export default class SimpleTable extends Simple {
1689
1770
  */
1690
1771
  removeColumns(columns: string | string[]): this;
1691
1772
  /**
1692
- * Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1773
+ * Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition.
1774
+ * With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
1693
1775
  *
1694
1776
  * @param newColumn - The name of the new column to be added.
1695
- * @param type - The data type for the new column. Can be a JavaScript type (e.g., `"number"`, `"string"`) or a SQL type (e.g., `"integer"`, `"varchar"`).
1777
+ * @param type - The data type for the new column. Can be a JavaScript type (e.g., `"number"`, `"string"`) or a SQL type (e.g., `"integer"`, `"varchar"`, `"JSON"`, `"FLOAT[3]"`, `"GEOMETRY('EPSG:4326')"`).
1696
1778
  * @param definition - A SQL expression defining how the values for the new column should be computed (e.g., `"column1 + column2"`, `"ST_Centroid(geom_column)"`).
1697
1779
  * @returns The table, so methods can be chained.
1698
1780
  * @category Column Operations
@@ -1708,8 +1790,27 @@ export default class SimpleTable extends Simple {
1708
1790
  * // Add a new geometry column 'centroid' using the centroid of an existing 'country' geometry column
1709
1791
  * await table.addColumn("centroid", "geometry('EPSG:4326')", `ST_Centroid("country")`).log();
1710
1792
  * ```
1793
+ *
1794
+ * @example
1795
+ * ```ts
1796
+ * // Read a number from a JSON object into a new column using dot notation.
1797
+ * await table.loadArray([{ details: { count: 3 } }], {
1798
+ * columnTypes: { details: "JSON" },
1799
+ * })
1800
+ * .addColumn("count", "integer", "details.count")
1801
+ * .log();
1802
+ * ```
1803
+ *
1804
+ * @example
1805
+ * ```ts
1806
+ * // Create JSON and fixed-size vector columns with DuckDB expressions.
1807
+ * await table.loadArray([{ count: 3 }])
1808
+ * .addColumn("details", "JSON", "json_object('count', count)")
1809
+ * .addColumn("embedding", "FLOAT[3]", "[0.25, 0.5, 0.75]")
1810
+ * .log();
1811
+ * ```
1711
1812
  */
1712
- addColumn(newColumn: string, type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | `geometry('${string}')` | `GEOMETRY('${string}')`, definition: string): this;
1813
+ addColumn(newColumn: string, type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`, definition: string): this;
1713
1814
  /**
1714
1815
  * Extracts one or more components from a temporal column into new columns.
1715
1816
  * Pass a single part to create a column with that part's name, or pass an
@@ -1724,9 +1825,6 @@ export default class SimpleTable extends Simple {
1724
1825
  * values produce `NULL` extracted values. Parts extracted from
1725
1826
  * `TIMESTAMP WITH TIME ZONE` values use UTC.
1726
1827
  *
1727
- * This method queues the operation; it runs when an async observer method
1728
- * (like `getData()` or `log()`) is awaited, or when `run()` is called.
1729
- *
1730
1828
  * @param column - The temporal column from which to extract components.
1731
1829
  * @param parts - A part to extract using its name as the new column, or an object mapping each custom new-column name to the part it should contain.
1732
1830
  * @returns The table, so methods can be chained.
@@ -1753,8 +1851,6 @@ export default class SimpleTable extends Simple {
1753
1851
  /**
1754
1852
  * Adds a new column to the table containing the row number, starting at 0 (like an index).
1755
1853
  *
1756
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1757
- *
1758
1854
  * @param newColumn - The name of the new column that will store the row number.
1759
1855
  * @param options - An optional object with configuration options:
1760
1856
  * @param options.by - A column name or an array of column names to partition by. The row number restarts at 0 within each group.
@@ -1780,8 +1876,6 @@ export default class SimpleTable extends Simple {
1780
1876
  * Performs a cross join operation with another table. A cross join returns the Cartesian product of the rows from both tables, meaning all possible pairs of rows will be in the resulting table.
1781
1877
  * This means that if the left table has `n` rows and the right table has `m` rows, the result will have `n * m` rows.
1782
1878
  *
1783
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1784
- *
1785
1879
  * @param rightTable - The SimpleTable instance to cross join with.
1786
1880
  * @param options - An optional object with configuration options:
1787
1881
  * @param options.outputTable - If `true`, the results will be stored in a new table with a generated name. If a string, it will be used as the name for the new table. If `false` or omitted, the current table will be overwritten. Defaults to `false`.
@@ -1813,7 +1907,6 @@ export default class SimpleTable extends Simple {
1813
1907
  * Merges the data of this table (considered the left table) with another table (the right table) based on a common column or multiple columns.
1814
1908
  * Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
1815
1909
  * This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
1816
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. The join uses the other table's state as of this call: operations queued on it afterwards run after the join.
1817
1910
  *
1818
1911
  * @param rightTable - The SimpleTable instance to be joined with this table.
1819
1912
  * @param options - An optional object with configuration options:
@@ -1855,8 +1948,6 @@ export default class SimpleTable extends Simple {
1855
1948
  *
1856
1949
  * This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
1857
1950
  *
1858
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. The join uses the other table's state as of this call: operations queued on it afterwards run after the join.
1859
- *
1860
1951
  * @param rightTable - The SimpleTable instance to be joined with this table.
1861
1952
  * @param leftColumn - The name of the column in this (left) table containing the text to compare.
1862
1953
  * @param rightColumn - The name of the column in the right table containing the text to compare.
@@ -1921,8 +2012,6 @@ export default class SimpleTable extends Simple {
1921
2012
  * Similarity is computed using the [rapidfuzz](https://query.farm/duckdb_extension_rapidfuzz) DuckDB community extension,
1922
2013
  * which is installed and loaded automatically.
1923
2014
  *
1924
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1925
- *
1926
2015
  * @param column - The name of the column containing the strings to normalize.
1927
2016
  * @param newColumn - The name of the column to write the normalized values to. Use the same name as `column` to normalize in-place.
1928
2017
  * @param threshold - The minimum similarity score (0–100) for two strings to be considered duplicates. For `method: "ratio"`, a length-based pre-filter is automatically applied based on the threshold to improve performance without losing accuracy.
@@ -1977,8 +2066,6 @@ export default class SimpleTable extends Simple {
1977
2066
  /**
1978
2067
  * Replaces specified strings in the selected columns.
1979
2068
  *
1980
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
1981
- *
1982
2069
  * @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
1983
2070
  * @param replacements - An object mapping old strings to new strings (e.g., `{ "oldValue": "newValue" }`).
1984
2071
  * @param options - An optional object with configuration options:
@@ -2024,7 +2111,7 @@ export default class SimpleTable extends Simple {
2024
2111
  regex?: boolean;
2025
2112
  }): this;
2026
2113
  /**
2027
- * Converts string values in the specified columns to lowercase. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2114
+ * Converts string values in the specified columns to lowercase.
2028
2115
  *
2029
2116
  * @param columns - The column name or an array of column names to be converted to lowercase.
2030
2117
  * @returns The table, so methods can be chained.
@@ -2044,7 +2131,7 @@ export default class SimpleTable extends Simple {
2044
2131
  */
2045
2132
  lower(columns: string | string[]): this;
2046
2133
  /**
2047
- * Converts string values in the specified columns to uppercase. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2134
+ * Converts string values in the specified columns to uppercase.
2048
2135
  *
2049
2136
  * @param columns - The column name or an array of column names to be converted to uppercase.
2050
2137
  * @returns The table, so methods can be chained.
@@ -2064,7 +2151,7 @@ export default class SimpleTable extends Simple {
2064
2151
  */
2065
2152
  upper(columns: string | string[]): this;
2066
2153
  /**
2067
- * Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase. This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2154
+ * Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase.
2068
2155
  *
2069
2156
  * @param columns - The column name or an array of column names to be capitalized.
2070
2157
  * @returns The table, so methods can be chained.
@@ -2086,8 +2173,6 @@ export default class SimpleTable extends Simple {
2086
2173
  /**
2087
2174
  * Truncates string values in a specified column to a maximum number of characters.
2088
2175
  *
2089
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2090
- *
2091
2176
  * @param column - The column name containing strings to be truncated.
2092
2177
  * @param length - The maximum number of characters to keep.
2093
2178
  * @returns The table, so methods can be chained.
@@ -2113,8 +2198,6 @@ export default class SimpleTable extends Simple {
2113
2198
  * column is of a different type. `null` values remain `null`. If any string
2114
2199
  * already exceeds the target length, an error is thrown (no silent truncation).
2115
2200
  *
2116
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2117
- *
2118
2201
  * @param columns - The column name(s) containing strings to be padded.
2119
2202
  * @param length - The target length of the padded strings.
2120
2203
  * @param options - An optional object with configuration options:
@@ -2154,8 +2237,6 @@ export default class SimpleTable extends Simple {
2154
2237
  * Splits strings in a specified column by a separator and extracts a substring at a given index, storing the result in a new or existing column.
2155
2238
  * If the index is out of bounds, an empty string will be returned for that row.
2156
2239
  *
2157
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2158
- *
2159
2240
  * @param column - The name of the column containing the strings to be split.
2160
2241
  * @param separator - The substring to use as a delimiter for splitting the strings.
2161
2242
  * @param index - The zero-based index of the substring to extract after splitting. For example, `0` for the first part, `1` for the second, etc.
@@ -2185,8 +2266,6 @@ export default class SimpleTable extends Simple {
2185
2266
  * If a row has fewer parts than the number of new columns, a warning will be logged and the extra columns will contain empty strings (unless `strict` is set to `false`).
2186
2267
  * If a row has more parts than the number of new columns, an error will be thrown unless `strict` is set to `false`.
2187
2268
  *
2188
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2189
- *
2190
2269
  * @param column - The name of the column containing the strings to be split.
2191
2270
  * @param separator - The substring to use as a delimiter for splitting the strings.
2192
2271
  * @param newColumns - An array of column names for the extracted parts.
@@ -2221,8 +2300,6 @@ export default class SimpleTable extends Simple {
2221
2300
  /**
2222
2301
  * Extracts a specific number of characters from the beginning (left side) of string values in the specified column.
2223
2302
  *
2224
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2225
- *
2226
2303
  * @param column - The name of the column containing the strings to be modified.
2227
2304
  * @param count - The number of characters to extract from the left side of each string.
2228
2305
  * @returns The table, so methods can be chained.
@@ -2239,8 +2316,6 @@ export default class SimpleTable extends Simple {
2239
2316
  /**
2240
2317
  * Extracts a specific number of characters from the end (right side) of string values in the specified column.
2241
2318
  *
2242
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2243
- *
2244
2319
  * @param column - The name of the column containing the strings to be modified.
2245
2320
  * @param count - The number of characters to extract from the right side of each string.
2246
2321
  * @returns The table, so methods can be chained.
@@ -2257,8 +2332,6 @@ export default class SimpleTable extends Simple {
2257
2332
  /**
2258
2333
  * Replaces `NULL` values in the specified columns with a given value.
2259
2334
  *
2260
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2261
- *
2262
2335
  * @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
2263
2336
  * @param value - The value to replace `NULL` occurrences with.
2264
2337
  * @returns The table, so methods can be chained.
@@ -2292,8 +2365,6 @@ export default class SimpleTable extends Simple {
2292
2365
  /**
2293
2366
  * Concatenates values from specified columns into a new column.
2294
2367
  *
2295
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2296
- *
2297
2368
  * @param columns - An array of column names whose values will be concatenated.
2298
2369
  * @param newColumn - The name of the new column to store the concatenated values.
2299
2370
  * @param options - An optional object with configuration options:
@@ -2327,8 +2398,6 @@ export default class SimpleTable extends Simple {
2327
2398
  *
2328
2399
  * If a column value is `NULL`, it will be replaced by `'Unknown'` in the concatenated result.
2329
2400
  *
2330
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2331
- *
2332
2401
  * @param columns - An array of column names whose values will be concatenated with labels.
2333
2402
  * @param newColumn - The name of the new column to create with the concatenated values.
2334
2403
  * @returns The table, so methods can be chained.
@@ -2373,8 +2442,6 @@ export default class SimpleTable extends Simple {
2373
2442
  *
2374
2443
  * Each value in the specified column is split using the provided separator, and a new row is created for each resulting substring. All other column values are duplicated across the newly created rows.
2375
2444
  *
2376
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2377
- *
2378
2445
  * @param column - The name of the column containing string values to be split and unnested.
2379
2446
  * @param separator - The delimiter string used to split the column values.
2380
2447
  * @returns The table, so methods can be chained.
@@ -2404,8 +2471,6 @@ export default class SimpleTable extends Simple {
2404
2471
  *
2405
2472
  * If a row has a value of 3 in the specified column, it will be repeated 3 times. If the value is 0 or negative, the row will be removed.
2406
2473
  *
2407
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2408
- *
2409
2474
  * @param column - The name of the column containing the number of times each row should be repeated.
2410
2475
  * @param options - An optional object with configuration options:
2411
2476
  * @param options.index - The name of a new column to store the index of the repeated row (starting at 0).
@@ -2436,8 +2501,6 @@ export default class SimpleTable extends Simple {
2436
2501
  *
2437
2502
  * This is the inverse operation of `unnest()`. Multiple rows are combined into fewer rows by grouping on specified category columns and concatenating the target column values with a separator.
2438
2503
  *
2439
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2440
- *
2441
2504
  * @param column - The name of the column whose values will be aggregated and concatenated.
2442
2505
  * @param separator - The delimiter string used to join the column values.
2443
2506
  * @param by - The column name or an array of column names to group by.
@@ -2467,8 +2530,6 @@ export default class SimpleTable extends Simple {
2467
2530
  /**
2468
2531
  * Rounds numeric values in specified columns.
2469
2532
  *
2470
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2471
- *
2472
2533
  * @param columns - The column name or an array of column names containing numeric values to be rounded.
2473
2534
  * @param options - An optional integer specifying the number of decimal places, or an object with configuration options:
2474
2535
  * @param options.decimals - The number of decimal places to round to. Defaults to `0` (rounds to the nearest integer).
@@ -2511,9 +2572,36 @@ export default class SimpleTable extends Simple {
2511
2572
  method?: "round" | "ceiling" | "floor";
2512
2573
  }): this;
2513
2574
  /**
2514
- * Updates values in a specified column using a SQL expression.
2575
+ * Adds independently generated uniform random noise to numeric values in one or more columns.
2576
+ * Each changed value receives an offset between `-max` and `max`. Selected integer and decimal columns become `DOUBLE` columns so fractional noise is retained. This method adds random jitter; it does not provide anonymization or differential privacy guarantees.
2515
2577
  *
2516
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2578
+ * @param columns - The numeric column name or array of numeric column names to which noise will be added. When multiple columns are provided, each value receives an independent random offset.
2579
+ * @param max - The maximum absolute offset, expressed in each column's units. Must be a finite number greater than or equal to `0`.
2580
+ * @param options - An optional object with configuration options:
2581
+ * @param options.onlyDuplicates - If `true`, adds noise only to values that occur more than once in their column. Each selected column is evaluated independently, and every occurrence of a duplicated value is changed. Defaults to `false`.
2582
+ * @returns The table, so methods can be chained.
2583
+ * @category Updating Data
2584
+ *
2585
+ * @example
2586
+ * ```ts
2587
+ * // Add an offset between -0.01 and 0.01 to every value
2588
+ * await table.addNoise("measurement", 0.01).log();
2589
+ * ```
2590
+ *
2591
+ * @example
2592
+ * ```ts
2593
+ * // Add noise independently to duplicated x values and duplicated y values
2594
+ * await table.addNoise(["x", "y"], 0.1, {
2595
+ * onlyDuplicates: true,
2596
+ * }).log();
2597
+ * ```
2598
+ */
2599
+ addNoise(columns: string | string[], max: number, options?: {
2600
+ onlyDuplicates?: boolean;
2601
+ }): this;
2602
+ /**
2603
+ * Updates values in a specified column using a SQL expression.
2604
+ * With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
2517
2605
  *
2518
2606
  * @param column - The name of the column to be updated.
2519
2607
  * @param definition - The SQL expression used to set the new values in the column (e.g., `"column1 * 2"`, `"UPPER(column_name)"`).
@@ -2537,13 +2625,21 @@ export default class SimpleTable extends Simple {
2537
2625
  * // Set 'status' to 'active' where 'isActive' is true
2538
2626
  * await table.updateColumn("status", `CASE WHEN isActive THEN 'active' ELSE 'inactive' END`).log();
2539
2627
  * ```
2628
+ *
2629
+ * @example
2630
+ * ```ts
2631
+ * // Update an existing column with a value from a JSON object using dot notation.
2632
+ * await table.loadArray([{ count: 0, details: { count: 3 } }], {
2633
+ * columnTypes: { details: "JSON" },
2634
+ * })
2635
+ * .updateColumn("count", "details.count")
2636
+ * .log();
2637
+ * ```
2540
2638
  */
2541
2639
  updateColumn(column: string, definition: string): this;
2542
2640
  /**
2543
2641
  * Assigns ranks to rows in a new column based on the values of a specified column.
2544
2642
  *
2545
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2546
- *
2547
2643
  * @param column - The column containing the values to be used for ranking.
2548
2644
  * @param newColumn - The name of the new column where the ranks will be stored.
2549
2645
  * @param options - An optional object with configuration options:
@@ -2585,8 +2681,6 @@ export default class SimpleTable extends Simple {
2585
2681
  /**
2586
2682
  * Assigns quantiles to rows in a new column based on specified column values.
2587
2683
  *
2588
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2589
- *
2590
2684
  * @param column - The column containing values from which quantiles will be assigned.
2591
2685
  * @param count - The number of quantiles to divide the data into (e.g., `4` for quartiles, `10` for deciles).
2592
2686
  * @param newColumn - The name of the new column where the assigned quantiles will be stored.
@@ -2619,8 +2713,6 @@ export default class SimpleTable extends Simple {
2619
2713
  /**
2620
2714
  * Assigns bins for specified column values based on an interval size.
2621
2715
  *
2622
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2623
- *
2624
2716
  * @param column - The column containing values from which bins will be computed.
2625
2717
  * @param interval - The interval size for binning the values.
2626
2718
  * @param newColumn - The name of the new column where the bins will be stored.
@@ -2689,17 +2781,23 @@ export default class SimpleTable extends Simple {
2689
2781
  * | 2022 | 354 | 278 | 56 | 0.51 | 0.4 | 0.08 |
2690
2782
  * | 2023 | 856 | 321 | 221 | 0.61 | 0.23 | 0.16 |
2691
2783
  *
2692
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2784
+ * @example
2785
+ * ```ts
2786
+ * // Compute percentages that sum to 100 on each row before rounding
2787
+ * await table.rowProportions(["Men", "Women", "NonBinary"], { base: 100, decimals: 1 }).log();
2788
+ * ```
2693
2789
  *
2694
2790
  * @param columns - An array of column names for which proportions will be computed on each row.
2695
2791
  * @param options - An optional object with configuration options:
2696
2792
  * @param options.suffix - A string suffix to append to the names of the new columns storing the computed proportions. Defaults to `"Perc"`.
2793
+ * @param options.base - A finite positive value that the proportions in each row sum to before rounding. Defaults to `1`.
2697
2794
  * @param options.decimals - The number of decimal places to round the computed proportions. Defaults to `undefined` (no rounding).
2698
2795
  * @returns The table, so methods can be chained.
2699
2796
  * @category Analyzing Data
2700
2797
  */
2701
2798
  rowProportions(columns: string[], options?: {
2702
2799
  suffix?: string;
2800
+ base?: number;
2703
2801
  decimals?: number;
2704
2802
  }): this;
2705
2803
  /**
@@ -2713,9 +2811,6 @@ export default class SimpleTable extends Simple {
2713
2811
  * option can therefore increase the table's row count. If null values leave
2714
2812
  * a row without the requested rank, the new columns contain null.
2715
2813
  *
2716
- * This method queues the operation; it runs when an async observer method
2717
- * (like `getData()` or `log()`) is awaited, or when `run()` is called.
2718
- *
2719
2814
  * @param columns - The numeric columns to rank within each row.
2720
2815
  * @param options - The output columns and ranking configuration. At least one of `nameColumn` or `valueColumn` is required.
2721
2816
  * @param options.nameColumn - The name of a new column containing the selected source column's name.
@@ -2816,12 +2911,11 @@ export default class SimpleTable extends Simple {
2816
2911
  /**
2817
2912
  * Computes proportions vertically over a column's values, relative to the sum of all values in that column or group.
2818
2913
  *
2819
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2820
- *
2821
2914
  * @param column - The column containing values for which proportions will be computed. The proportions are calculated based on the sum of values in the specified column.
2822
2915
  * @param newColumn - The name of the new column where the proportions will be stored.
2823
2916
  * @param options - An optional object with configuration options:
2824
2917
  * @param options.by - The column name or an array of column names to partition by. Proportions are calculated independently within each group.
2918
+ * @param options.base - A finite positive value that the proportions in the column or each group sum to before rounding. Defaults to `1`.
2825
2919
  * @param options.decimals - The number of decimal places to round the computed proportions. Defaults to `undefined` (no rounding).
2826
2920
  * @returns The table, so methods can be chained.
2827
2921
  * @category Analyzing Data
@@ -2840,20 +2934,25 @@ export default class SimpleTable extends Simple {
2840
2934
  *
2841
2935
  * @example
2842
2936
  * ```ts
2937
+ * // Compute percentages that sum to 100 before rounding
2938
+ * await table.columnProportions("sales", "sales_percentage", { base: 100, decimals: 1 }).log();
2939
+ * ```
2940
+ *
2941
+ * @example
2942
+ * ```ts
2843
2943
  * // Compute proportions for 'sales' by 'region' and 'product_type'
2844
2944
  * await table.columnProportions("sales", "sales_proportion", { by: ["region", "product_type"] }).log();
2845
2945
  * ```
2846
2946
  */
2847
2947
  columnProportions(column: string, newColumn: string, options?: {
2848
2948
  by?: string | string[];
2949
+ base?: number;
2849
2950
  decimals?: number;
2850
2951
  }): this;
2851
2952
  /**
2852
2953
  * Creates a summary table from selected columns, optionally grouped by other columns.
2853
2954
  * This method allows you to aggregate data, calculate statistics (e.g., count, mean, sum), and group results by categorical columns.
2854
2955
  *
2855
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
2856
- *
2857
2956
  * @param options - An object with configuration options for summarization:
2858
2957
  * @param options.columns - The column name or an array of column names to summarize. If omitted, only the row count is returned.
2859
2958
  * @param options.by - The column name or an array of column names to group by.
@@ -2959,9 +3058,6 @@ export default class SimpleTable extends Simple {
2959
3058
  * string is also used as its row label; pass an object to customize that
2960
3059
  * label. If `options.stats` is omitted, every supported stat is added.
2961
3060
  *
2962
- * This method queues the operation; it runs when an async observer method
2963
- * (like `getData()` or `log()`) is awaited, or when `run()` is called.
2964
- *
2965
3061
  * @param columns - The numeric column name, an array of numeric column names, or `"all"` to summarize every numeric column.
2966
3062
  * @param labelColumn - The existing string column in which stat row labels will be written.
2967
3063
  * @param options - An optional object with configuration options:
@@ -3009,8 +3105,6 @@ export default class SimpleTable extends Simple {
3009
3105
  /**
3010
3106
  * Computes the cumulative sum of values in a column. For this method to work properly, ensure your data is sorted first.
3011
3107
  *
3012
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3013
- *
3014
3108
  * @param column - The name of the column storing the values to be accumulated.
3015
3109
  * @param newColumn - The name of the new column in which the computed cumulative values will be stored.
3016
3110
  * @param options - An optional object with configuration options:
@@ -3046,8 +3140,6 @@ export default class SimpleTable extends Simple {
3046
3140
  * For rows without enough preceding or following rows to form a complete window, `NULL` will be returned.
3047
3141
  * For this method to work properly, ensure your data is sorted by the relevant column(s) first.
3048
3142
  *
3049
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3050
- *
3051
3143
  * @param column - The name of the column storing the values to be aggregated.
3052
3144
  * @param newColumn - The name of the new column in which the computed rolling values will be stored.
3053
3145
  * @param stat - The aggregation function to apply: `"min"`, `"max"`, `"mean"`, `"median"`, or `"sum"`.
@@ -3086,8 +3178,6 @@ export default class SimpleTable extends Simple {
3086
3178
  * Calculates correlations between columns. If no `x` and `y` columns are specified, the method computes the correlations for all numeric column combinations.
3087
3179
  * Note that correlation is symmetrical: the correlation of `x` with `y` is the same as `y` with `x`.
3088
3180
  *
3089
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3090
- *
3091
3181
  * @param options - An optional object with configuration options:
3092
3182
  * @param options.x - The name of the column for the x-values. If omitted, correlations will be computed for all numeric columns.
3093
3183
  * @param options.y - The name of the column for the y-values. It can be provided only when `options.x` is also set. If both are omitted, correlations will be computed for all numeric column pairs.
@@ -3139,8 +3229,6 @@ export default class SimpleTable extends Simple {
3139
3229
  * If no `x` and `y` columns are specified, the method computes linear regression analysis for all numeric column permutations.
3140
3230
  * Note that linear regression analysis is asymmetrical: the linear regression of `x` over `y` is not the same as `y` over `x`.
3141
3231
  *
3142
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3143
- *
3144
3232
  * @param options - An optional object with configuration options:
3145
3233
  * @param options.x - The name of the column for the independent variable (x-values). If omitted, linear regressions will be computed for all numeric columns as x.
3146
3234
  * @param options.y - The name of the column for the dependent variable (y-values). It can be provided only when `options.x` is also set. If both are omitted, linear regressions will be computed for all numeric column permutations.
@@ -3190,8 +3278,6 @@ export default class SimpleTable extends Simple {
3190
3278
  /**
3191
3279
  * Identifies outliers in a specified column using the Interquartile Range (IQR) method.
3192
3280
  *
3193
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3194
- *
3195
3281
  * @param column - The name of the column in which outliers will be identified.
3196
3282
  * @param newColumn - The name of the new column where the boolean results (`TRUE` for outlier, `FALSE` otherwise) will be stored.
3197
3283
  * @param options - An optional object with configuration options:
@@ -3217,8 +3303,6 @@ export default class SimpleTable extends Simple {
3217
3303
  /**
3218
3304
  * Computes the Z-score for values in a specified column.
3219
3305
  *
3220
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3221
- *
3222
3306
  * @param column - The name of the column for which Z-scores will be calculated.
3223
3307
  * @param newColumn - The name of the new column where the computed Z-scores will be stored.
3224
3308
  * @param options - An optional object with configuration options:
@@ -3252,8 +3336,6 @@ export default class SimpleTable extends Simple {
3252
3336
  /**
3253
3337
  * Normalizes the values in a column using min-max normalization.
3254
3338
  *
3255
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3256
- *
3257
3339
  * @param column - The name of the column in which values will be normalized.
3258
3340
  * @param newColumn - The name of the new column where normalized values will be stored.
3259
3341
  * @param options - An optional object with configuration options:
@@ -3299,8 +3381,6 @@ export default class SimpleTable extends Simple {
3299
3381
  *
3300
3382
  * Exact temporal references are compared at their full DuckDB precision. JavaScript `Date` objects only have millisecond precision and always represent an instant. Construct them with an explicit timezone, such as `new Date("2001-01-01T00:00:00Z")`; date-time strings without `Z` or an offset use the user's local timezone.
3301
3383
  *
3302
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3303
- *
3304
3384
  * @param column - The numeric column containing the values to index.
3305
3385
  * @param newColumn - The name of the new column where indexed values will be stored.
3306
3386
  * @param reference - A statistic calculated from `column`, a column and exact non-null `equals` value selecting a row, or a column and `at` set to `min` or `max` selecting its unique extreme row. The selected row's `column` value becomes the reference.
@@ -3374,50 +3454,84 @@ export default class SimpleTable extends Simple {
3374
3454
  /**
3375
3455
  * Updates data in the table using a JavaScript function. The function receives the existing rows as an array of objects and must return the modified rows as an array of objects.
3376
3456
  * This method offers high flexibility for data manipulation but can be slow for large tables as it involves transferring data between DuckDB and JavaScript.
3377
- * This method does not work with tables containing geometries.
3457
+ * Before writing a JavaScript callback, check for an existing SDA method that
3458
+ * performs the same operation; it will usually be faster and more efficient.
3378
3459
  *
3379
- * This method queues the update; the dataModifier function runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3460
+ * If the table has geometry columns, the callback can read and modify their
3461
+ * GeoJSON geometry objects directly. Extra properties added to these objects
3462
+ * are ignored; create new columns on the returned rows to store additional
3463
+ * attributes. All geometry columns must use EPSG:4326; use reproject() first
3464
+ * if needed.
3380
3465
  *
3381
3466
  * @param dataModifier - A synchronous or asynchronous function that takes the existing rows (as an array of objects) and returns the modified rows (as an array of objects).
3382
3467
  * @param options - An optional object with configuration options:
3383
- * @param options.batchSize - If provided, rows are processed in batches of this size instead of all at once, so large tables don't have to be materialized entirely in memory. The modifier function is called once per batch.
3468
+ * @param options.batchSize - If provided, rows are processed in batches of this size instead of all at once, so large tables don't have to be materialized entirely in memory. This limits input rows per batch, but does not eliminate conversion work or bound geometry size or callback output expansion. The modifier function is called once per batch. Tables with a column named `rowid` or `__sda_rowid` (case-insensitive) are rejected before the modifier runs; rename the column or omit batchSize.
3469
+ * @param options.columnTypes - Explicit types for newly added columns, following loadArray's columnTypes contract. Declare geometry as GEOMETRY('EPSG:4326'); geometry is never inferred from object shape. Existing columns cannot be redeclared.
3384
3470
  * @returns The table, so methods can be chained.
3385
3471
  * @category Updating Data
3386
3472
  *
3387
3473
  * @example
3388
3474
  * ```ts
3389
- * // Count words correctly across multilingual article text.
3390
- * const segmenter = new Intl.Segmenter(undefined, { granularity: "word" });
3391
- * const table = await sdb
3392
- * .newTable()
3393
- * .loadData("articles.csv")
3394
- * .updateWithJS((rows) => {
3395
- * return rows.map((row) => ({
3396
- * ...row,
3397
- * wordCount: typeof row.text === "string"
3398
- * ? [...segmenter.segment(row.text)].filter((part) => part.isWordLike)
3399
- * .length
3400
- * : null,
3401
- * }));
3402
- * })
3475
+ * // Double the value in each row with a JavaScript callback.
3476
+ * await table.loadArray([{ value: 1 }, { value: 2 }])
3477
+ * .updateWithJS((rows) => rows.map((row) => ({
3478
+ * value: Number(row.value) * 2,
3479
+ * })))
3403
3480
  * .log();
3404
3481
  * ```
3405
3482
  *
3406
3483
  * @example
3407
3484
  * ```ts
3408
- * // Enrich reviews with scores from an external service, 100 at a time.
3409
- * const reviews = await table
3410
- * .updateWithJS(async (rows) => {
3411
- * const response = await fetch("https://api.example.com/score", {
3412
- * method: "POST",
3413
- * headers: { "content-type": "application/json" },
3414
- * body: JSON.stringify(rows.map((row) => row.review)),
3415
- * });
3416
- * const scores = await response.json() as number[];
3417
- * return rows.map((row, index) => ({ ...row, score: scores[index] }));
3418
- * }, { batchSize: 100 })
3485
+ * // Process two rows per callback to limit how many rows are handled at once.
3486
+ * await table.loadArray([{ value: 1 }, { value: 2 }, { value: 3 }])
3487
+ * .updateWithJS((rows) => rows.map((row) => ({
3488
+ * value: Number(row.value) * 2,
3489
+ * })), { batchSize: 2 })
3419
3490
  * .log();
3420
3491
  * ```
3492
+ *
3493
+ * @example
3494
+ * ```ts
3495
+ * // Add a JSON object column to keep related attributes together.
3496
+ * await table.loadArray([{ name: "Station" }])
3497
+ * .updateWithJS((rows) => rows.map((row) => ({
3498
+ * ...row, details: { active: true, category: "weather" },
3499
+ * })), { columnTypes: { details: "JSON" } })
3500
+ * .log();
3501
+ * ```
3502
+ *
3503
+ * @example
3504
+ * ```ts
3505
+ * // Add a three-element float vector, such as an embedding.
3506
+ * await table.loadArray([{ name: "Station" }])
3507
+ * .updateWithJS((rows) => rows.map((row) => ({
3508
+ * ...row, embedding: [0.25, 0.5, 0.75],
3509
+ * })), { columnTypes: { embedding: "FLOAT[3]" } })
3510
+ * .log();
3511
+ * ```
3512
+ *
3513
+ * @example
3514
+ * ```ts
3515
+ * // Move each point slightly east by editing its longitude.
3516
+ * await sdb.newTable().loadArray([{
3517
+ * geom: { type: "Point", coordinates: [-73, 45] },
3518
+ * }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } })
3519
+ * .updateWithJS((rows) => rows.map((row) => {
3520
+ * // This example loads only Points. Narrow the type for coordinate access.
3521
+ * const geom = row.geom as { type: "Point"; coordinates: number[] } | null;
3522
+ * if (geom !== null) geom.coordinates[0] += 0.01;
3523
+ * return row;
3524
+ * })).log();
3525
+ * ```
3526
+ *
3527
+ * @example
3528
+ * ```ts
3529
+ * // Create a geometry column from longitude and latitude values.
3530
+ * await sdb.newTable().loadArray([{ longitude: -73, latitude: 45 }])
3531
+ * .updateWithJS((rows) => rows.map((row) => ({
3532
+ * ...row, geom: { type: "Point", coordinates: [row.longitude, row.latitude] },
3533
+ * })), { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
3534
+ * ```
3421
3535
  */
3422
3536
  updateWithJS(dataModifier: ((rows: {
3423
3537
  [key: string]: unknown;
@@ -3429,6 +3543,9 @@ export default class SimpleTable extends Simple {
3429
3543
  [key: string]: unknown;
3430
3544
  }[]), options?: {
3431
3545
  batchSize?: number;
3546
+ columnTypes?: {
3547
+ [key: string]: string;
3548
+ };
3432
3549
  }): this;
3433
3550
  /**
3434
3551
  * Returns the schema of the table, including column names and their data types.
@@ -3501,8 +3618,6 @@ export default class SimpleTable extends Simple {
3501
3618
  * Produces identical output to `journalism-format`'s `normalizeString()` function
3502
3619
  * for all common cases including accented Latin characters.
3503
3620
  *
3504
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
3505
- *
3506
3621
  * @param column The column containing the text to normalize
3507
3622
  * @param newColumn The column to store the normalized results
3508
3623
  * @param options Configuration options
@@ -3544,8 +3659,42 @@ export default class SimpleTable extends Simple {
3544
3659
  * ```
3545
3660
  */
3546
3661
  getColumnCount(): Promise<number>;
3662
+ /**
3663
+ * Adds a new column containing the number of characters in each string in the specified column.
3664
+ * Counts are based on Unicode code points, not grapheme clusters. A user-perceived character composed of multiple code points, such as some emoji or decomposed accented letters, counts as multiple characters.
3665
+ * `NULL` input values produce `NULL` counts.
3666
+ *
3667
+ * @param column - The name of the column containing the strings to count.
3668
+ * @param newColumn - The name of the new column where the character counts will be stored.
3669
+ * @returns The table, so methods can be chained.
3670
+ * @category Text Processing
3671
+ *
3672
+ * @example
3673
+ * ```ts
3674
+ * // Add a character count for each value in the 'name' column
3675
+ * await table.addCharacterCount("name", "nameCharacterCount").log();
3676
+ * ```
3677
+ */
3678
+ addCharacterCount(column: string, newColumn: string): this;
3679
+ /**
3680
+ * Adds a new column containing the word count for each string in the specified column.
3681
+ * A word is any contiguous sequence of non-whitespace characters. Spaces, tabs, and line breaks separate words. Punctuation is not removed, so a standalone punctuation sequence counts as a word. Text without whitespace counts as one word, regardless of language. Empty or whitespace-only strings produce `0`, and `NULL` input values produce `NULL` counts.
3682
+ *
3683
+ * @param column - The name of the column containing the strings to count.
3684
+ * @param newColumn - The name of the new column where the word counts will be stored.
3685
+ * @returns The table, so methods can be chained.
3686
+ * @category Text Processing
3687
+ *
3688
+ * @example
3689
+ * ```ts
3690
+ * // Add a word count for each value in the 'article' column
3691
+ * await table.addWordCount("article", "wordCount").log();
3692
+ * ```
3693
+ */
3694
+ addWordCount(column: string, newColumn: string): this;
3547
3695
  /**
3548
3696
  * Returns the total number of characters in a column storing strings.
3697
+ * Counts are based on Unicode code points, not grapheme clusters. A user-perceived character composed of multiple code points, such as some emoji or decomposed accented letters, counts as multiple characters.
3549
3698
  *
3550
3699
  * @param column - The name of the string column to count characters from.
3551
3700
  * @returns A promise that resolves to the total number of characters across all rows in the specified column.
@@ -3561,6 +3710,7 @@ export default class SimpleTable extends Simple {
3561
3710
  getCharacterCount(column: string): Promise<number>;
3562
3711
  /**
3563
3712
  * Returns the number of rows in the table.
3713
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
3564
3714
  *
3565
3715
  * @param options - An optional object with configuration options:
3566
3716
  * @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
@@ -3887,7 +4037,7 @@ export default class SimpleTable extends Simple {
3887
4037
  getUniques(column: string): Promise<unknown[]>;
3888
4038
  /**
3889
4039
  * Returns the first row of the table, optionally filtered by SQL conditions.
3890
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
4040
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
3891
4041
  * Temporal values use the same JavaScript representations as `getData()`.
3892
4042
  *
3893
4043
  * @param options - An optional object with configuration options:
@@ -3916,7 +4066,7 @@ export default class SimpleTable extends Simple {
3916
4066
  } | null>;
3917
4067
  /**
3918
4068
  * Returns the last row of the table, optionally filtered by SQL conditions.
3919
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
4069
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
3920
4070
  * Temporal values use the same JavaScript representations as `getData()`.
3921
4071
  *
3922
4072
  * @param options - An optional object with configuration options:
@@ -3945,7 +4095,7 @@ export default class SimpleTable extends Simple {
3945
4095
  } | null>;
3946
4096
  /**
3947
4097
  * Returns the top `n` rows of the table, optionally filtered by SQL conditions.
3948
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
4098
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
3949
4099
  * Temporal values use the same JavaScript representations as `getData()`.
3950
4100
  *
3951
4101
  * @param count - The number of rows to return from the top of the table.
@@ -3976,7 +4126,7 @@ export default class SimpleTable extends Simple {
3976
4126
  /**
3977
4127
  * Returns the bottom `n` rows of the table, optionally filtered by SQL conditions.
3978
4128
  * By default, the last row will be returned first. To preserve the original order, use the `originalOrder` option.
3979
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
4129
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
3980
4130
  * Temporal values use the same JavaScript representations as `getData()`.
3981
4131
  *
3982
4132
  * @param count - The number of rows to return from the bottom of the table.
@@ -4015,7 +4165,7 @@ export default class SimpleTable extends Simple {
4015
4165
  }[]>;
4016
4166
  /**
4017
4167
  * Returns a single row that matches the specified conditions. If no row matches or if more than one row matches, an error is thrown by default.
4018
- * You can also use JavaScript syntax for conditions (e.g., `AND`, `||`, `===`, `!==`).
4168
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
4019
4169
  * Temporal values use the same JavaScript representations as `getData()`.
4020
4170
  *
4021
4171
  * @param conditions - The conditions to match, specified as a SQL `WHERE` clause.
@@ -4053,13 +4203,26 @@ export default class SimpleTable extends Simple {
4053
4203
  } | null>;
4054
4204
  /**
4055
4205
  * Returns the data from the table as an array of objects, optionally filtered by SQL conditions.
4056
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
4206
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
4057
4207
  *
4058
4208
  * Top-level DuckDB `DATE` and `TIMESTAMP` columns are returned as JavaScript
4059
4209
  * `Date` objects interpreted in UTC. `TIMESTAMP WITH TIME ZONE` values are
4060
4210
  * returned as UTC strings, preserving DuckDB's microsecond precision;
4061
4211
  * JavaScript `Date` supports only milliseconds.
4062
4212
  *
4213
+ * Top-level `BIGINT`, `UBIGINT`, `HUGEINT`, and `UHUGEINT` columns are
4214
+ * returned as JavaScript numbers. Values outside `Number.MIN_SAFE_INTEGER`
4215
+ * through `Number.MAX_SAFE_INTEGER` throw instead of losing precision.
4216
+ * Use `convert({ columnName: "string" })` before `getData()` to retrieve
4217
+ * their exact digits as strings.
4218
+ *
4219
+ * SQL arrays and lists, including float vectors, return their actual elements
4220
+ * as JavaScript arrays. Null cells and null elements remain null.
4221
+ *
4222
+ * Nested SQL lists and structs become JavaScript arrays and objects. Within
4223
+ * them, `BIGINT`, `UBIGINT`, `HUGEINT`, `UHUGEINT`, and `DECIMAL` values remain
4224
+ * strings to preserve precision, even for small integers.
4225
+ *
4063
4226
  * @param options - An optional object with configuration options:
4064
4227
  * @param options.columns - An array of column names to include in the result. If omitted, all columns will be included.
4065
4228
  * @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
@@ -4093,6 +4256,18 @@ export default class SimpleTable extends Simple {
4093
4256
  * // Return at most two rows.
4094
4257
  * const preview = await table.getData({ limit: 2 });
4095
4258
  * ```
4259
+ *
4260
+ * @example
4261
+ * ```ts
4262
+ * // Read nested integers without losing digits. SQL creates the nested types.
4263
+ * await sdb.customQuery(`CREATE TABLE nested_example AS SELECT
4264
+ * [42::BIGINT, 9007199254740993::BIGINT] AS ids,
4265
+ * {'count': 2::INTEGER, 'amount': 123.450::DECIMAL(6,3)} AS details`);
4266
+ * const nested = sdb.newTable("nested_example");
4267
+ * const rows = await nested.getData();
4268
+ * // [{ ids: ["42", "9007199254740993"], details: { count: 2, amount: "123.450" } }]
4269
+ * await nested.log();
4270
+ * ```
4096
4271
  */
4097
4272
  getData(options?: {
4098
4273
  columns?: string | string[];
@@ -4105,6 +4280,7 @@ export default class SimpleTable extends Simple {
4105
4280
  * Streams the table rows one by one as an async iterator, without
4106
4281
  * materializing the whole table in memory. Values are converted to
4107
4282
  * JavaScript types the same way as `getData()`.
4283
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
4108
4284
  *
4109
4285
  * The underlying DuckDB result is streamed chunk by chunk, so tables
4110
4286
  * larger than the available memory can be iterated. Avoid running other
@@ -4140,7 +4316,7 @@ export default class SimpleTable extends Simple {
4140
4316
  }, void, undefined>;
4141
4317
  /**
4142
4318
  * Returns the data from the table as a CSV string, optionally filtered by SQL conditions.
4143
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
4319
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
4144
4320
  * Temporal values are first converted as they are in `getData()`, then
4145
4321
  * serialized using UTC date and timestamp text.
4146
4322
  *
@@ -4178,8 +4354,6 @@ export default class SimpleTable extends Simple {
4178
4354
  /**
4179
4355
  * Creates point geometries from latitude (y) and longitude (x) columns.
4180
4356
  *
4181
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4182
- *
4183
4357
  * @param latColumn - The name of the column storing the latitude (y-coordinate) values.
4184
4358
  * @param lonColumn - The name of the column storing the longitude (x-coordinate) values.
4185
4359
  * @param newColumn - The name of the new column where the point geometries will be stored.
@@ -4208,8 +4382,6 @@ export default class SimpleTable extends Simple {
4208
4382
  /**
4209
4383
  * Adds a column with boolean values indicating the validity of geometries.
4210
4384
  *
4211
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4212
- *
4213
4385
  * @param newColumn - The name of the new column where the boolean results (`TRUE` for valid, `FALSE` for invalid) will be stored.
4214
4386
  * @param options - An optional object with configuration options:
4215
4387
  * @param options.column - The name of the column storing the geometries to be checked. If omitted, the method will automatically attempt to find a geometry column.
@@ -4235,8 +4407,6 @@ export default class SimpleTable extends Simple {
4235
4407
  /**
4236
4408
  * Adds a column with the number of vertices (points) in each geometry.
4237
4409
  *
4238
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4239
- *
4240
4410
  * @param newColumn - The name of the new column where the vertex counts will be stored.
4241
4411
  * @param options - An optional object with configuration options:
4242
4412
  * @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
@@ -4262,8 +4432,6 @@ export default class SimpleTable extends Simple {
4262
4432
  /**
4263
4433
  * Attempts to make invalid geometries valid without removing any vertices.
4264
4434
  *
4265
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4266
- *
4267
4435
  * @param column - The name of the column storing the geometries to be fixed. If omitted, the method will automatically attempt to find a geometry column.
4268
4436
  * @returns The table, so methods can be chained.
4269
4437
  * @category Geospatial
@@ -4284,8 +4452,6 @@ export default class SimpleTable extends Simple {
4284
4452
  /**
4285
4453
  * Adds a column with boolean values indicating whether geometries are closed (e.g., polygons) or open (e.g., linestrings).
4286
4454
  *
4287
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4288
- *
4289
4455
  * @param newColumn - The name of the new column where the boolean results (`TRUE` for closed, `FALSE` for open) will be stored.
4290
4456
  * @param options - An optional object with configuration options:
4291
4457
  * @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
@@ -4310,8 +4476,6 @@ export default class SimpleTable extends Simple {
4310
4476
  /**
4311
4477
  * Adds a column with the geometry type (e.g., `"POINT"`, `"LINESTRING"`, `"POLYGON"`) for each geometry.
4312
4478
  *
4313
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4314
- *
4315
4479
  * @param newColumn - The name of the new column where the geometry types will be stored.
4316
4480
  * @param options - An optional object with configuration options:
4317
4481
  * @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
@@ -4337,8 +4501,6 @@ export default class SimpleTable extends Simple {
4337
4501
  * Flips the coordinate order of geometries in a specified column (e.g., from `[longitude (x), latitude (y)]` to `[latitude (y), longitude (x)]` or vice-versa).
4338
4502
  * **Warning:** This method should be used with caution as it directly manipulates coordinate order and can affect the accuracy of geospatial operations if not used correctly.
4339
4503
  *
4340
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4341
- *
4342
4504
  * @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
4343
4505
  * @returns The table, so methods can be chained.
4344
4506
  * @category Geospatial
@@ -4357,9 +4519,43 @@ export default class SimpleTable extends Simple {
4357
4519
  */
4358
4520
  flipCoordinates(column?: string): this;
4359
4521
  /**
4360
- * Reduces the precision of geometries in a specified column to a given number of decimal places.
4522
+ * Moves EPSG:4326 point geometries to random locations within a maximum great-circle distance of their original positions.
4523
+ *
4524
+ * Points are sampled uniformly within the requested distance using the spherical direct geodesic (destination-point) formula and the same spherical Earth model as DuckDB's `ST_Distance_Sphere()`. This accounts for longitude scale changing with latitude. This method adds random jitter; it does not provide anonymization or differential privacy guarantees.
4361
4525
  *
4362
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4526
+ * This method supports only `POINT` geometries in `EPSG:4326`. Null and empty geometries are preserved.
4527
+ *
4528
+ * @param maxDistance - The maximum great-circle displacement in the selected unit. Must be a finite number greater than or equal to `0` and no greater than half Earth's circumference.
4529
+ * @param options - An optional object with configuration options:
4530
+ * @param options.column - The name of the EPSG:4326 point geometry column. If omitted, the method will automatically attempt to find a geometry column.
4531
+ * @param options.unit - The unit of `maxDistance`: `"m"` for metres or `"km"` for kilometres. Defaults to `"m"`.
4532
+ * @param options.onlyDuplicates - If `true`, moves only points whose complete original geometry occurs more than once in the selected geometry column. Every point in a duplicated group is moved. Defaults to `false`.
4533
+ * @returns The table, so methods can be chained.
4534
+ * @category Geospatial
4535
+ *
4536
+ * @example
4537
+ * ```ts
4538
+ * // Move every point by no more than 500 metres
4539
+ * await table.addGeoNoise(500).log();
4540
+ * ```
4541
+ *
4542
+ * @example
4543
+ * ```ts
4544
+ * // Separate duplicated points by up to 0.1 kilometres
4545
+ * await table.addGeoNoise(0.1, {
4546
+ * column: "geom",
4547
+ * unit: "km",
4548
+ * onlyDuplicates: true,
4549
+ * }).log();
4550
+ * ```
4551
+ */
4552
+ addGeoNoise(maxDistance: number, options?: {
4553
+ column?: string;
4554
+ unit?: "m" | "km";
4555
+ onlyDuplicates?: boolean;
4556
+ }): this;
4557
+ /**
4558
+ * Reduces the precision of geometries in a specified column to a given number of decimal places.
4363
4559
  *
4364
4560
  * @param decimals - The number of decimal places to keep in the coordinates of the geometries.
4365
4561
  * @param options - An optional object with configuration options:
@@ -4385,8 +4581,6 @@ export default class SimpleTable extends Simple {
4385
4581
  /**
4386
4582
  * Reprojects the geometries in a specified column to another Spatial Reference System (SRS).
4387
4583
  *
4388
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4389
- *
4390
4584
  * @param crs - The target SRS (e.g., `"EPSG:3347"`, or `"EPSG:4326"` for EPSG:4326 (WGS84)).
4391
4585
  * @param options - An optional object with configuration options:
4392
4586
  * @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
@@ -4412,8 +4606,6 @@ export default class SimpleTable extends Simple {
4412
4606
  * Computes the area of geometries in square meters (`"m2"`) or optionally square kilometers (`"km2"`).
4413
4607
  * The input geometry is assumed to be in EPSG:4326 (WGS84).
4414
4608
  *
4415
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4416
- *
4417
4609
  * @param newColumn - The name of the new column where the computed areas will be stored.
4418
4610
  * @param options - An optional object with configuration options:
4419
4611
  * @param options.unit - The unit for the computed area: `"m2"` (square meters) or `"km2"` (square kilometers). Defaults to `"m2"`.
@@ -4455,8 +4647,6 @@ export default class SimpleTable extends Simple {
4455
4647
  * Computes the length of line geometries in meters (`"m"`) or optionally kilometers (`"km"`).
4456
4648
  * The input geometry is assumed to be in EPSG:4326 (WGS84).
4457
4649
  *
4458
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4459
- *
4460
4650
  * @param newColumn - The name of the new column where the computed lengths will be stored.
4461
4651
  * @param options - An optional object with configuration options:
4462
4652
  * @param options.unit - The unit for the computed length: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
@@ -4498,8 +4688,6 @@ export default class SimpleTable extends Simple {
4498
4688
  * Computes the perimeter of polygon geometries in meters (`"m"`) or optionally kilometers (`"km"`).
4499
4689
  * The input geometry is assumed to be in EPSG:4326 (WGS84).
4500
4690
  *
4501
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4502
- *
4503
4691
  * @param newColumn - The name of the new column where the computed perimeters will be stored.
4504
4692
  * @param options - An optional object with configuration options:
4505
4693
  * @param options.unit - The unit for the computed perimeter: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
@@ -4541,8 +4729,6 @@ export default class SimpleTable extends Simple {
4541
4729
  * Computes a buffer (a polygon representing a specified distance around a geometry) for geometries in a specified column.
4542
4730
  * The distance is in the Spatial Reference System (SRS) unit of the input geometries.
4543
4731
  *
4544
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4545
- *
4546
4732
  * @param newColumn - The name of the new column where the buffered geometries will be stored.
4547
4733
  * @param distance - The distance for the buffer. This value is in the units of the geometry's SRS.
4548
4734
  * @param options - An optional object with configuration options:
@@ -4569,7 +4755,6 @@ export default class SimpleTable extends Simple {
4569
4755
  * Merges the data of this table (considered the left table) with another table (the right table) based on a spatial relationship.
4570
4756
  * Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
4571
4757
  * This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
4572
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. The join uses the other table's state as of this call: operations queued on it afterwards run after the join.
4573
4758
  *
4574
4759
  * @param rightTable - The SimpleTable instance to be joined with this table.
4575
4760
  * @param method - The spatial join method to use: `"intersect"` (geometries overlap), `"inside"` (geometries of the left table are entirely within geometries of the right table), or `"withinDistance"` (geometries of the left table are within a specified distance of geometries in the right table).
@@ -4643,8 +4828,6 @@ export default class SimpleTable extends Simple {
4643
4828
  /**
4644
4829
  * Computes the intersection of two sets of geometries, creating new geometries where they overlap.
4645
4830
  *
4646
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4647
- *
4648
4831
  * @param column1 - The name of the first column storing geometries.
4649
4832
  * @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
4650
4833
  * @param newColumn - The name of the new column where the computed intersection geometries will be stored.
@@ -4661,8 +4844,6 @@ export default class SimpleTable extends Simple {
4661
4844
  /**
4662
4845
  * Computes the geometric difference between two geometries, returning the portion of the first geometry that does not intersect the second.
4663
4846
  *
4664
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4665
- *
4666
4847
  * @param column1 - The name of the column storing the geometries from which the second geometries will be subtracted.
4667
4848
  * @param column2 - The name of the column storing the geometries to subtract. Both columns must have the same projection.
4668
4849
  * @param newColumn - The name of the new column where the geometric differences will be stored.
@@ -4679,8 +4860,6 @@ export default class SimpleTable extends Simple {
4679
4860
  /**
4680
4861
  * Fills holes in polygon geometries.
4681
4862
  *
4682
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4683
- *
4684
4863
  * @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
4685
4864
  * @returns The table, so methods can be chained.
4686
4865
  * @category Geospatial
@@ -4701,8 +4880,6 @@ export default class SimpleTable extends Simple {
4701
4880
  /**
4702
4881
  * Returns `TRUE` if two geometries intersect (overlap in any way), and `FALSE` otherwise.
4703
4882
  *
4704
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4705
- *
4706
4883
  * @param column1 - The name of the first column storing geometries.
4707
4884
  * @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
4708
4885
  * @param newColumn - The name of the new column where the boolean results (`TRUE` for intersection, `FALSE` otherwise) will be stored.
@@ -4719,8 +4896,6 @@ export default class SimpleTable extends Simple {
4719
4896
  /**
4720
4897
  * Returns `TRUE` if every point of a geometry in `column` is covered by a geometry in `containerColumn`, including their boundaries, and `FALSE` otherwise.
4721
4898
  *
4722
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4723
- *
4724
4899
  * @param column - The name of the column storing the geometries to be tested for containment.
4725
4900
  * @param containerColumn - The name of the column storing the geometries to be tested as containers. Both columns must have the same projection.
4726
4901
  * @param newColumn - The name of the new column where the boolean results (`TRUE` when covered, `FALSE` otherwise) will be stored.
@@ -4737,8 +4912,6 @@ export default class SimpleTable extends Simple {
4737
4912
  /**
4738
4913
  * Computes the union of two geometries, creating a new geometry that represents the merged area of both.
4739
4914
  *
4740
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4741
- *
4742
4915
  * @param column1 - The name of the first column storing geometries.
4743
4916
  * @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
4744
4917
  * @param newColumn - The name of the new column where the computed union geometries will be stored.
@@ -4756,8 +4929,6 @@ export default class SimpleTable extends Simple {
4756
4929
  * Extracts the latitude (y) and longitude (x) coordinates from point geometries.
4757
4930
  * The input geometry is assumed to be in EPSG:4326 (WGS84).
4758
4931
  *
4759
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4760
- *
4761
4932
  * @param column - The name of the column storing the point geometries.
4762
4933
  * @param latColumn - The name of the new column where the extracted latitude (y-coordinate) values will be stored.
4763
4934
  * @param lonColumn - The name of the new column where the extracted longitude (x-coordinate) values will be stored.
@@ -4774,8 +4945,6 @@ export default class SimpleTable extends Simple {
4774
4945
  /**
4775
4946
  * Simplifies geometries while preserving their overall coverage. A higher tolerance results in more significant simplification.
4776
4947
  *
4777
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4778
- *
4779
4948
  * @param tolerance - A numeric value representing the simplification tolerance. A higher value leads to greater simplification.
4780
4949
  * @param options - An optional object with configuration options:
4781
4950
  * @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
@@ -4803,8 +4972,6 @@ export default class SimpleTable extends Simple {
4803
4972
  * Computes the centroid of geometries.
4804
4973
  * The values are returned in the SRS unit of the input geometries.
4805
4974
  *
4806
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4807
- *
4808
4975
  * @param newColumn - The name of the new column where the computed centroid geometries will be stored.
4809
4976
  * @param options - An optional object with configuration options:
4810
4977
  * @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
@@ -4829,8 +4996,6 @@ export default class SimpleTable extends Simple {
4829
4996
  /**
4830
4997
  * Generates a random point within the geometries of a specified column.
4831
4998
  *
4832
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4833
- *
4834
4999
  * @param newColumn - The name of the new column where the random points will be stored.
4835
5000
  * @param tries - The number of points to generate within the bounding box of each geometry to find one that is within the geometry itself.
4836
5001
  * @param options - An optional object with configuration options:
@@ -4865,8 +5030,6 @@ export default class SimpleTable extends Simple {
4865
5030
  * You can optionally specify `"spheroid"` or `"haversine"` methods to get results in meters or kilometers.
4866
5031
  * If using `"spheroid"` or `"haversine"`, the input geometries must be in EPSG:4326 (WGS84).
4867
5032
  *
4868
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4869
- *
4870
5033
  * @param column1 - The name of the first column storing geometries.
4871
5034
  * @param column2 - The name of the second column storing geometries.
4872
5035
  * @param newColumn - The name of the new column where the computed distances will be stored.
@@ -4912,8 +5075,6 @@ export default class SimpleTable extends Simple {
4912
5075
  /**
4913
5076
  * Unnests geometries recursively, transforming multi-part geometries (e.g., MultiPolygon) into individual single-part geometries (e.g., Polygon).
4914
5077
  *
4915
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4916
- *
4917
5078
  * @param column - The name of the column storing the geometries to be unnested. If omitted, the method will automatically attempt to find a geometry column.
4918
5079
  * @returns The table, so methods can be chained.
4919
5080
  * @category Geospatial
@@ -4934,8 +5095,6 @@ export default class SimpleTable extends Simple {
4934
5095
  /**
4935
5096
  * Adds the bounding box coordinates of geometries in a specified column as four new columns: `minLon`, `minLat`, `maxLon`, and `maxLat`.
4936
5097
  *
4937
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4938
- *
4939
5098
  * @param options - An optional object with configuration options:
4940
5099
  * @param options.column - The name of the column storing the geometries for which the bounding box will be computed. If omitted, the method will automatically attempt to find a geometry column.
4941
5100
  * @param options.decimals - The number of decimal places to round the bounding box coordinates. Defaults to `undefined` (no rounding).
@@ -4963,8 +5122,6 @@ export default class SimpleTable extends Simple {
4963
5122
  /**
4964
5123
  * Aggregates geometries in a specified column based on a chosen aggregation method.
4965
5124
  *
4966
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
4967
- *
4968
5125
  * @param method - The aggregation method to apply: `"union"` (combines all geometries into a single multi-geometry) or `"intersection"` (computes the intersection of all geometries).
4969
5126
  * @param options - An optional object with configuration options:
4970
5127
  * @param options.column - The name of the column storing the geometries to be aggregated. If omitted, the method will automatically attempt to find a geometry column.
@@ -4999,8 +5156,6 @@ export default class SimpleTable extends Simple {
4999
5156
  /**
5000
5157
  * Transforms closed linestring geometries into polygon geometries.
5001
5158
  *
5002
- * This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
5003
- *
5004
5159
  * @param column - The name of the column storing the linestring geometries. If omitted, the method will automatically attempt to find a geometry column.
5005
5160
  * @returns The table, so methods can be chained.
5006
5161
  * @category Geospatial
@@ -5042,7 +5197,9 @@ export default class SimpleTable extends Simple {
5042
5197
  */
5043
5198
  getBoundingBox(column?: string): Promise<[number, number, number, number]>;
5044
5199
  /**
5045
- * Returns the table's geospatial data as a GeoJSON object.
5200
+ * Returns the table's geospatial data as a GeoJSON FeatureCollection.
5201
+ * Each row becomes a Feature: the selected geometry column becomes its geometry,
5202
+ * and the remaining columns become its properties.
5046
5203
  * If the table has multiple geometry columns, you must specify which one to use.
5047
5204
  *
5048
5205
  * @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
@@ -5080,12 +5237,13 @@ export default class SimpleTable extends Simple {
5080
5237
  }>;
5081
5238
  /**
5082
5239
  * Writes the table's data to a file in various formats (CSV, JSON, Parquet, DuckDB, SQLite).
5240
+ * Tables with geometry columns must use `writeGeoData()` instead.
5083
5241
  * If the specified path does not exist, it will be created.
5084
5242
  *
5085
5243
  * @param file - The absolute path to the output file (e.g., `"./output.csv"`, `"./output.json"`).
5086
5244
  * @param options - An optional object with configuration options:
5087
5245
  * @param options.compression - A boolean indicating whether to compress the output file. If `true`, CSV and JSON files will be compressed with GZIP, while Parquet files will use ZSTD. Defaults to `false`.
5088
- * @param options.dataAsArrays - For JSON files only. If `true`, JSON files are written as a single object with arrays for each column (e.g., `{ "col1": [v1, v2], "col2": [v3, v4] }`) instead of an array of objects. This can reduce file size for web projects. You can use the `arraysToData` function from the [journalism library](https://jsr.io/@nshiab/journalism/doc/~/arraysToData) to convert it back.
5246
+ * @param options.dataAsArrays - For JSON files only. If `true`, JSON files are written as a single object with arrays for each column (e.g., `{ "col1": [v1, v2], "col2": [v3, v4] }`) instead of an array of objects. This can reduce file size for web projects. You can use the `arraysToData` function from the [journalism-format library](https://jsr.io/@nshiab/journalism-format/doc/~/arraysToData) to convert it back.
5089
5247
  * @param options.formatDates - For CSV and JSON files only. If `true`, date and timestamp columns will be formatted as ISO 8601 strings (e.g., `"2025-01-01T01:00:00.000Z"`). Defaults to `false`.
5090
5248
  * @returns A promise that resolves to the table, so methods can be chained.
5091
5249
  * @category File Operations
@@ -5190,28 +5348,28 @@ export default class SimpleTable extends Simple {
5190
5348
  * Caches the results of computations in `./.sda-cache`.
5191
5349
  * You should add `./.sda-cache` to your `.gitignore` file.
5192
5350
  *
5193
- * Cache entries are stored as DuckDB database files. Full-text search (FTS)
5194
- * indexes are persisted in the cache file and restored directly on a cache
5195
- * hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
5196
- * cache file; their definitions are stored as metadata and used to rebuild
5197
- * the indexes on every cache hit. If loading the entry or restoring its
5198
- * indexes fails, the computation runs again and replaces the cache entry.
5199
- *
5200
5351
  * `cache()` automatically tracks whether earlier SDA operations changed the
5201
5352
  * table. It also records every other already registered `SimpleTable` read
5202
5353
  * through `SimpleTable` methods while `compute` runs and invalidates the
5203
5354
  * cached step when any of their generations change. Tables created inside
5204
5355
  * `compute` are part of the computation itself and are not dependencies.
5205
5356
  *
5357
+ * Inside `compute`, you may modify the table being cached and create or
5358
+ * modify temporary tables, provided you remove them before the callback
5359
+ * finishes. Other tables that already existed may be read but not modified,
5360
+ * renamed, or removed. `customQuery()` bypasses enforcement of these rules.
5361
+ *
5206
5362
  * `SimpleDB.customQuery()` bypasses this tracking. Reading or changing a
5207
5363
  * table with `customQuery()` can therefore return stale cached data. Include
5208
5364
  * a value that identifies the custom query's dependencies in `options.inputs`
5209
5365
  * (such as a table content hash), or use tracked `SimpleTable` methods.
5210
5366
  *
5211
- * `compute` may modify only the table being cached. Other tables that existed
5212
- * before `compute` must remain read-only. Temporary tables may be created and
5213
- * modified inside `compute`, but they must be removed before it finishes
5214
- * because a cache hit does not run `compute` again.
5367
+ * Cache entries are stored as DuckDB database files. Full-text search (FTS)
5368
+ * indexes are persisted in the cache file and restored directly on a cache
5369
+ * hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
5370
+ * cache file; their definitions are stored as metadata and used to rebuild
5371
+ * the indexes on every cache hit. If loading the entry or restoring its
5372
+ * indexes fails, the computation runs again and replaces the cache entry.
5215
5373
  *
5216
5374
  * @param compute - A function wrapping the computations to be cached. It receives the table on which `cache()` was called. This function will be executed on the first run or if the cached data is invalid/expired.
5217
5375
  * @param options - An optional object with configuration options:
@@ -5296,7 +5454,16 @@ export default class SimpleTable extends Simple {
5296
5454
  /**
5297
5455
  * Logs a specified number of rows from the table to the console. By default, the first 10 rows are logged.
5298
5456
  * You can optionally log the column types and filter the data based on conditions.
5299
- * You can also use JavaScript syntax for conditions (e.g., `&&`, `||`, `===`, `!==`).
5457
+ * SQL dates and timestamps retain their native precision for display, including
5458
+ * temporal infinities. Lists and objects are stringified using the same nested
5459
+ * representations as `getData()`, then truncated according to `charsToLog`.
5460
+ * Unsafe top-level large integers throw, just as with `getData()`.
5461
+ * Type annotations describe the SQL type and the JavaScript extraction type
5462
+ * before display formatting; nulls do not determine the column's annotation.
5463
+ * Colors reflect the SQL value's meaning, so exact decimal strings use numeric
5464
+ * coloring. Column width is independent of the content truncation budget.
5465
+ *
5466
+ * With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
5300
5467
  *
5301
5468
  * @param options - Either the number of rows to log (a specific number or `"all"`) or an object with configuration options:
5302
5469
  * @param options.count - The number of rows to log. Defaults to 10 or the value set in the SimpleDB instance. Use `"all"` to log all rows.
@@ -5485,6 +5652,10 @@ export default class SimpleTable extends Simple {
5485
5652
  /**
5486
5653
  * Logs the bottom `n` rows of the table to the console. By default, the last row will be returned first. To preserve the original order, use the `originalOrder` option.
5487
5654
  *
5655
+ * Uses the same precision-preserving temporal display, nested stringification,
5656
+ * numeric coloring, and `charsToLog` truncation as `log()`. Unsafe top-level
5657
+ * large integers throw, just as with `getData()`.
5658
+ *
5488
5659
  * @param count - The number of rows to log from the bottom of the table. Defaults to the table's `rowsToLog` option if not specified.
5489
5660
  * @param options - An optional object with logging preferences.
5490
5661
  * @param options.originalOrder - If true, the rows are displayed in their original order (top to bottom). Defaults to false.