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

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 -21
  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
 
@@ -41,7 +48,6 @@ for the most up-to-date roadmap.
41
48
  - Linux x64 glibc
42
49
  - Linux x64 musl
43
50
  - Mac OS X (Darwin) arm64 (Apple Silicon)
44
- - Mac OS X (Darwin) x64 (Intel)
45
51
  - Windows (Win32) arm64
46
52
  - Windows (Win32) x64
47
53
 
@@ -213,16 +219,50 @@ These are:
213
219
  | `LIST` | `listValue` |
214
220
  | `MAP` | `mapValue` |
215
221
  | `STRUCT` | `structValue` |
222
+ | `STRUCT` (unnamed, a tuple) | `tupleValue` |
216
223
  | `TIME` | `timeValue` |
217
224
  | `TIMETZ` | `timeTZValue` |
218
225
  | `TIMESTAMP` | `timestampValue` |
219
226
  | `TIMESTAMPTZ` | `timestampTZValue` |
227
+ | `TIMESTAMPTZ_NS` | `timestampTZNanosValue` |
220
228
  | `TIMESTAMP_S` | `timestampSecondsValue` |
221
229
  | `TIMESTAMP_MS` | `timestampMillisValue` |
222
230
  | `TIMESTAMP_NS` | `timestampNanosValue` |
223
231
  | `UNION` | `unionValue` |
224
232
  | `UUID` | `uuidValue` |
225
233
 
234
+ Alternatively, `jsToDuckDBValue` converts a plain JS value to the form
235
+ a given DuckDB type expects, so these functions need not be called
236
+ directly:
237
+
238
+ ```ts
239
+ import { jsToDuckDBValue, DATE, TIMESTAMP_MS } from '@haybarn/node-api';
240
+
241
+ jsToDuckDBValue(new Date('2024-01-15T12:34:56.789Z'), TIMESTAMP_MS);
242
+ // same as timestampMillisValue(1705322096789n)
243
+
244
+ jsToDuckDBValue(new Date('2024-01-15T00:00:00.000Z'), DATE);
245
+ // same as dateValue(19737)
246
+
247
+ jsToDuckDBValue(null, DATE); // null, for any type
248
+ ```
249
+
250
+ It is generic over the type, so a statically known one checks its input:
251
+
252
+ ```ts
253
+ jsToDuckDBValue(new Date(), TIMESTAMP); // ok
254
+ jsToDuckDBValue(new Date(), INTEGER); // rejected at compile time
255
+ ```
256
+
257
+ What each type accepts is given by `JSInputTypeForTypeId`, and by
258
+ `JSInputTypeFor` when keyed by a `DuckDBType`. These are wider than
259
+ what is read back where a second spelling is unambiguous: `BIGINT` and
260
+ the wider integers accept `number` as well as `bigint`, and `DECIMAL`
261
+ accepts either a double or a raw scaled `bigint`.
262
+
263
+ The result is a `DuckDBValue`, which is what `appendValue`,
264
+ `bindValue`, and `setRows` all accept.
265
+
226
266
  ### Stream Results
227
267
 
228
268
  Streaming results evaluate lazily when rows are read.
@@ -231,6 +271,38 @@ Streaming results evaluate lazily when rows are read.
231
271
  const result = await connection.stream('from range(10_000)');
