@haybarn/node-api 1.5.6-rc1 → 2.0.0-rc3

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 (285) hide show
  1. package/README.md +315 -20
  2. package/lib/DuckDBAppender.d.ts +8 -2
  3. package/lib/DuckDBAppender.js +19 -1
  4. package/lib/DuckDBConnection.d.ts +2 -0
  5. package/lib/DuckDBConnection.js +4 -1
  6. package/lib/DuckDBDataChunk.d.ts +30 -0
  7. package/lib/DuckDBDataChunk.js +94 -1
  8. package/lib/DuckDBDataChunkWriter.d.ts +74 -0
  9. package/lib/DuckDBDataChunkWriter.js +109 -0
  10. package/lib/DuckDBLogicalType.d.ts +5 -1
  11. package/lib/DuckDBLogicalType.js +18 -1
  12. package/lib/DuckDBMaterializedResult.d.ts +8 -1
  13. package/lib/DuckDBMaterializedResult.js +22 -2
  14. package/lib/DuckDBPendingResult.d.ts +16 -1
  15. package/lib/DuckDBPendingResult.js +19 -2
  16. package/lib/DuckDBPreparedStatement.d.ts +4 -1
  17. package/lib/DuckDBPreparedStatement.js +17 -4
  18. package/lib/DuckDBResult.d.ts +21 -1
  19. package/lib/DuckDBResult.js +87 -5
  20. package/lib/DuckDBResultReader.d.ts +5 -0
  21. package/lib/DuckDBResultReader.js +9 -2
  22. package/lib/DuckDBScalarFunction.d.ts +9 -5
  23. package/lib/DuckDBScalarFunction.js +14 -5
  24. package/lib/DuckDBScalarFunctionBindInfo.d.ts +16 -0
  25. package/lib/{DuckDBBindInfo.js → DuckDBScalarFunctionBindInfo.js} +5 -3
  26. package/lib/DuckDBScalarFunctionInfo.d.ts +16 -0
  27. package/lib/{DuckDBFunctionInfo.js → DuckDBScalarFunctionInfo.js} +11 -3
  28. package/lib/{DuckDBBindInfo.d.ts → DuckDBScalarFunctionInitInfo.d.ts} +6 -4
  29. package/lib/DuckDBScalarFunctionInitInfo.js +39 -0
  30. package/lib/DuckDBTableFunction.d.ts +41 -0
  31. package/lib/DuckDBTableFunction.js +83 -0
  32. package/lib/DuckDBTableFunctionBindInfo.d.ts +21 -0
  33. package/lib/DuckDBTableFunctionBindInfo.js +54 -0
  34. package/lib/DuckDBTableFunctionInfo.d.ts +15 -0
  35. package/lib/DuckDBTableFunctionInfo.js +42 -0
  36. package/lib/DuckDBTableFunctionInitInfo.d.ts +22 -0
  37. package/lib/DuckDBTableFunctionInitInfo.js +58 -0
  38. package/lib/DuckDBType.d.ts +1 -373
  39. package/lib/DuckDBType.js +14 -927
  40. package/lib/DuckDBTypeId.d.ts +4 -1
  41. package/lib/DuckDBTypeId.js +3 -0
  42. package/lib/DuckDBValueConverter.d.ts +10 -0
  43. package/lib/DuckDBValueConverters.d.ts +27 -0
  44. package/lib/DuckDBValueConverters.js +128 -1
  45. package/lib/DuckDBVector.d.ts +1 -596
  46. package/lib/DuckDBVector.js +14 -2522
  47. package/lib/JSDuckDBValueConverter.d.ts +1 -2
  48. package/lib/JSDuckDBValueConverter.js +5 -2
  49. package/lib/JSInputTypeForTypeId.d.ts +104 -0
  50. package/lib/JSInputTypeForTypeId.js +3 -0
  51. package/lib/JSToDuckDBValueConverter.d.ts +30 -0
  52. package/lib/JSToDuckDBValueConverter.js +83 -0
  53. package/lib/JSTypeForTypeId.d.ts +91 -0
  54. package/lib/JSTypeForTypeId.js +3 -0
  55. package/lib/JsonDuckDBValueConverter.d.ts +1 -2
  56. package/lib/JsonDuckDBValueConverter.js +4 -1
  57. package/lib/JsonTypeForTypeId.d.ts +96 -0
  58. package/lib/JsonTypeForTypeId.js +3 -0
  59. package/lib/ToDuckDBValueConverter.d.ts +41 -0
  60. package/lib/ToDuckDBValueConverter.js +27 -0
  61. package/lib/ToDuckDBValueConverters.d.ts +54 -0
  62. package/lib/ToDuckDBValueConverters.js +199 -0
  63. package/lib/conversion/dateTimeStringConversion.d.ts +2 -2
  64. package/lib/conversion/dateTimeStringConversion.js +20 -7
  65. package/lib/conversion/varintDecode.d.ts +18 -0
  66. package/lib/conversion/varintDecode.js +42 -0
  67. package/lib/convertColumnsFromChunks.d.ts +1 -1
  68. package/lib/convertColumnsFromChunks.js +2 -2
  69. package/lib/createResult.d.ts +2 -1
  70. package/lib/createResult.js +3 -3
  71. package/lib/createValue.js +63 -5
  72. package/lib/duckdb.d.ts +15 -2
  73. package/lib/duckdb.js +15 -2
  74. package/lib/getColumnsFromChunks.d.ts +1 -1
  75. package/lib/getColumnsFromChunks.js +2 -2
  76. package/lib/getColumnsObjectFromChunks.js +3 -0
  77. package/lib/readValue.d.ts +22 -0
  78. package/lib/readValue.js +35 -0
  79. package/lib/typeForValue.js +21 -2
  80. package/lib/types/BaseDuckDBType.d.ts +11 -0
  81. package/lib/types/BaseDuckDBType.js +34 -0
  82. package/lib/types/DuckDBAnyType.d.ts +8 -0
  83. package/lib/types/DuckDBAnyType.js +16 -0
  84. package/lib/types/DuckDBArrayType.d.ts +14 -0
  85. package/lib/types/DuckDBArrayType.js +38 -0
  86. package/lib/types/DuckDBBigIntType.d.ts +12 -0
  87. package/lib/types/DuckDBBigIntType.js +24 -0
  88. package/lib/types/DuckDBBigNumType.d.ts +12 -0
  89. package/lib/types/DuckDBBigNumType.js +24 -0
  90. package/lib/types/DuckDBBitType.d.ts +8 -0
  91. package/lib/types/DuckDBBitType.js +16 -0
  92. package/lib/types/DuckDBBlobType.d.ts +8 -0
  93. package/lib/types/DuckDBBlobType.js +16 -0
  94. package/lib/types/DuckDBBooleanType.d.ts +8 -0
  95. package/lib/types/DuckDBBooleanType.js +16 -0
  96. package/lib/types/DuckDBDateType.d.ts +14 -0
  97. package/lib/types/DuckDBDateType.js +32 -0
  98. package/lib/types/DuckDBDecimalType.d.ts +14 -0
  99. package/lib/types/DuckDBDecimalType.js +45 -0
  100. package/lib/types/DuckDBDoubleType.d.ts +12 -0
  101. package/lib/types/DuckDBDoubleType.js +24 -0
  102. package/lib/types/DuckDBEnumType.d.ts +29 -0
  103. package/lib/types/DuckDBEnumType.js +100 -0
  104. package/lib/types/DuckDBFloatType.d.ts +12 -0
  105. package/lib/types/DuckDBFloatType.js +24 -0
  106. package/lib/types/DuckDBGeometryType.d.ts +19 -0
  107. package/lib/types/DuckDBGeometryType.js +38 -0
  108. package/lib/types/DuckDBHugeIntType.d.ts +12 -0
  109. package/lib/types/DuckDBHugeIntType.js +24 -0
  110. package/lib/types/DuckDBIntegerLiteralType.d.ts +8 -0
  111. package/lib/types/DuckDBIntegerLiteralType.js +16 -0
  112. package/lib/types/DuckDBIntegerType.d.ts +12 -0
  113. package/lib/types/DuckDBIntegerType.js +24 -0
  114. package/lib/types/DuckDBIntervalType.d.ts +8 -0
  115. package/lib/types/DuckDBIntervalType.js +16 -0
  116. package/lib/types/DuckDBListType.d.ts +13 -0
  117. package/lib/types/DuckDBListType.js +35 -0
  118. package/lib/types/DuckDBMapType.d.ts +14 -0
  119. package/lib/types/DuckDBMapType.js +38 -0
  120. package/lib/types/DuckDBSQLNullType.d.ts +10 -0
  121. package/lib/types/DuckDBSQLNullType.js +20 -0
  122. package/lib/types/DuckDBSmallIntType.d.ts +12 -0
  123. package/lib/types/DuckDBSmallIntType.js +24 -0
  124. package/lib/types/DuckDBStringLiteralType.d.ts +8 -0
  125. package/lib/types/DuckDBStringLiteralType.js +16 -0
  126. package/lib/types/DuckDBStructType.d.ts +29 -0
  127. package/lib/types/DuckDBStructType.js +86 -0
  128. package/lib/types/DuckDBTimeNSType.d.ts +11 -0
  129. package/lib/types/DuckDBTimeNSType.js +23 -0
  130. package/lib/types/DuckDBTimeTZType.d.ts +12 -0
  131. package/lib/types/DuckDBTimeTZType.js +26 -0
  132. package/lib/types/DuckDBTimeType.d.ts +11 -0
  133. package/lib/types/DuckDBTimeType.js +23 -0
  134. package/lib/types/DuckDBTimestampMillisecondsType.d.ts +14 -0
  135. package/lib/types/DuckDBTimestampMillisecondsType.js +32 -0
  136. package/lib/types/DuckDBTimestampNanosecondsType.d.ts +14 -0
  137. package/lib/types/DuckDBTimestampNanosecondsType.js +32 -0
  138. package/lib/types/DuckDBTimestampSecondsType.d.ts +14 -0
  139. package/lib/types/DuckDBTimestampSecondsType.js +32 -0
  140. package/lib/types/DuckDBTimestampTZNanosecondsType.d.ts +15 -0
  141. package/lib/types/DuckDBTimestampTZNanosecondsType.js +35 -0
  142. package/lib/types/DuckDBTimestampTZType.d.ts +15 -0
  143. package/lib/types/DuckDBTimestampTZType.js +35 -0
  144. package/lib/types/DuckDBTimestampType.d.ts +16 -0
  145. package/lib/types/DuckDBTimestampType.js +33 -0
  146. package/lib/types/DuckDBTinyIntType.d.ts +12 -0
  147. package/lib/types/DuckDBTinyIntType.js +24 -0
  148. package/lib/types/DuckDBType.d.ts +43 -0
  149. package/lib/types/DuckDBType.js +2 -0
  150. package/lib/types/DuckDBUBigIntType.d.ts +12 -0
  151. package/lib/types/DuckDBUBigIntType.js +24 -0
  152. package/lib/types/DuckDBUHugeIntType.d.ts +12 -0
  153. package/lib/types/DuckDBUHugeIntType.js +24 -0
  154. package/lib/types/DuckDBUIntegerType.d.ts +12 -0
  155. package/lib/types/DuckDBUIntegerType.js +24 -0
  156. package/lib/types/DuckDBUSmallIntType.d.ts +12 -0
  157. package/lib/types/DuckDBUSmallIntType.js +24 -0
  158. package/lib/types/DuckDBUTinyIntType.d.ts +12 -0
  159. package/lib/types/DuckDBUTinyIntType.js +24 -0
  160. package/lib/types/DuckDBUUIDType.d.ts +11 -0
  161. package/lib/types/DuckDBUUIDType.js +23 -0
  162. package/lib/types/DuckDBUnionType.d.ts +18 -0
  163. package/lib/types/DuckDBUnionType.js +64 -0
  164. package/lib/types/DuckDBVarCharType.d.ts +8 -0
  165. package/lib/types/DuckDBVarCharType.js +16 -0
  166. package/lib/types/DuckDBVariantType.d.ts +8 -0
  167. package/lib/types/DuckDBVariantType.js +16 -0
  168. package/lib/types/index.d.ts +44 -0
  169. package/lib/types/index.js +60 -0
  170. package/lib/values/DuckDBGeometryValue.d.ts +12 -0
  171. package/lib/values/DuckDBGeometryValue.js +30 -0
  172. package/lib/values/DuckDBTimestampTZNanosecondsValue.d.ts +14 -0
  173. package/lib/values/DuckDBTimestampTZNanosecondsValue.js +33 -0
  174. package/lib/values/DuckDBTupleValue.d.ts +11 -0
  175. package/lib/values/DuckDBTupleValue.js +22 -0
  176. package/lib/values/DuckDBUUIDValue.js +5 -1
  177. package/lib/values/DuckDBValue.d.ts +5 -1
  178. package/lib/values/DuckDBVariantValue.d.ts +19 -0
  179. package/lib/values/DuckDBVariantValue.js +30 -0
  180. package/lib/values/index.d.ts +4 -0
  181. package/lib/values/index.js +4 -0
  182. package/lib/vectors/DuckDBArrayVector.d.ts +21 -0
  183. package/lib/vectors/DuckDBArrayVector.js +79 -0
  184. package/lib/vectors/DuckDBBigIntVector.d.ts +17 -0
  185. package/lib/vectors/DuckDBBigIntVector.js +58 -0
  186. package/lib/vectors/DuckDBBigNumVector.d.ts +21 -0
  187. package/lib/vectors/DuckDBBigNumVector.js +70 -0
  188. package/lib/vectors/DuckDBBitVector.d.ts +22 -0
  189. package/lib/vectors/DuckDBBitVector.js +74 -0
  190. package/lib/vectors/DuckDBBlobVector.d.ts +32 -0
  191. package/lib/vectors/DuckDBBlobVector.js +83 -0
  192. package/lib/vectors/DuckDBBooleanVector.d.ts +18 -0
  193. package/lib/vectors/DuckDBBooleanVector.js +58 -0
  194. package/lib/vectors/DuckDBDateVector.d.ts +18 -0
  195. package/lib/vectors/DuckDBDateVector.js +64 -0
  196. package/lib/vectors/DuckDBDecimal128Vector.d.ts +21 -0
  197. package/lib/vectors/DuckDBDecimal128Vector.js +64 -0
  198. package/lib/vectors/DuckDBDecimal16Vector.d.ts +21 -0
  199. package/lib/vectors/DuckDBDecimal16Vector.js +64 -0
  200. package/lib/vectors/DuckDBDecimal32Vector.d.ts +21 -0
  201. package/lib/vectors/DuckDBDecimal32Vector.js +64 -0
  202. package/lib/vectors/DuckDBDecimal64Vector.d.ts +21 -0
  203. package/lib/vectors/DuckDBDecimal64Vector.js +64 -0
  204. package/lib/vectors/DuckDBDoubleVector.d.ts +17 -0
  205. package/lib/vectors/DuckDBDoubleVector.js +54 -0
  206. package/lib/vectors/DuckDBEnum16Vector.d.ts +18 -0
  207. package/lib/vectors/DuckDBEnum16Vector.js +57 -0
  208. package/lib/vectors/DuckDBEnum32Vector.d.ts +18 -0
  209. package/lib/vectors/DuckDBEnum32Vector.js +57 -0
  210. package/lib/vectors/DuckDBEnum8Vector.d.ts +18 -0
  211. package/lib/vectors/DuckDBEnum8Vector.js +57 -0
  212. package/lib/vectors/DuckDBFloatVector.d.ts +17 -0
  213. package/lib/vectors/DuckDBFloatVector.js +54 -0
  214. package/lib/vectors/DuckDBGeometryVector.d.ts +22 -0
  215. package/lib/vectors/DuckDBGeometryVector.js +69 -0
  216. package/lib/vectors/DuckDBHugeIntVector.d.ts +19 -0
  217. package/lib/vectors/DuckDBHugeIntVector.js +63 -0
  218. package/lib/vectors/DuckDBIntegerVector.d.ts +17 -0
  219. package/lib/vectors/DuckDBIntegerVector.js +61 -0
  220. package/lib/vectors/DuckDBIntervalVector.d.ts +19 -0
  221. package/lib/vectors/DuckDBIntervalVector.js +67 -0
  222. package/lib/vectors/DuckDBListVector.d.ts +35 -0
  223. package/lib/vectors/DuckDBListVector.js +151 -0
  224. package/lib/vectors/DuckDBMapVector.d.ts +17 -0
  225. package/lib/vectors/DuckDBMapVector.js +60 -0
  226. package/lib/vectors/DuckDBSQLNullVector.d.ts +18 -0
  227. package/lib/vectors/DuckDBSQLNullVector.js +44 -0
  228. package/lib/vectors/DuckDBSmallIntVector.d.ts +17 -0
  229. package/lib/vectors/DuckDBSmallIntVector.js +61 -0
  230. package/lib/vectors/DuckDBStructVector.d.ts +35 -0
  231. package/lib/vectors/DuckDBStructVector.js +105 -0
  232. package/lib/vectors/DuckDBTimeNSVector.d.ts +18 -0
  233. package/lib/vectors/DuckDBTimeNSVector.js +61 -0
  234. package/lib/vectors/DuckDBTimeTZVector.d.ts +18 -0
  235. package/lib/vectors/DuckDBTimeTZVector.js +61 -0
  236. package/lib/vectors/DuckDBTimeVector.d.ts +18 -0
  237. package/lib/vectors/DuckDBTimeVector.js +61 -0
  238. package/lib/vectors/DuckDBTimestampMillisecondsVector.d.ts +18 -0
  239. package/lib/vectors/DuckDBTimestampMillisecondsVector.js +61 -0
  240. package/lib/vectors/DuckDBTimestampNanosecondsVector.d.ts +18 -0
  241. package/lib/vectors/DuckDBTimestampNanosecondsVector.js +61 -0
  242. package/lib/vectors/DuckDBTimestampSecondsVector.d.ts +18 -0
  243. package/lib/vectors/DuckDBTimestampSecondsVector.js +61 -0
  244. package/lib/vectors/DuckDBTimestampTZNanosecondsVector.d.ts +18 -0
  245. package/lib/vectors/DuckDBTimestampTZNanosecondsVector.js +61 -0
  246. package/lib/vectors/DuckDBTimestampTZVector.d.ts +18 -0
  247. package/lib/vectors/DuckDBTimestampTZVector.js +61 -0
  248. package/lib/vectors/DuckDBTimestampVector.d.ts +18 -0
  249. package/lib/vectors/DuckDBTimestampVector.js +61 -0
  250. package/lib/vectors/DuckDBTinyIntVector.d.ts +17 -0
  251. package/lib/vectors/DuckDBTinyIntVector.js +61 -0
  252. package/lib/vectors/DuckDBTupleVector.d.ts +26 -0
  253. package/lib/vectors/DuckDBTupleVector.js +91 -0
  254. package/lib/vectors/DuckDBUBigIntVector.d.ts +17 -0
  255. package/lib/vectors/DuckDBUBigIntVector.js +58 -0
  256. package/lib/vectors/DuckDBUHugeIntVector.d.ts +19 -0
  257. package/lib/vectors/DuckDBUHugeIntVector.js +63 -0
  258. package/lib/vectors/DuckDBUIntegerVector.d.ts +17 -0
  259. package/lib/vectors/DuckDBUIntegerVector.js +61 -0
  260. package/lib/vectors/DuckDBUSmallIntVector.d.ts +17 -0
  261. package/lib/vectors/DuckDBUSmallIntVector.js +61 -0
  262. package/lib/vectors/DuckDBUTinyIntVector.d.ts +17 -0
  263. package/lib/vectors/DuckDBUTinyIntVector.js +61 -0
  264. package/lib/vectors/DuckDBUUIDVector.d.ts +19 -0
  265. package/lib/vectors/DuckDBUUIDVector.js +59 -0
  266. package/lib/vectors/DuckDBUnionVector.d.ts +17 -0
  267. package/lib/vectors/DuckDBUnionVector.js +70 -0
  268. package/lib/vectors/DuckDBValidity.d.ts +12 -0
  269. package/lib/vectors/DuckDBValidity.js +91 -0
  270. package/lib/vectors/DuckDBVarCharVector.d.ts +21 -0
  271. package/lib/vectors/DuckDBVarCharVector.js +74 -0
  272. package/lib/vectors/DuckDBVariantVector.d.ts +42 -0
  273. package/lib/vectors/DuckDBVariantVector.js +461 -0
  274. package/lib/vectors/DuckDBVector.d.ts +14 -0
  275. package/lib/vectors/DuckDBVector.js +27 -0
  276. package/lib/vectors/createVector.d.ts +1 -0
  277. package/lib/vectors/createVector.js +201 -0
  278. package/lib/vectors/dataAccessors.d.ts +45 -0
  279. package/lib/vectors/dataAccessors.js +344 -0
  280. package/lib/vectors/index.d.ts +47 -0
  281. package/lib/vectors/index.js +65 -0
  282. package/lib/vectors/vectorRegistry.d.ts +20 -0
  283. package/lib/vectors/vectorRegistry.js +16 -0
  284. package/package.json +3 -2
  285. package/lib/DuckDBFunctionInfo.d.ts +0 -10