232
272
  ```
233
273
 
274
+ ### Close Results
275
+
276
+ Results are destroyed automatically soon after their reference is
277
+ dropped, but you can also close them explicitly to free their memory:
278
+
279
+ ```ts
280
+ result.closeSync();
281
+ ```
282
+
283
+ From DuckDB 2.0, a streaming result that hasn't been read to the end, or
284
+ a pending result that hasn't been executed, blocks its connection: the
285
+ next statement on it fails until the result is closed. A result reader
286
+ or pending result can be closed the same way:
287
+
288
+ ```ts
289
+ const reader = await connection.streamAndReadUntil(sql, 100);
290
+ reader.closeSync();
291
+ const rows = reader.getRows(); // rows already read stay available
292
+ ```
293
+
294
+ Column names and types also stay available after closing; reading more
295
+ rows throws.
296
+
297
+ The same applies to appenders: from DuckDB 2.0, an appender can't flush
298
+ while its connection has such a result. Appenders flush on `flushSync()`
299
+ and `closeSync()`, and automatically about every 204,800 rows, so with a
300
+ streaming result open, appending fails at the next flush, and the rows
301
+ appended since the last successful flush are lost. Read the result to the
302
+ end or close it before appending, or append on a separate connection.
303
+ Close appenders explicitly too: one that is flushed when it's garbage
304
+ collected can't report a failure.
305
+
234
306
  ### Inspect Result Metadata
235
307
 
236
308
  Get column names and types:
@@ -577,6 +649,45 @@ const columnNameAndTypeObjects = reader.columnNameAndTypeObjectsJson();
577
649
  // ]
578
650
  ```
579
651
 
652
+ ### Infer JS Types from DuckDB Types
653
+
654
+ The mapping each converter applies is also available at the type level.
655
+ `JSTypeFor` gives the JS type that `getRowsJS` and the other `JS` methods
656
+ produce for a given DuckDB type; `JsonTypeFor` does the same for the `Json`
657
+ methods.
658
+
659
+ ```ts
660
+ import {
661
+ JSTypeFor,
662
+ JsonTypeFor,
663
+ DuckDBBigIntType,
664
+ DuckDBIntegerType,
665
+ DuckDBTimestampTZType,
666
+ } from '@haybarn/node-api';
667
+
668
+ type A = JSTypeFor<DuckDBIntegerType>; // number
669
+ type B = JSTypeFor<DuckDBBigIntType>; // bigint
670
+ type C = JSTypeFor<DuckDBTimestampTZType>; // Date
671
+
672
+ type D = JsonTypeFor<DuckDBBigIntType>; // string
673
+ type E = JsonTypeFor<DuckDBTimestampTZType>; // string
674
+ ```
675
+
676
+ The two differ wherever a value has no lossless JSON form: 64-bit and
677
+ wider integers, temporal types, `DECIMAL`, `BLOB`, `BIT` and `GEOMETRY`
678
+ render as strings, and `FLOAT` and `DOUBLE` widen to `number | string`
679
+ so that Infinity and NaN survive.
680
+
681
+ Both are also available keyed by type id, as `JSTypeForTypeId` and
682
+ `JsonTypeForTypeId`, which is the form to use when the id is what you have:
683
+
684
+ ```ts
685
+ type F = JSTypeForTypeId[DuckDBTypeId.INTEGER]; // number
686
+ ```
687
+
688
+ These describe non-NULL values. Since any column can be NULL, a value read
689
+ from one is `JSTypeFor<T> | null`.
690
+
580
691
  ### Fetch Chunks
581
692
 
582
693
  Fetch all chunks:
@@ -611,7 +722,8 @@ Get chunk data:
611
722
  ```ts
612
723
  const rows = chunk.getRows();
613
724
 
614
- const rowObjects = chunk.getRowObjects(result.deduplicatedColumnNames());
725
+ const rowObjects =
726
+ chunk.getRowObjects(result.deduplicatedColumnNames());
615
727
 
616
728
  const columns = chunk.getColumns();
617
729
 
@@ -740,8 +852,13 @@ if (columnType.typeId === DuckDBTypeId.MAP) {
740
852
  }
741
853
 
742
854
  if (columnType.typeId === DuckDBTypeId.STRUCT) {
743
- // { name1: value1, name2: value2, ... }
744
- const structEntries = columnValue.entries;
855
+ if (columnType.isTuple) {
856
+ // An unnamed struct, such as (1, 'a'): items in entry order
857
+ const tupleItems = columnValue.items; // array of values
858
+ } else {
859
+ // { name1: value1, name2: value2, ... }
860
+ const structEntries = columnValue.entries;
861
+ }
745
862
  const structString = columnValue.toString();
746
863
  }
747
864
 
@@ -810,9 +927,9 @@ if (columnType.typeId === DuckDBTypeId.UUID) {
810
927
 
811
928
  ### Displaying Timezones
812
929
 
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.
930
+ Converting a TIMESTAMP_TZ or TIMESTAMPTZ_NS value to a string depends on
931
+ a timezone offset. By default, this is set to the offset for the local
932
+ timezone when the Node process is started.
816
933
 
817
934
  To change it, set the `timezoneOffsetInMinutes`
818
935
  property of `DuckDBTimestampTZValue`:
@@ -827,6 +944,9 @@ const cet = DuckDBTimestampTZValue.Epoch.toString();
827
944
  // 1970-01-01 01:00:00+01
828
945
  ```