package/README.md CHANGED
@@ -1,6 +1,13 @@
1
+ <p align="center">
2
+ <a href="https://query.farm/products/haybarn/"><img src="https://raw.githubusercontent.com/Query-farm-haybarn/.github/haybarn/profile/assets/haybarn-icon.png" alt="Haybarn" width="120" height="120"></a>
3
+ </p>
4
+ <p align="center">
5
+ <a href="https://query.farm"><img src="https://query.farm/media-kit/logo/wordmark-light.png" alt="Query.Farm" height="28"></a>
6
+ </p>
7
+
1
8
  # Haybarn Node API
2
9
 
3
- A high-level Node API for [Haybarn](https://github.com/Query-farm-haybarn/haybarn),
10
+ A high-level Node API for [Haybarn](https://query.farm/products/haybarn/),
4
11
  a derived distribution of [DuckDB](https://duckdb.org/) (powered by DuckDB),
5
12
  published by Query Farm LLC.
6
13
 
@@ -213,16 +220,50 @@ These are:
213
220
  | `LIST` | `listValue` |
214
221
  | `MAP` | `mapValue` |
215
222
  | `STRUCT` | `structValue` |
223
+ | `STRUCT` (unnamed, a tuple) | `tupleValue` |
216
224
  | `TIME` | `timeValue` |
217
225
  | `TIMETZ` | `timeTZValue` |
218
226
  | `TIMESTAMP` | `timestampValue` |
219
227
  | `TIMESTAMPTZ` | `timestampTZValue` |
228
+ | `TIMESTAMPTZ_NS` | `timestampTZNanosValue` |
220
229
  | `TIMESTAMP_S` | `timestampSecondsValue` |
221
230
  | `TIMESTAMP_MS` | `timestampMillisValue` |
222
231
  | `TIMESTAMP_NS` | `timestampNanosValue` |
223
232
  | `UNION` | `unionValue` |
224
233
  | `UUID` | `uuidValue` |
225
234
 
235
+ Alternatively, `jsToDuckDBValue` converts a plain JS value to the form
236
+ a given DuckDB type expects, so these functions need not be called
237
+ directly:
238
+
239
+ ```ts
240
+ import { jsToDuckDBValue, DATE, TIMESTAMP_MS } from '@haybarn/node-api';
241
+
242
+ jsToDuckDBValue(new Date('2024-01-15T12:34:56.789Z'), TIMESTAMP_MS);
243
+ // same as timestampMillisValue(1705322096789n)
244
+
245
+ jsToDuckDBValue(new Date('2024-01-15T00:00:00.000Z'), DATE);
246
+ // same as dateValue(19737)
247
+
248
+ jsToDuckDBValue(null, DATE); // null, for any type
249
+ ```
250
+
251
+ It is generic over the type, so a statically known one checks its input:
252
+
253
+ ```ts
254
+ jsToDuckDBValue(new Date(), TIMESTAMP); // ok
255
+ jsToDuckDBValue(new Date(), INTEGER); // rejected at compile time
256
+ ```
257
+
258
+ What each type accepts is given by `JSInputTypeForTypeId`, and by
259
+ `JSInputTypeFor` when keyed by a `DuckDBType`. These are wider than
260
+ what is read back where a second spelling is unambiguous: `BIGINT` and
261
+ the wider integers accept `number` as well as `bigint`, and `DECIMAL`
262
+ accepts either a double or a raw scaled `bigint`.
263
+
264
+ The result is a `DuckDBValue`, which is what `appendValue`,
265
+ `bindValue`, and `setRows` all accept.
266
+
226
267
  ### Stream Results
227
268
 
228
269
  Streaming results evaluate lazily when rows are read.
@@ -231,6 +272,38 @@ Streaming results evaluate lazily when rows are read.
231
272
  const result = await connection.stream('from range(10_000)');
232
273
  ```
233
274
 
275
+ ### Close Results
276
+
277
+ Results are destroyed automatically soon after their reference is
278
+ dropped, but you can also close them explicitly to free their memory:
279
+
280
+ ```ts
281
+ result.closeSync();
282
+ ```
283
+
284
+ From DuckDB 2.0, a streaming result that hasn't been read to the end, or
285
+ a pending result that hasn't been executed, blocks its connection: the
286
+ next statement on it fails until the result is closed. A result reader
287
+ or pending result can be closed the same way:
288
+
289
+ ```ts
290
+ const reader = await connection.streamAndReadUntil(sql, 100);
291
+ reader.closeSync();
292
+ const rows = reader.getRows(); // rows already read stay available
293
+ ```
294
+
295
+ Column names and types also stay available after closing; reading more
296
+ rows throws.
297
+
298
+ The same applies to appenders: from DuckDB 2.0, an appender can't flush
299
+ while its connection has such a result. Appenders flush on `flushSync()`
300
+ and `closeSync()`, and automatically about every 204,800 rows, so with a
301
+ streaming result open, appending fails at the next flush, and the rows
302
+ appended since the last successful flush are lost. Read the result to the
303
+ end or close it before appending, or append on a separate connection.
304
+ Close appenders explicitly too: one that is flushed when it's garbage
305
+ collected can't report a failure.
306
+
234
307
  ### Inspect Result Metadata
235
308
 
236
309
  Get column names and types:
@@ -577,6 +650,45 @@ const columnNameAndTypeObjects = reader.columnNameAndTypeObjectsJson();
577
650
  // ]
578
651
  ```
579
652
 
653
+ ### Infer JS Types from DuckDB Types
654
+
655
+ The mapping each converter applies is also available at the type level.
656
+ `JSTypeFor` gives the JS type that `getRowsJS` and the other `JS` methods
657
+ produce for a given DuckDB type; `JsonTypeFor` does the same for the `Json`
658
+ methods.
659
+
660
+ ```ts
661
+ import {
662
+ JSTypeFor,
663
+ JsonTypeFor,
664
+ DuckDBBigIntType,
665
+ DuckDBIntegerType,
666
+ DuckDBTimestampTZType,
667
+ } from '@haybarn/node-api';
668
+
669
+ type A = JSTypeFor<DuckDBIntegerType>; // number
670
+ type B = JSTypeFor<DuckDBBigIntType>; // bigint
671
+ type C = JSTypeFor<DuckDBTimestampTZType>; // Date
672
+
673
+ type D = JsonTypeFor<DuckDBBigIntType>; // string
674
+ type E = JsonTypeFor<DuckDBTimestampTZType>; // string
675
+ ```
676
+
677
+ The two differ wherever a value has no lossless JSON form: 64-bit and
678
+ wider integers, temporal types, `DECIMAL`, `BLOB`, `BIT` and `GEOMETRY`
679
+ render as strings, and `FLOAT` and `DOUBLE` widen to `number | string`
680
+ so that Infinity and NaN survive.
681
+
682
+ Both are also available keyed by type id, as `JSTypeForTypeId` and
683
+ `JsonTypeForTypeId`, which is the form to use when the id is what you have:
684
+
685
+ ```ts
686
+ type F = JSTypeForTypeId[DuckDBTypeId.INTEGER]; // number
687
+ ```
688
+
689
+ These describe non-NULL values. Since any column can be NULL, a value read
690
+ from one is `JSTypeFor<T> | null`.
691
+
580
692
  ### Fetch Chunks
581
693
 
582
694
  Fetch all chunks:
@@ -611,7 +723,8 @@ Get chunk data:
611
723
  ```ts
612
724
  const rows = chunk.getRows();
613
725
 
614
- const rowObjects = chunk.getRowObjects(result.deduplicatedColumnNames());
726
+ const rowObjects =
727
+ chunk.getRowObjects(result.deduplicatedColumnNames());
615
728
 
616
729
  const columns = chunk.getColumns();
617
730
 
@@ -740,8 +853,13 @@ if (columnType.typeId === DuckDBTypeId.MAP) {
740
853
  }
741
854
 
742
855
  if (columnType.typeId === DuckDBTypeId.STRUCT) {
743
- // { name1: value1, name2: value2, ... }
744
- const structEntries = columnValue.entries;
856
+ if (columnType.isTuple) {
857
+ // An unnamed struct, such as (1, 'a'): items in entry order
858
+ const tupleItems = columnValue.items; // array of values
859
+ } else {
860
+ // { name1: value1, name2: value2, ... }
861
+ const structEntries = columnValue.entries;
862
+ }
745
863
  const structString = columnValue.toString();
746
864
  }
747
865
 
@@ -810,9 +928,9 @@ if (columnType.typeId === DuckDBTypeId.UUID) {
810
928
 
811
929
  ### Displaying Timezones
812
930
 
813
- Converting a TIMESTAMP_TZ value to a string depends on a timezone offset.
814
- By default, this is set to the offset for the local timezone when the Node
815
- process is started.
931
+ Converting a TIMESTAMP_TZ or TIMESTAMPTZ_NS value to a string depends on
932
+ a timezone offset. By default, this is set to the offset for the local
933
+ timezone when the Node process is started.
816
934
 
817
935
  To change it, set the `timezoneOffsetInMinutes`
818
936
  property of `DuckDBTimestampTZValue`:
@@ -827,6 +945,9 @@ const cet = DuckDBTimestampTZValue.Epoch.toString();
827
945
  // 1970-01-01 01:00:00+01
828
946
  ```
829
947
 
948
+ `DuckDBTimestampTZNanosecondsValue` (TIMESTAMPTZ_NS) uses the same
949
+ `DuckDBTimestampTZValue.timezoneOffsetInMinutes` setting.
950
+
830
951
  Note that the timezone offset used for this string
831
952
  conversion is distinct from the `TimeZone` setting of DuckDB.
832
953
 
@@ -853,11 +974,13 @@ appender.appendInteger(42);
853
974
  appender.appendVarchar('duck');
854
975
  appender.endRow();
855
976
 
977
+ appender.flushSync();
978
+
856
979
  appender.appendInteger(123);
857
980
  appender.appendVarchar('mallard');
858
981
  appender.endRow();
859
982
 
860
- appender.flushSync();
983
+ appender.clear(); // discards the unflushed 'mallard' row
861
984
 
862
985
  appender.appendInteger(17);
863
986
  appender.appendVarchar('goose');
@@ -893,6 +1016,87 @@ appender.flushSync();
893
1016
 
894
1017
  See "Specifying Values" above for how to supply values to the appender.
895
1018
 
1019
+ ### Append Data Chunk of JS Values
1020
+
1021
+ `setRowsConverted` and `setColumnsConverted` fill a data chunk from
1022
+ values in another representation, converting on the way in.
1023
+ `JSToDuckDBValueConverter` converts from plain JS, so a `Date` can be
1024
+ written to a `TIMESTAMP` column without constructing a
1025
+ `DuckDBTimestampValue` first:
1026
+
1027
+ ```ts
1028
+ import {
1029
+ DuckDBDataChunk,
1030
+ JSToDuckDBValueConverter,
1031
+ INTEGER,
1032
+ TIMESTAMP,
1033
+ VARCHAR,
1034
+ } from '@haybarn/node-api';
1035
+
1036
+ await connection.run(
1037
+ `create or replace table target_table(
1038
+ i integer, v varchar, t timestamp
1039
+ )`
1040
+ );
1041
+
1042
+ const appender = await connection.createAppender('target_table');
1043
+
1044
+ const chunk = DuckDBDataChunk.create([INTEGER, VARCHAR, TIMESTAMP]);
1045
+ chunk.setRowsConverted(
1046
+ [
1047
+ [42, 'duck', new Date('2024-01-15T12:34:56.000Z')],
1048
+ [123, 'mallard', null],
1049
+ ],
1050
+ JSToDuckDBValueConverter
1051
+ );
1052
+
1053
+ appender.appendDataChunk(chunk);
1054
+ appender.flushSync();
1055
+ ```
1056
+
1057
+ The column types come from the chunk, so no types are passed to the
1058
+ converter. `setColumnValuesConverted` does the same for a single
1059
+ column.
1060
+
1061
+ ### Buffer Rows Into Data Chunks
1062
+
1063
+ `DuckDBDataChunkWriter` accumulates rows and emits them as filled data
1064
+ chunks, for callers producing a row at a time. `forAppender` takes the
1065
+ column types from the appender:
1066
+
1067
+ ```ts
1068
+ import {
1069
+ DuckDBDataChunkWriter,
1070
+ JSToDuckDBValueConverter,
1071
+ } from '@haybarn/node-api';
1072
+
1073
+ await connection.run(
1074
+ `create or replace table target_table(i integer, v varchar)`
1075
+ );
1076
+
1077
+ const appender = await connection.createAppender('target_table');
1078
+
1079
+ const writer = DuckDBDataChunkWriter.forAppender(appender, {
1080
+ converter: JSToDuckDBValueConverter,
1081
+ });
1082
+
1083
+ writer.appendRow([42, 'duck']);
1084
+ writer.appendRow([123, 'mallard']);
1085
+ writer.appendRow([17, 'goose']);
1086
+
1087
+ // Emits the buffered rows. The last chunk is usually a partial one.
1088
+ writer.flush();
1089
+ appender.closeSync();
1090
+ ```
1091
+
1092
+ A chunk is emitted every `rowsPerDataChunk` rows, which defaults to the
1093
+ DuckDB vector size. Omit the converter to write `DuckDBValue`s instead.
1094
+ Rows are copied as they are appended, so the same array can be reused
1095
+ across calls.
1096
+
1097
+ Callers who already have rows in chunk-sized batches do not need a writer;
1098
+ filling a data chunk directly, as above, avoids the buffering.
1099
+
896
1100
  ### Scalar Functions
897
1101
 
898
1102
  ```ts
@@ -919,6 +1123,93 @@ const rows = reader.getRows();
919
1123
  // [ [ 5 ] ]
920
1124
  ```
921
1125
 
1126
+ An optional `initFunction` runs once per DuckDB worker thread, giving each thread
1127
+ its own state:
1128
+
1129
+ ```ts
1130
+ connection.registerScalarFunction(
1131
+ DuckDBScalarFunction.create({
1132
+ name: 'my_counter',
1133
+ initFunction: (initInfo) => {
1134
+ initInfo.setState({ next: 0 });
1135
+ },
1136
+ mainFunction: (functionInfo, input, output) => {
1137
+ const state = functionInfo.state as { next: number };
1138
+ for (let rowIndex = 0; rowIndex < input.rowCount; rowIndex++) {
1139
+ output.setItem(rowIndex, state.next++);
1140
+ }
1141
+ output.flush();
1142
+ },
1143
+ returnType: INTEGER,
1144
+ volatile: true,
1145
+ })
1146
+ );
1147
+ const reader = await connection.runAndReadAll(
1148
+ 'select my_counter() from range(3)'
1149
+ );
1150
+ const rows = reader.getRows();
1151
+ // [ [ 0 ], [ 1 ], [ 2 ] ]
1152
+ ```
1153
+
1154
+ Marking the function `volatile` is required whenever its result depends on init
1155
+ state rather than only on its arguments: without it, DuckDB may treat the call as
1156
+ constant and evaluate it just once.
1157
+
1158
+ Note that this is per-thread state, unlike a table function's `initData`, which is
1159
+ shared across the scan. Init info also exposes the client context, bind data, and
1160
+ extra info, and reports errors with `setError`. Callbacks are always run on the JS
1161
+ thread, so they are serialized even when DuckDB evaluates in parallel.
1162
+
1163
+ ### Table Functions
1164
+
1165
+ ```ts
1166
+ connection.registerTableFunction(
1167
+ DuckDBTableFunction.create({
1168
+ name: 'my_range',
1169
+ parameterTypes: [INTEGER],
1170
+ bindFunction: (info) => {
1171
+ const count = info.getParameter(0) as number;
1172
+ info.addResultColumn('n', INTEGER);
1173
+ info.setBindData({ count });
1174
+ },
1175
+ initFunction: (info) => {
1176
+ info.setInitData({ nextRow: 0 });
1177
+ },
1178
+ mainFunction: (info, output) => {
1179
+ const { count } = info.bindData as { count: number };
1180
+ const initData = info.initData as { nextRow: number };
1181
+ const chunkSize = Math.min(2048, count - initData.nextRow);
1182
+ // Set the row count before writing: that is what sizes the
1183
+ // vectors.
1184
+ // A row count of zero reports that the scan is finished.
1185
+ output.rowCount = chunkSize;
1186
+ if (chunkSize > 0) {
1187
+ const column = output.getColumnVector(0);
1188
+ for (let i = 0; i < chunkSize; i++) {
1189
+ column.setItem(i, initData.nextRow + i);
1190
+ }
1191
+ column.flush();
1192
+ initData.nextRow += chunkSize;
1193
+ }
1194
+ },
1195
+ })
1196
+ );
1197
+ const reader =
1198
+ await connection.runAndReadAll('select * from my_range(3)');
1199
+ const rows = reader.getRows();
1200
+ // [ [ 0 ], [ 1 ], [ 2 ] ]
1201
+ ```
1202
+
1203
+ The main function is called repeatedly until it reports a row count of zero.
1204
+ Bind data is read-only during the scan; use init data to track progress. Setting
1205
+ `supportsProjectionPushdown: true` makes DuckDB report the columns actually
1206
+ selected, which init can read with `getColumnIndexes`.
1207
+
1208
+ For a scan that runs on several threads, set `maxThreads` from the init function
1209
+ and give each thread its own state with `localInitFunction`; the main function
1210
+ reads it with `localInitData`. Callbacks are always run on the JS thread, so they
1211
+ are serialized even when DuckDB scans in parallel.
1212
+
922
1213
  ### Extract Statements
923
1214
 
924
1215
  ```ts
@@ -1032,8 +1323,9 @@ const reader = await connection.streamAndReadAll(sql, values, types);
1032
1323
  const reader = await connection.streamAndReadUntil(sql, targetRowCount);
1033
1324
  const reader =
1034
1325
  await connection.streamAndReadUntil(sql, targetRowCount, values);
1035
- const reader =
1036
- await connection.streamAndReadUntil(sql, targetRowCount, values, types);
1326
+ const reader = await connection.streamAndReadUntil(
1327
+ sql, targetRowCount, values, types
1328
+ );
1037
1329
 
1038
1330
  // Prepared Statements
1039
1331
 
@@ -1044,7 +1336,8 @@ const prepared = await connection.prepare(sql);
1044
1336
  prepared.bind(values);
1045
1337
  prepared.bind(values, types);
1046
1338
 
1047
- // Run the prepared statement. These mirror the methods on the connection.
1339
+ // Run the prepared statement. These mirror the methods on the
1340
+ // connection.
1048
1341
  const result = prepared.run();
1049
1342
 
1050
1343
  const reader = prepared.runAndRead();
@@ -1064,11 +1357,11 @@ const pending = await connection.start(sql);
1064
1357
  const pending = await connection.start(sql, values);
1065
1358
  const pending = await connection.start(sql, values, types);
1066
1359
 
1067
- // The methods beginning with "startThenRead" provide some, but not full,
1068
- // cooperative multithreading. They use pending results to split processing
1069
- // into short tasks, but they fully materialize the result, which can
1070
- // take some time (and memory). For full cooperative multithreading,
1071
- // see the "startStreamThenRead" methods below.
1360
+ // The methods beginning with "startThenRead" provide some, but not
1361
+ // full, cooperative multithreading. They use pending results to split
1362
+ // processing into short tasks, but they fully materialize the result,
1363
+ // which can take some time (and memory). For full cooperative
1364
+ // multithreading, see the "startStreamThenRead" methods below.
1072
1365
  const reader = await connection.startThenRead(sql);
1073
1366
  const reader = await connection.startThenRead(sql, values);
1074
1367
  const reader = await connection.startThenRead(sql, values, types);
@@ -1080,8 +1373,9 @@ const reader = await connection.startThenReadAll(sql, values, types);
1080
1373
  const reader = await connection.startThenReadUntil(sql, targetRowCount);
1081
1374
  const reader =
1082
1375
  await connection.startThenReadUntil(sql, targetRowCount, values);
1083
- const reader =
1084
- await connection.startThenReadUntil(sql, targetRowCount, values, types);
1376
+ const reader = await connection.startThenReadUntil(
1377
+ sql, targetRowCount, values, types
1378
+ );
1085
1379
 
1086
1380
  // Create a pending, streaming result.
1087
1381
  const pending = await connection.startStream(sql);
@@ -1104,8 +1398,9 @@ const reader =
1104
1398
 
1105
1399
  const reader =
1106
1400
  await connection.startStreamThenReadUntil(sql, targetRowCount);
1107
- const reader =
1108
- await connection.startStreamThenReadUntil(sql, targetRowCount, values);
1401
+ const reader = await connection.startStreamThenReadUntil(
1402
+ sql, targetRowCount, values
1403
+ );
1109
1404
  const reader = await connection.startStreamThenReadUntil(
1110
1405
  sql, targetRowCount, values, types);
1111
1406
 
@@ -1,12 +1,15 @@
1
1
  import duckdb from '@haybarn/node-bindings';
2
+ import { DuckDBConnection } from './DuckDBConnection';
2
3
  import { DuckDBDataChunk } from './DuckDBDataChunk';
3
4
  import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBMapType, DuckDBStructType, DuckDBType, DuckDBUnionType } from './DuckDBType';
4
- import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBMapValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUnionValue, DuckDBUUIDValue, DuckDBValue } from './values';
5
+ import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBMapValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampTZNanosecondsValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBTupleValue, DuckDBUnionValue, DuckDBUUIDValue, DuckDBValue, DuckDBVariantValue } from './values';
5
6
  export declare class DuckDBAppender {
7
+ readonly connection: DuckDBConnection;
6
8
  private readonly appender;
7
- constructor(appender: duckdb.Appender);
9
+ constructor(connection: DuckDBConnection, appender: duckdb.Appender);
8
10
  closeSync(): void;
9
11
  flushSync(): void;
12
+ clear(): void;
10
13
  get columnCount(): number;
11
14
  columnType(columnIndex: number): DuckDBType;
12
15
  endRow(): void;
@@ -30,6 +33,7 @@ export declare class DuckDBAppender {
30
33
  appendTimeTZ(value: DuckDBTimeTZValue): void;
31
34
  appendTimestamp(value: DuckDBTimestampValue): void;
32
35
  appendTimestampTZ(value: DuckDBTimestampTZValue): void;
36
+ appendTimestampTZNanoseconds(value: DuckDBTimestampTZNanosecondsValue): void;
33
37
  appendTimestampSeconds(value: DuckDBTimestampSecondsValue): void;
34
38
  appendTimestampMilliseconds(value: DuckDBTimestampMillisecondsValue): void;
35
39
  appendTimestampNanoseconds(value: DuckDBTimestampNanosecondsValue): void;
@@ -39,12 +43,14 @@ export declare class DuckDBAppender {
39
43
  appendEnum(value: string, type: DuckDBEnumType): void;
40
44
  appendList(value: DuckDBListValue | readonly DuckDBValue[], type?: DuckDBListType): void;
41
45
  appendStruct(value: DuckDBStructValue | Readonly<Record<string, DuckDBValue>>, type?: DuckDBStructType): void;
46
+ appendTuple(value: DuckDBTupleValue | readonly DuckDBValue[], type?: DuckDBStructType): void;
42
47
  appendMap(value: DuckDBMapValue, type?: DuckDBMapType): void;
43
48
  appendArray(value: DuckDBArrayValue | readonly DuckDBValue[], type?: DuckDBArrayType): void;
44
49
  appendUnion(value: DuckDBUnionValue, type?: DuckDBUnionType): void;
45
50
  appendUUID(value: DuckDBUUIDValue): void;
46
51
  appendBit(value: DuckDBBitValue): void;
47
52
  appendBigNum(value: bigint): void;
53
+ appendVariant(value: DuckDBVariantValue | null): void;
48
54
  appendNull(): void;
49
55
  appendValue(value: DuckDBValue, type?: DuckDBType): void;
50
56
  appendDataChunk(dataChunk: DuckDBDataChunk): void;
@@ -11,8 +11,10 @@ const DuckDBType_1 = require("./DuckDBType");
11
11
  const typeForValue_1 = require("./typeForValue");
12
12
  const values_1 = require("./values");
13
13
  class DuckDBAppender {
14
+ connection;
14
15
  appender;
15
- constructor(appender) {
16
+ constructor(connection, appender) {
17
+ this.connection = connection;
16
18
  this.appender = appender;
17
19
  }
18
20
  closeSync() {
@@ -21,6 +23,9 @@ class DuckDBAppender {
21
23
  flushSync() {
22
24
  node_bindings_1.default.appender_flush_sync(this.appender);
23
25
  }
26
+ clear() {
27
+ node_bindings_1.default.appender_clear(this.appender);
28
+ }
24
29
  get columnCount() {
25
30
  return node_bindings_1.default.appender_column_count(this.appender);
26
31
  }
@@ -91,6 +96,9 @@ class DuckDBAppender {
91
96
  appendTimestampTZ(value) {
92
97
  this.appendValue(value, DuckDBType_1.TIMESTAMPTZ);
93
98
  }
99
+ appendTimestampTZNanoseconds(value) {
100
+ this.appendValue(value, DuckDBType_1.TIMESTAMPTZ_NS);
101
+ }
94
102
  appendTimestampSeconds(value) {
95
103
  this.appendValue(value, DuckDBType_1.TIMESTAMP_S);
96
104
  }
@@ -118,6 +126,9 @@ class DuckDBAppender {
118
126
  appendStruct(value, type) {
119
127
  this.appendValue(value instanceof values_1.DuckDBStructValue ? value : (0, values_1.structValue)(value), type);
120
128
  }
129
+ appendTuple(value, type) {
130
+ this.appendValue(value instanceof values_1.DuckDBTupleValue ? value : (0, values_1.tupleValue)(value), type);
131
+ }
121
132
  appendMap(value, type) {
122
133
  this.appendValue(value, type);
123
134
  }
@@ -136,6 +147,13 @@ class DuckDBAppender {
136
147
  appendBigNum(value) {
137
148
  this.appendValue(value, DuckDBType_1.BIGNUM);
138
149
  }
150
+ appendVariant(value) {
151
+ if (value === null) {
152
+ this.appendNull();
153
+ return;
154
+ }
155
+ this.appendValue(value, DuckDBType_1.VARIANT);
156
+ }
139
157
  appendNull() {
140
158
  node_bindings_1.default.append_null(this.appender);
141
159
  }
@@ -9,6 +9,7 @@ import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
9
9
  import { DuckDBResult } from './DuckDBResult';
10
10
  import { DuckDBResultReader } from './DuckDBResultReader';
11
11
  import { DuckDBScalarFunction } from './DuckDBScalarFunction';
12
+ import { DuckDBTableFunction } from './DuckDBTableFunction';
12
13
  import { DuckDBType } from './DuckDBType';
13
14
  import { DuckDBValue } from './values';
14
15
  export declare class DuckDBConnection {
@@ -45,5 +46,6 @@ export declare class DuckDBConnection {
45
46
  private runUntilLast;
46
47
  getTableNames(query: string, qualified: boolean): readonly string[];
47
48
  createAppender(table: string, schema?: string | null, catalog?: string | null): Promise<DuckDBAppender>;
49
+ registerTableFunction(tableFunction: DuckDBTableFunction): void;
48
50
  registerScalarFunction(scalarFunction: DuckDBScalarFunction): void;
49
51
  }
@@ -199,7 +199,10 @@ class DuckDBConnection {
199
199
  return names;
200
200
  }
201
201
  async createAppender(table, schema, catalog) {
202
- return new DuckDBAppender_1.DuckDBAppender(node_bindings_1.default.appender_create_ext(this.connection, catalog ?? null, schema ?? null, table));
202
+ return new DuckDBAppender_1.DuckDBAppender(this, node_bindings_1.default.appender_create_ext(this.connection, catalog ?? null, schema ?? null, table));
203
+ }
204
+ registerTableFunction(tableFunction) {
205
+ node_bindings_1.default.register_table_function(this.connection, tableFunction.table_function);
203
206
  }
204
207
  registerScalarFunction(scalarFunction) {
205
208
  node_bindings_1.default.register_scalar_function(this.connection, scalarFunction.scalar_function);
@@ -1,6 +1,7 @@
1
1
  import duckdb from '@haybarn/node-bindings';
2
2
  import { DuckDBType } from './DuckDBType';
3
3
  import { DuckDBValueConverter } from './DuckDBValueConverter';
4
+ import { ToDuckDBValueConverter } from './ToDuckDBValueConverter';
4
5
  import { DuckDBVector } from './DuckDBVector';
5
6
  import { DuckDBValue } from './values';
6
7
  export declare class DuckDBDataChunk {
@@ -12,17 +13,38 @@ export declare class DuckDBDataChunk {
12
13
  get columnCount(): number;
13
14
  get rowCount(): number;
14
15
  set rowCount(count: number);
16
+ /**
17
+ * Refuses a column count that does not match the chunk's.
18
+ *
19
+ * A short array would leave the remaining vectors never written and never
20
+ * flushed while the chunk reports a non-zero row count, and reading or
21
+ * appending it then crashes the process instead of raising.
22
+ */
23
+ private assertColumnCount;
15
24
  getColumnVector(columnIndex: number): DuckDBVector;
16
25
  visitColumnValues(columnIndex: number, visitValue: (value: DuckDBValue, rowIndex: number, columnIndex: number, type: DuckDBType) => void): void;
17
26
  appendColumnValues(columnIndex: number, values: DuckDBValue[]): void;
18
27
  getColumnValues(columnIndex: number): DuckDBValue[];
19
28
  convertColumnValues<T>(columnIndex: number, converter: DuckDBValueConverter<T>): (T | null)[];
20
29
  setColumnValues(columnIndex: number, values: readonly DuckDBValue[]): void;
30
+ /**
31
+ * `setColumnValues` with each value converted on the way in: the write
32
+ * counterpart of `convertColumnValues`.
33
+ *
34
+ * The column's type comes from its vector, so the converter is the only
35
+ * thing the caller supplies.
36
+ */
37
+ setColumnValuesConverted<T>(columnIndex: number, values: readonly (T | null)[], converter: ToDuckDBValueConverter<T>): void;
21
38
  visitColumns(visitColumn: (column: DuckDBValue[], columnIndex: number, type: DuckDBType) => void): void;
22
39
  appendToColumns(columns: (DuckDBValue[] | undefined)[]): void;
23
40
  getColumns(): DuckDBValue[][];
24
41
  convertColumns<T>(converter: DuckDBValueConverter<T>): (T | null)[][];
25
42
  setColumns(columns: readonly (readonly DuckDBValue[])[]): void;
43
+ /**
44
+ * `setColumns` with each value converted on the way in: the write
45
+ * counterpart of `convertColumns`.
46
+ */
47
+ setColumnsConverted<T>(columns: readonly (readonly (T | null)[])[], converter: ToDuckDBValueConverter<T>): void;
26
48
  appendToColumnsObject(columnNames: readonly string[], columnsObject: Record<string, DuckDBValue[] | undefined>): void;
27
49
  getColumnsObject(columnNames: readonly string[]): Record<string, DuckDBValue[]>;
28
50
  visitColumnMajor(visitValue: (value: DuckDBValue, rowIndex: number, columnIndex: number, type: DuckDBType) => void): void;
@@ -35,6 +57,14 @@ export declare class DuckDBDataChunk {
35
57
  getRows(): DuckDBValue[][];
36
58
  convertRows<T>(converter: DuckDBValueConverter<T>): (T | null)[][];
37
59
  setRows(rows: readonly (readonly DuckDBValue[])[]): void;
60
+ /**
61
+ * `setRows` with each value converted on the way in: the write counterpart
62
+ * of `convertRows`.
63
+ *
64
+ * Each column's type comes from its vector, so the converter is the only
65
+ * thing the caller supplies.
66
+ */
67
+ setRowsConverted<T>(rows: readonly (readonly (T | null)[])[], converter: ToDuckDBValueConverter<T>): void;
38
68
  appendToRowObjects(columnNames: readonly string[], rowObjects: Record<string, DuckDBValue>[]): void;
39
69
  getRowObjects(columnNames: readonly string[]): Record<string, DuckDBValue>[];
40
70
  visitRowMajor(visitValue: (value: DuckDBValue, rowIndex: number, columnIndex: number, type: DuckDBType) => void): void;