829
946
 
947
+ `DuckDBTimestampTZNanosecondsValue` (TIMESTAMPTZ_NS) uses the same
948
+ `DuckDBTimestampTZValue.timezoneOffsetInMinutes` setting.
949
+
830
950
  Note that the timezone offset used for this string
831
951
  conversion is distinct from the `TimeZone` setting of DuckDB.
832
952
 
@@ -853,11 +973,13 @@ appender.appendInteger(42);
853
973
  appender.appendVarchar('duck');
854
974
  appender.endRow();
855
975
 
976
+ appender.flushSync();
977
+
856
978
  appender.appendInteger(123);
857
979
  appender.appendVarchar('mallard');
858
980
  appender.endRow();
859
981
 
860
- appender.flushSync();
982
+ appender.clear(); // discards the unflushed 'mallard' row
861
983
 
862
984
  appender.appendInteger(17);
863
985
  appender.appendVarchar('goose');
@@ -893,6 +1015,87 @@ appender.flushSync();
893
1015
 
894
1016
  See "Specifying Values" above for how to supply values to the appender.
895
1017
 
1018
+ ### Append Data Chunk of JS Values
1019
+
1020
+ `setRowsConverted` and `setColumnsConverted` fill a data chunk from
1021
+ values in another representation, converting on the way in.
1022
+ `JSToDuckDBValueConverter` converts from plain JS, so a `Date` can be
1023
+ written to a `TIMESTAMP` column without constructing a
1024
+ `DuckDBTimestampValue` first:
1025
+
1026
+ ```ts
1027
+ import {
1028
+ DuckDBDataChunk,
1029
+ JSToDuckDBValueConverter,
1030
+ INTEGER,
1031
+ TIMESTAMP,
1032
+ VARCHAR,
1033
+ } from '@haybarn/node-api';
1034
+
1035
+ await connection.run(
1036
+ `create or replace table target_table(
1037
+ i integer, v varchar, t timestamp
1038
+ )`
1039
+ );
1040
+
1041
+ const appender = await connection.createAppender('target_table');
1042
+
1043
+ const chunk = DuckDBDataChunk.create([INTEGER, VARCHAR, TIMESTAMP]);
1044
+ chunk.setRowsConverted(
1045
+ [
1046
+ [42, 'duck', new Date('2024-01-15T12:34:56.000Z')],
1047
+ [123, 'mallard', null],
1048
+ ],
1049
+ JSToDuckDBValueConverter
1050
+ );
1051
+
1052
+ appender.appendDataChunk(chunk);
1053
+ appender.flushSync();
1054
+ ```
1055
+
1056
+ The column types come from the chunk, so no types are passed to the
1057
+ converter. `setColumnValuesConverted` does the same for a single
1058
+ column.
1059
+
1060
+ ### Buffer Rows Into Data Chunks
1061
+
1062
+ `DuckDBDataChunkWriter` accumulates rows and emits them as filled data
1063
+ chunks, for callers producing a row at a time. `forAppender` takes the
1064
+ column types from the appender:
1065
+
1066
+ ```ts
1067
+ import {
1068
+ DuckDBDataChunkWriter,
1069
+ JSToDuckDBValueConverter,
1070
+ } from '@haybarn/node-api';
1071
+
1072
+ await connection.run(
1073
+ `create or replace table target_table(i integer, v varchar)`
1074
+ );
1075
+
1076
+ const appender = await connection.createAppender('target_table');
1077
+
1078
+ const writer = DuckDBDataChunkWriter.forAppender(appender, {
1079
+ converter: JSToDuckDBValueConverter,
1080
+ });
1081
+
1082
+ writer.appendRow([42, 'duck']);
1083
+ writer.appendRow([123, 'mallard']);
1084
+ writer.appendRow([17, 'goose']);
1085
+
1086
+ // Emits the buffered rows. The last chunk is usually a partial one.
1087
+ writer.flush();
1088
+ appender.closeSync();
1089
+ ```
1090
+
1091
+ A chunk is emitted every `rowsPerDataChunk` rows, which defaults to the
1092
+ DuckDB vector size. Omit the converter to write `DuckDBValue`s instead.
1093
+ Rows are copied as they are appended, so the same array can be reused
1094
+ across calls.
1095
+
1096
+ Callers who already have rows in chunk-sized batches do not need a writer;
1097
+ filling a data chunk directly, as above, avoids the buffering.
1098
+
896
1099
  ### Scalar Functions
897
1100
 
898
1101
  ```ts
@@ -919,6 +1122,93 @@ const rows = reader.getRows();
919
1122
  // [ [ 5 ] ]
920
1123
  ```
921
1124
 
1125
+ An optional `initFunction` runs once per DuckDB worker thread, giving each thread
1126
+ its own state:
1127
+
1128
+ ```ts
1129
+ connection.registerScalarFunction(
1130
+ DuckDBScalarFunction.create({
1131
+ name: 'my_counter',
1132
+ initFunction: (initInfo) => {
1133
+ initInfo.setState({ next: 0 });
1134
+ },
1135
+ mainFunction: (functionInfo, input, output) => {
1136
+ const state = functionInfo.state as { next: number };
1137
+ for (let rowIndex = 0; rowIndex < input.rowCount; rowIndex++) {
1138
+ output.setItem(rowIndex, state.next++);
1139
+ }
1140
+ output.flush();
1141
+ },
1142
+ returnType: INTEGER,
1143
+ volatile: true,
1144
+ })
1145
+ );
1146
+ const reader = await connection.runAndReadAll(
1147
+ 'select my_counter() from range(3)'
1148
+ );
1149
+ const rows = reader.getRows();
1150
+ // [ [ 0 ], [ 1 ], [ 2 ] ]
1151
+ ```
1152
+
1153
+ Marking the function `volatile` is required whenever its result depends on init
1154
+ state rather than only on its arguments: without it, DuckDB may treat the call as
1155
+ constant and evaluate it just once.
1156
+
1157
+ Note that this is per-thread state, unlike a table function's `initData`, which is
1158
+ shared across the scan. Init info also exposes the client context, bind data, and
1159
+ extra info, and reports errors with `setError`. Callbacks are always run on the JS
1160
+ thread, so they are serialized even when DuckDB evaluates in parallel.
1161
+
1162
+ ### Table Functions
1163
+
1164
+ ```ts
1165
+ connection.registerTableFunction(
1166
+ DuckDBTableFunction.create({
1167
+ name: 'my_range',
1168
+ parameterTypes: [INTEGER],
1169
+ bindFunction: (info) => {
1170
+ const count = info.getParameter(0) as number;
1171
+ info.addResultColumn('n', INTEGER);
1172
+ info.setBindData({ count });
1173
+ },
1174
+ initFunction: (info) => {
1175
+ info.setInitData({ nextRow: 0 });
1176
+ },
1177
+ mainFunction: (info, output) => {
1178
+ const { count } = info.bindData as { count: number };
1179
+ const initData = info.initData as { nextRow: number };
1180
+ const chunkSize = Math.min(2048, count - initData.nextRow);
1181
+ // Set the row count before writing: that is what sizes the
1182
+ // vectors.
1183
+ // A row count of zero reports that the scan is finished.
1184
+ output.rowCount = chunkSize;
1185
+ if (chunkSize > 0) {
1186
+ const column = output.getColumnVector(0);
1187
+ for (let i = 0; i < chunkSize; i++) {
1188
+ column.setItem(i, initData.nextRow + i);
1189
+ }
1190
+ column.flush();
1191
+ initData.nextRow += chunkSize;
1192
+ }
1193
+ },
1194
+ })
1195
+ );
1196
+ const reader =
1197
+ await connection.runAndReadAll('select * from my_range(3)');
1198
+ const rows = reader.getRows();
1199
+ // [ [ 0 ], [ 1 ], [ 2 ] ]
1200
+ ```
1201
+
1202
+ The main function is called repeatedly until it reports a row count of zero.
1203
+ Bind data is read-only during the scan; use init data to track progress. Setting
1204
+ `supportsProjectionPushdown: true` makes DuckDB report the columns actually
1205
+ selected, which init can read with `getColumnIndexes`.
1206
+
1207
+ For a scan that runs on several threads, set `maxThreads` from the init function
1208
+ and give each thread its own state with `localInitFunction`; the main function
1209
+ reads it with `localInitData`. Callbacks are always run on the JS thread, so they
1210
+ are serialized even when DuckDB scans in parallel.
1211
+
922
1212
  ### Extract Statements
923
1213
 
924
1214
  ```ts
@@ -1032,8 +1322,9 @@ const reader = await connection.streamAndReadAll(sql, values, types);
1032
1322
  const reader = await connection.streamAndReadUntil(sql, targetRowCount);
1033
1323
  const reader =
1034
1324
  await connection.streamAndReadUntil(sql, targetRowCount, values);
1035
- const reader =
1036
- await connection.streamAndReadUntil(sql, targetRowCount, values, types);
1325
+ const reader = await connection.streamAndReadUntil(
1326
+ sql, targetRowCount, values, types
1327
+ );
1037
1328
 
1038
1329
  // Prepared Statements
1039
1330
 
@@ -1044,7 +1335,8 @@ const prepared = await connection.prepare(sql);
1044
1335
  prepared.bind(values);
1045
1336
  prepared.bind(values, types);
1046
1337
 
1047
- // Run the prepared statement. These mirror the methods on the connection.
1338
+ // Run the prepared statement. These mirror the methods on the
1339
+ // connection.
1048
1340
  const result = prepared.run();
1049
1341
 
1050
1342
  const reader = prepared.runAndRead();
@@ -1064,11 +1356,11 @@ const pending = await connection.start(sql);
1064
1356
  const pending = await connection.start(sql, values);
1065
1357
  const pending = await connection.start(sql, values, types);
1066
1358
 
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.
1359
+ // The methods beginning with "startThenRead" provide some, but not
1360
+ // full, cooperative multithreading. They use pending results to split
1361
+ // processing into short tasks, but they fully materialize the result,
1362
+ // which can take some time (and memory). For full cooperative
1363
+ // multithreading, see the "startStreamThenRead" methods below.
1072
1364
  const reader = await connection.startThenRead(sql);
1073
1365
  const reader = await connection.startThenRead(sql, values);
1074
1366
  const reader = await connection.startThenRead(sql, values, types);
@@ -1080,8 +1372,9 @@ const reader = await connection.startThenReadAll(sql, values, types);
1080
1372
  const reader = await connection.startThenReadUntil(sql, targetRowCount);
1081
1373
  const reader =
1082
1374
  await connection.startThenReadUntil(sql, targetRowCount, values);
1083
- const reader =
1084
- await connection.startThenReadUntil(sql, targetRowCount, values, types);
1375
+ const reader = await connection.startThenReadUntil(
1376
+ sql, targetRowCount, values, types
1377
+ );
1085
1378
 
1086
1379
  // Create a pending, streaming result.
1087
1380
  const pending = await connection.startStream(sql);
@@ -1104,8 +1397,9 @@ const reader =
1104
1397
 
1105
1398
  const reader =
1106
1399
  await connection.startStreamThenReadUntil(sql, targetRowCount);
1107
- const reader =
1108
- await connection.startStreamThenReadUntil(sql, targetRowCount, values);
1400
+ const reader = await connection.startStreamThenReadUntil(
1401
+ sql, targetRowCount, values
1402
+ );
1109
1403
  const reader = await connection.startStreamThenReadUntil(
1110
1404
  sql, targetRowCount, values, types);
1111
1405
 
@@ -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;