@avidian/duckdb-bun 0.0.0-stage → 1.0.0

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 (231) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +284 -2
  3. package/package.json +95 -4
  4. package/src/bindings/api/appender.ts +288 -0
  5. package/src/bindings/api/data-chunk.ts +58 -0
  6. package/src/bindings/api/database.ts +232 -0
  7. package/src/bindings/api/datetime.ts +158 -0
  8. package/src/bindings/api/index.ts +13 -0
  9. package/src/bindings/api/logical-types.ts +227 -0
  10. package/src/bindings/api/query.ts +616 -0
  11. package/src/bindings/api/scalar-function.ts +274 -0
  12. package/src/bindings/api/table-function.ts +339 -0
  13. package/src/bindings/api/values.ts +546 -0
  14. package/src/bindings/api/vector.ts +266 -0
  15. package/src/bindings/generated/capi.ts +695 -0
  16. package/src/bindings/generated/contract.ts +162 -0
  17. package/src/bindings/index.ts +10 -0
  18. package/src/bindings/runtime/convert.ts +307 -0
  19. package/src/bindings/runtime/diagnostics.ts +45 -0
  20. package/src/bindings/runtime/dispatch.ts +200 -0
  21. package/src/bindings/runtime/exception.ts +103 -0
  22. package/src/bindings/runtime/flags.ts +19 -0
  23. package/src/bindings/runtime/handle.ts +217 -0
  24. package/src/bindings/runtime/kinds.ts +53 -0
  25. package/src/bindings/runtime/marshal.ts +190 -0
  26. package/src/bindings/runtime/native.ts +150 -0
  27. package/src/bindings/runtime/ring.ts +54 -0
  28. package/src/bindings/runtime/scope.ts +133 -0
  29. package/src/bindings/runtime/trace.ts +65 -0
  30. package/src/connection.ts +35 -0
  31. package/src/database.ts +27 -0
  32. package/src/errors.ts +30 -0
  33. package/src/file-assets.d.ts +10 -0
  34. package/src/index.ts +17 -0
  35. package/src/library.ts +83 -0
  36. package/src/neo.ts +16 -0
  37. package/src/reader.ts +47 -0
  38. package/src/statement.ts +61 -0
  39. package/src/types.ts +52 -0
  40. package/src/version.ts +6 -0
  41. package/vendor/node-api/LICENSE +7 -0
  42. package/vendor/node-api/PROVENANCE.md +54 -0
  43. package/vendor/node-api/node-bindings.d.ts +1669 -0
  44. package/vendor/node-api/src/DuckDBAppender.ts +237 -0
  45. package/vendor/node-api/src/DuckDBClientContext.ts +13 -0
  46. package/vendor/node-api/src/DuckDBConnection.ts +315 -0
  47. package/vendor/node-api/src/DuckDBDataChunk.ts +412 -0
  48. package/vendor/node-api/src/DuckDBDataChunkWriter.ts +144 -0
  49. package/vendor/node-api/src/DuckDBExtractedStatements.ts +37 -0
  50. package/vendor/node-api/src/DuckDBInstance.ts +35 -0
  51. package/vendor/node-api/src/DuckDBInstanceCache.ts +29 -0
  52. package/vendor/node-api/src/DuckDBLogicalType.ts +446 -0
  53. package/vendor/node-api/src/DuckDBMaterializedResult.ts +39 -0
  54. package/vendor/node-api/src/DuckDBPendingResult.ts +83 -0
  55. package/vendor/node-api/src/DuckDBPreparedStatement.ts +376 -0
  56. package/vendor/node-api/src/DuckDBPreparedStatementCollection.ts +5 -0
  57. package/vendor/node-api/src/DuckDBPreparedStatementWeakRefCollection.ts +31 -0
  58. package/vendor/node-api/src/DuckDBResult.ts +403 -0
  59. package/vendor/node-api/src/DuckDBResultReader.ts +283 -0
  60. package/vendor/node-api/src/DuckDBScalarFunction.ts +149 -0
  61. package/vendor/node-api/src/DuckDBScalarFunctionBindInfo.ts +34 -0
  62. package/vendor/node-api/src/DuckDBScalarFunctionInfo.ts +34 -0
  63. package/vendor/node-api/src/DuckDBScalarFunctionInitInfo.ts +35 -0
  64. package/vendor/node-api/src/DuckDBTableFunction.ts +149 -0
  65. package/vendor/node-api/src/DuckDBTableFunctionBindInfo.ts +56 -0
  66. package/vendor/node-api/src/DuckDBTableFunctionInfo.ts +36 -0
  67. package/vendor/node-api/src/DuckDBTableFunctionInitInfo.ts +52 -0
  68. package/vendor/node-api/src/DuckDBType.ts +1 -0
  69. package/vendor/node-api/src/DuckDBTypeId.ts +46 -0
  70. package/vendor/node-api/src/DuckDBValueConverter.ts +23 -0
  71. package/vendor/node-api/src/DuckDBValueConverters.ts +461 -0
  72. package/vendor/node-api/src/DuckDBVector.ts +1 -0
  73. package/vendor/node-api/src/JS.ts +11 -0
  74. package/vendor/node-api/src/JSDuckDBValueConverter.ts +85 -0
  75. package/vendor/node-api/src/JSInputTypeForTypeId.ts +101 -0
  76. package/vendor/node-api/src/JSToDuckDBValueConverter.ts +136 -0
  77. package/vendor/node-api/src/JSTypeForTypeId.ts +78 -0
  78. package/vendor/node-api/src/Json.ts +7 -0
  79. package/vendor/node-api/src/JsonDuckDBValueConverter.ts +72 -0
  80. package/vendor/node-api/src/JsonTypeForTypeId.ts +86 -0
  81. package/vendor/node-api/src/ToDuckDBValueConverter.ts +68 -0
  82. package/vendor/node-api/src/ToDuckDBValueConverters.ts +303 -0
  83. package/vendor/node-api/src/configurationOptionDescriptions.ts +13 -0
  84. package/vendor/node-api/src/conversion/bytesFromString.ts +5 -0
  85. package/vendor/node-api/src/conversion/dateTimeStringConversion.ts +343 -0
  86. package/vendor/node-api/src/conversion/displayStringForDuckDBValue.ts +12 -0
  87. package/vendor/node-api/src/conversion/stringFromBlob.ts +48 -0
  88. package/vendor/node-api/src/conversion/stringFromDecimal.ts +129 -0
  89. package/vendor/node-api/src/conversion/varintDecode.ts +42 -0
  90. package/vendor/node-api/src/convertColumnsFromChunks.ts +28 -0
  91. package/vendor/node-api/src/convertColumnsObjectFromChunks.ts +29 -0
  92. package/vendor/node-api/src/convertRowObjectsFromChunks.ts +21 -0
  93. package/vendor/node-api/src/convertRowsFromChunks.ts +16 -0
  94. package/vendor/node-api/src/createConfig.ts +14 -0
  95. package/vendor/node-api/src/createDuckDBValueConverter.ts +17 -0
  96. package/vendor/node-api/src/createResult.ts +15 -0
  97. package/vendor/node-api/src/createValue.ts +355 -0
  98. package/vendor/node-api/src/duckdb.ts +51 -0
  99. package/vendor/node-api/src/enums.ts +7 -0
  100. package/vendor/node-api/src/getColumnsFromChunks.ts +13 -0
  101. package/vendor/node-api/src/getColumnsObjectFromChunks.ts +16 -0
  102. package/vendor/node-api/src/getRowObjectsFromChunks.ts +13 -0
  103. package/vendor/node-api/src/getRowsFromChunks.ts +12 -0
  104. package/vendor/node-api/src/index.ts +3 -0
  105. package/vendor/node-api/src/readValue.ts +31 -0
  106. package/vendor/node-api/src/sleep.ts +5 -0
  107. package/vendor/node-api/src/sql.ts +7 -0
  108. package/vendor/node-api/src/tsconfig.json +7 -0
  109. package/vendor/node-api/src/typeForValue.ts +144 -0
  110. package/vendor/node-api/src/types/BaseDuckDBType.ts +31 -0
  111. package/vendor/node-api/src/types/DuckDBAnyType.ts +13 -0
  112. package/vendor/node-api/src/types/DuckDBArrayType.ts +43 -0
  113. package/vendor/node-api/src/types/DuckDBBigIntType.ts +21 -0
  114. package/vendor/node-api/src/types/DuckDBBigNumType.ts +21 -0
  115. package/vendor/node-api/src/types/DuckDBBitType.ts +13 -0
  116. package/vendor/node-api/src/types/DuckDBBlobType.ts +13 -0
  117. package/vendor/node-api/src/types/DuckDBBooleanType.ts +13 -0
  118. package/vendor/node-api/src/types/DuckDBDateType.ts +29 -0
  119. package/vendor/node-api/src/types/DuckDBDecimalType.ts +46 -0
  120. package/vendor/node-api/src/types/DuckDBDoubleType.ts +21 -0
  121. package/vendor/node-api/src/types/DuckDBEnumType.ts +111 -0
  122. package/vendor/node-api/src/types/DuckDBFloatType.ts +21 -0
  123. package/vendor/node-api/src/types/DuckDBGeometryType.ts +36 -0
  124. package/vendor/node-api/src/types/DuckDBHugeIntType.ts +21 -0
  125. package/vendor/node-api/src/types/DuckDBIntegerLiteralType.ts +13 -0
  126. package/vendor/node-api/src/types/DuckDBIntegerType.ts +21 -0
  127. package/vendor/node-api/src/types/DuckDBIntervalType.ts +13 -0
  128. package/vendor/node-api/src/types/DuckDBListType.ts +35 -0
  129. package/vendor/node-api/src/types/DuckDBMapType.ts +47 -0
  130. package/vendor/node-api/src/types/DuckDBSQLNullType.ts +17 -0
  131. package/vendor/node-api/src/types/DuckDBSmallIntType.ts +21 -0
  132. package/vendor/node-api/src/types/DuckDBStringLiteralType.ts +13 -0
  133. package/vendor/node-api/src/types/DuckDBStructType.ts +104 -0
  134. package/vendor/node-api/src/types/DuckDBTimeNSType.ts +20 -0
  135. package/vendor/node-api/src/types/DuckDBTimeTZType.ts +23 -0
  136. package/vendor/node-api/src/types/DuckDBTimeType.ts +20 -0
  137. package/vendor/node-api/src/types/DuckDBTimestampMillisecondsType.ts +29 -0
  138. package/vendor/node-api/src/types/DuckDBTimestampNanosecondsType.ts +29 -0
  139. package/vendor/node-api/src/types/DuckDBTimestampSecondsType.ts +29 -0
  140. package/vendor/node-api/src/types/DuckDBTimestampTZNanosecondsType.ts +32 -0
  141. package/vendor/node-api/src/types/DuckDBTimestampTZType.ts +32 -0
  142. package/vendor/node-api/src/types/DuckDBTimestampType.ts +32 -0
  143. package/vendor/node-api/src/types/DuckDBTinyIntType.ts +21 -0
  144. package/vendor/node-api/src/types/DuckDBType.ts +86 -0
  145. package/vendor/node-api/src/types/DuckDBUBigIntType.ts +21 -0
  146. package/vendor/node-api/src/types/DuckDBUHugeIntType.ts +21 -0
  147. package/vendor/node-api/src/types/DuckDBUIntegerType.ts +21 -0
  148. package/vendor/node-api/src/types/DuckDBUSmallIntType.ts +21 -0
  149. package/vendor/node-api/src/types/DuckDBUTinyIntType.ts +21 -0
  150. package/vendor/node-api/src/types/DuckDBUUIDType.ts +20 -0
  151. package/vendor/node-api/src/types/DuckDBUnionType.ts +74 -0
  152. package/vendor/node-api/src/types/DuckDBVarCharType.ts +13 -0
  153. package/vendor/node-api/src/types/DuckDBVariantType.ts +13 -0
  154. package/vendor/node-api/src/types/index.ts +44 -0
  155. package/vendor/node-api/src/values/DuckDBArrayValue.ts +18 -0
  156. package/vendor/node-api/src/values/DuckDBBitValue.ts +117 -0
  157. package/vendor/node-api/src/values/DuckDBBlobValue.ts +26 -0
  158. package/vendor/node-api/src/values/DuckDBDateValue.ts +43 -0
  159. package/vendor/node-api/src/values/DuckDBDecimalValue.ts +44 -0
  160. package/vendor/node-api/src/values/DuckDBGeometryValue.ts +30 -0
  161. package/vendor/node-api/src/values/DuckDBIntervalValue.ts +22 -0
  162. package/vendor/node-api/src/values/DuckDBListValue.ts +18 -0
  163. package/vendor/node-api/src/values/DuckDBMapValue.ts +25 -0
  164. package/vendor/node-api/src/values/DuckDBStructValue.ts +22 -0
  165. package/vendor/node-api/src/values/DuckDBTimeNSValue.ts +23 -0
  166. package/vendor/node-api/src/values/DuckDBTimeTZValue.ts +96 -0
  167. package/vendor/node-api/src/values/DuckDBTimeValue.ts +34 -0
  168. package/vendor/node-api/src/values/DuckDBTimestampMillisecondsValue.ts +29 -0
  169. package/vendor/node-api/src/values/DuckDBTimestampNanosecondsValue.ts +28 -0
  170. package/vendor/node-api/src/values/DuckDBTimestampSecondsValue.ts +28 -0
  171. package/vendor/node-api/src/values/DuckDBTimestampTZNanosecondsValue.ts +44 -0
  172. package/vendor/node-api/src/values/DuckDBTimestampTZValue.ts +54 -0
  173. package/vendor/node-api/src/values/DuckDBTimestampValue.ts +45 -0
  174. package/vendor/node-api/src/values/DuckDBTupleValue.ts +22 -0
  175. package/vendor/node-api/src/values/DuckDBUUIDValue.ts +48 -0
  176. package/vendor/node-api/src/values/DuckDBUnionValue.ts +22 -0
  177. package/vendor/node-api/src/values/DuckDBValue.ts +53 -0
  178. package/vendor/node-api/src/values/DuckDBVariantValue.ts +34 -0
  179. package/vendor/node-api/src/values/index.ts +24 -0
  180. package/vendor/node-api/src/vectors/DuckDBArrayVector.ts +107 -0
  181. package/vendor/node-api/src/vectors/DuckDBBigIntVector.ts +75 -0
  182. package/vendor/node-api/src/vectors/DuckDBBigNumVector.ts +98 -0
  183. package/vendor/node-api/src/vectors/DuckDBBitVector.ts +102 -0
  184. package/vendor/node-api/src/vectors/DuckDBBlobVector.ts +112 -0
  185. package/vendor/node-api/src/vectors/DuckDBBooleanVector.ts +84 -0
  186. package/vendor/node-api/src/vectors/DuckDBDateVector.ts +80 -0
  187. package/vendor/node-api/src/vectors/DuckDBDecimal128Vector.ts +107 -0
  188. package/vendor/node-api/src/vectors/DuckDBDecimal16Vector.ts +104 -0
  189. package/vendor/node-api/src/vectors/DuckDBDecimal32Vector.ts +104 -0
  190. package/vendor/node-api/src/vectors/DuckDBDecimal64Vector.ts +104 -0
  191. package/vendor/node-api/src/vectors/DuckDBDoubleVector.ts +68 -0
  192. package/vendor/node-api/src/vectors/DuckDBEnum16Vector.ts +75 -0
  193. package/vendor/node-api/src/vectors/DuckDBEnum32Vector.ts +75 -0
  194. package/vendor/node-api/src/vectors/DuckDBEnum8Vector.ts +75 -0
  195. package/vendor/node-api/src/vectors/DuckDBFloatVector.ts +68 -0
  196. package/vendor/node-api/src/vectors/DuckDBGeometryVector.ts +97 -0
  197. package/vendor/node-api/src/vectors/DuckDBHugeIntVector.ts +89 -0
  198. package/vendor/node-api/src/vectors/DuckDBIntegerVector.ts +75 -0
  199. package/vendor/node-api/src/vectors/DuckDBIntervalVector.ts +100 -0
  200. package/vendor/node-api/src/vectors/DuckDBListVector.ts +221 -0
  201. package/vendor/node-api/src/vectors/DuckDBMapVector.ts +88 -0
  202. package/vendor/node-api/src/vectors/DuckDBSQLNullVector.ts +53 -0
  203. package/vendor/node-api/src/vectors/DuckDBSmallIntVector.ts +75 -0
  204. package/vendor/node-api/src/vectors/DuckDBStructVector.ts +138 -0
  205. package/vendor/node-api/src/vectors/DuckDBTimeNSVector.ts +80 -0
  206. package/vendor/node-api/src/vectors/DuckDBTimeTZVector.ts +80 -0
  207. package/vendor/node-api/src/vectors/DuckDBTimeVector.ts +80 -0
  208. package/vendor/node-api/src/vectors/DuckDBTimestampMillisecondsVector.ts +88 -0
  209. package/vendor/node-api/src/vectors/DuckDBTimestampNanosecondsVector.ts +88 -0
  210. package/vendor/node-api/src/vectors/DuckDBTimestampSecondsVector.ts +88 -0
  211. package/vendor/node-api/src/vectors/DuckDBTimestampTZNanosecondsVector.ts +88 -0
  212. package/vendor/node-api/src/vectors/DuckDBTimestampTZVector.ts +86 -0
  213. package/vendor/node-api/src/vectors/DuckDBTimestampVector.ts +83 -0
  214. package/vendor/node-api/src/vectors/DuckDBTinyIntVector.ts +75 -0
  215. package/vendor/node-api/src/vectors/DuckDBTupleVector.ts +125 -0
  216. package/vendor/node-api/src/vectors/DuckDBUBigIntVector.ts +75 -0
  217. package/vendor/node-api/src/vectors/DuckDBUHugeIntVector.ts +89 -0
  218. package/vendor/node-api/src/vectors/DuckDBUIntegerVector.ts +75 -0
  219. package/vendor/node-api/src/vectors/DuckDBUSmallIntVector.ts +75 -0
  220. package/vendor/node-api/src/vectors/DuckDBUTinyIntVector.ts +75 -0
  221. package/vendor/node-api/src/vectors/DuckDBUUIDVector.ts +89 -0
  222. package/vendor/node-api/src/vectors/DuckDBUnionVector.ts +84 -0
  223. package/vendor/node-api/src/vectors/DuckDBValidity.ts +104 -0
  224. package/vendor/node-api/src/vectors/DuckDBVarCharVector.ts +100 -0
  225. package/vendor/node-api/src/vectors/DuckDBVariantVector.ts +609 -0
  226. package/vendor/node-api/src/vectors/DuckDBVector.ts +33 -0
  227. package/vendor/node-api/src/vectors/createVector.ts +269 -0
  228. package/vendor/node-api/src/vectors/dataAccessors.ts +387 -0
  229. package/vendor/node-api/src/vectors/index.ts +50 -0
  230. package/vendor/node-api/src/vectors/vectorRegistry.ts +24 -0
  231. package/vendor/node-api/src/version.ts +5 -0
@@ -0,0 +1,355 @@
1
+ import duckdb, { Value } from "../../../src/bindings/index.ts";
2
+ import { DuckDBType } from './DuckDBType';
3
+ import { DuckDBTypeId } from './DuckDBTypeId';
4
+ import { typeForValue } from './typeForValue';
5
+ import {
6
+ DuckDBArrayValue,
7
+ DuckDBBitValue,
8
+ DuckDBBlobValue,
9
+ DuckDBDateValue,
10
+ DuckDBDecimalValue,
11
+ DuckDBGeometryValue,
12
+ DuckDBIntervalValue,
13
+ DuckDBListValue,
14
+ DuckDBMapValue,
15
+ DuckDBStructValue,
16
+ DuckDBTimeNSValue,
17
+ DuckDBTimestampMillisecondsValue,
18
+ DuckDBTimestampNanosecondsValue,
19
+ DuckDBTimestampSecondsValue,
20
+ DuckDBTimestampTZValue,
21
+ DuckDBTimestampTZNanosecondsValue,
22
+ DuckDBTimestampValue,
23
+ DuckDBTimeTZValue,
24
+ DuckDBTimeValue,
25
+ DuckDBTupleValue,
26
+ DuckDBUnionValue,
27
+ DuckDBUUIDValue,
28
+ DuckDBValue,
29
+ DuckDBVariantValue,
30
+ } from './values';
31
+
32
+ export function createValue(type: DuckDBType, input: DuckDBValue): Value {
33
+ if (input === null) {
34
+ return duckdb.create_null_value();
35
+ }
36
+ const { typeId } = type;
37
+ switch (typeId) {
38
+ case DuckDBTypeId.BOOLEAN:
39
+ if (typeof input === 'boolean') {
40
+ return duckdb.create_bool(input);
41
+ }
42
+ throw new Error(`input is not a boolean`);
43
+ case DuckDBTypeId.TINYINT:
44
+ if (typeof input === 'number') {
45
+ return duckdb.create_int8(input);
46
+ }
47
+ throw new Error(`input is not a number`);
48
+ case DuckDBTypeId.SMALLINT:
49
+ if (typeof input === 'number') {
50
+ return duckdb.create_int16(input);
51
+ }
52
+ throw new Error(`input is not a number`);
53
+ case DuckDBTypeId.INTEGER:
54
+ if (typeof input === 'number') {
55
+ return duckdb.create_int32(input);
56
+ }
57
+ throw new Error(`input is not a number`);
58
+ case DuckDBTypeId.BIGINT:
59
+ if (typeof input === 'bigint' || typeof input === 'number') {
60
+ return duckdb.create_int64(BigInt(input));
61
+ }
62
+ throw new Error(`input is not a bigint`);
63
+ case DuckDBTypeId.UTINYINT:
64
+ if (typeof input === 'number') {
65
+ return duckdb.create_uint8(input);
66
+ }
67
+ throw new Error(`input is not a number`);
68
+ case DuckDBTypeId.USMALLINT:
69
+ if (typeof input === 'number') {
70
+ return duckdb.create_uint16(input);
71
+ }
72
+ throw new Error(`input is not a number`);
73
+ case DuckDBTypeId.UINTEGER:
74
+ if (typeof input === 'number') {
75
+ return duckdb.create_uint32(input);
76
+ }
77
+ throw new Error(`input is not a number`);
78
+ case DuckDBTypeId.UBIGINT:
79
+ if (typeof input === 'bigint' || typeof input === 'number') {
80
+ return duckdb.create_uint64(BigInt(input));
81
+ }
82
+ throw new Error(`input is not a bigint`);
83
+ case DuckDBTypeId.FLOAT:
84
+ if (typeof input === 'number') {
85
+ return duckdb.create_float(input);
86
+ }
87
+ throw new Error(`input is not a number`);
88
+ case DuckDBTypeId.DOUBLE:
89
+ if (typeof input === 'number') {
90
+ return duckdb.create_double(input);
91
+ }
92
+ throw new Error(`input is not a number`);
93
+ case DuckDBTypeId.TIMESTAMP:
94
+ if (input instanceof DuckDBTimestampValue) {
95
+ return duckdb.create_timestamp(input);
96
+ }
97
+ throw new Error(`input is not a DuckDBTimestampValue`);
98
+ case DuckDBTypeId.DATE:
99
+ if (input instanceof DuckDBDateValue) {
100
+ return duckdb.create_date(input);
101
+ }
102
+ throw new Error(`input is not a DuckDBDateValue`);
103
+ case DuckDBTypeId.TIME:
104
+ if (input instanceof DuckDBTimeValue) {
105
+ return duckdb.create_time(input);
106
+ }
107
+ throw new Error(`input is not a DuckDBTimeValue`);
108
+ case DuckDBTypeId.INTERVAL:
109
+ if (input instanceof DuckDBIntervalValue) {
110
+ return duckdb.create_interval(input);
111
+ }
112
+ throw new Error(`input is not a DuckDBIntervalValue`);
113
+ case DuckDBTypeId.HUGEINT:
114
+ if (typeof input === 'bigint') {
115
+ return duckdb.create_hugeint(input);
116
+ }
117
+ throw new Error(`input is not a bigint`);
118
+ case DuckDBTypeId.UHUGEINT:
119
+ if (typeof input === 'bigint') {
120
+ return duckdb.create_uhugeint(input);
121
+ }
122
+ throw new Error(`input is not a bigint`);
123
+ case DuckDBTypeId.VARCHAR:
124
+ if (typeof input === 'string') {
125
+ return duckdb.create_varchar(input);
126
+ }
127
+ throw new Error(`input is not a string`);
128
+ case DuckDBTypeId.BLOB:
129
+ if (input instanceof DuckDBBlobValue) {
130
+ return duckdb.create_blob(input.bytes);
131
+ }
132
+ throw new Error(`input is not a DuckDBBlobValue`);
133
+ case DuckDBTypeId.DECIMAL:
134
+ if (input instanceof DuckDBDecimalValue) {
135
+ return duckdb.create_decimal(input);
136
+ }
137
+ throw new Error(`input is not a DuckDBDecimalValue`);
138
+ case DuckDBTypeId.TIMESTAMP_S:
139
+ if (input instanceof DuckDBTimestampSecondsValue) {
140
+ return duckdb.create_timestamp_s(input);
141
+ }
142
+ throw new Error(`input is not a DuckDBTimestampSecondsValue`);
143
+ case DuckDBTypeId.TIMESTAMP_MS:
144
+ if (input instanceof DuckDBTimestampMillisecondsValue) {
145
+ return duckdb.create_timestamp_ms(input);
146
+ }
147
+ throw new Error(`input is not a DuckDBTimestampMillisecondsValue`);
148
+ case DuckDBTypeId.TIMESTAMP_NS:
149
+ if (input instanceof DuckDBTimestampNanosecondsValue) {
150
+ return duckdb.create_timestamp_ns(input);
151
+ }
152
+ throw new Error(`input is not a DuckDBTimestampNanosecondsValue`);
153
+ case DuckDBTypeId.ENUM:
154
+ if (typeof input === 'string') {
155
+ return duckdb.create_enum_value(
156
+ type.toLogicalType().logical_type,
157
+ type.indexForValue(input)
158
+ );
159
+ }
160
+ throw new Error(`input is not a string`);
161
+ case DuckDBTypeId.LIST:
162
+ if (input instanceof DuckDBListValue) {
163
+ if (type.valueType.typeId === DuckDBTypeId.ANY) {
164
+ throw new Error(
165
+ 'Cannot create lists with item type of ANY. Specify a specific type.'
166
+ );
167
+ }
168
+ return duckdb.create_list_value(
169
+ type.valueType.toLogicalType().logical_type,
170
+ input.items.map((item) => createValue(type.valueType, item))
171
+ );
172
+ }
173
+ throw new Error(`input is not a DuckDBListValue`);
174
+ case DuckDBTypeId.STRUCT:
175
+ if (type.isTuple) {
176
+ if (input instanceof DuckDBTupleValue) {
177
+ if (
178
+ type.entryTypes.find(
179
+ (entryType) => entryType.typeId === DuckDBTypeId.ANY
180
+ )
181
+ ) {
182
+ throw new Error(
183
+ 'Cannot create tuples with an entry type of ANY. Specify a specific type.'
184
+ );
185
+ }
186
+ if (input.items.length !== type.entryCount) {
187
+ throw new Error(
188
+ `Expected ${type.entryCount} items for ${type}, got ${input.items.length}`
189
+ );
190
+ }
191
+ return duckdb.create_struct_value(
192
+ type.toLogicalType().logical_type,
193
+ input.items.map((item, i) => createValue(type.entryTypes[i], item))
194
+ );
195
+ }
196
+ throw new Error(`input is not a DuckDBTupleValue`);
197
+ }
198
+ if (input instanceof DuckDBStructValue) {
199
+ if (
200
+ type.entryTypes.find(
201
+ (entryType) => entryType.typeId === DuckDBTypeId.ANY
202
+ )
203
+ ) {
204
+ throw new Error(
205
+ 'Cannot create structs with an entry type of ANY. Specify a specific type.'
206
+ );
207
+ }
208
+ // Pair entries by name rather than positionally so that
209
+ // `structValue({b: 'x', a: 1})` against `STRUCT({a: INTEGER, b:
210
+ // VARCHAR})` doesn't silently mispair when the value's insertion
211
+ // order differs from the type's declared field order.
212
+ return duckdb.create_struct_value(
213
+ type.toLogicalType().logical_type,
214
+ type.entryNames.map((name, i) => {
215
+ if (!(name in input.entries)) {
216
+ throw new Error(
217
+ `STRUCT entry '${name}' is missing from input`
218
+ );
219
+ }
220
+ return createValue(type.entryTypes[i], input.entries[name]);
221
+ })
222
+ );
223
+ }
224
+ throw new Error(`input is not a DuckDBStructValue`);
225
+ case DuckDBTypeId.MAP:
226
+ if (input instanceof DuckDBMapValue) {
227
+ if (type.keyType.typeId === DuckDBTypeId.ANY) {
228
+ throw new Error(
229
+ 'Cannot create maps with key type of ANY. Specify a specific type.'
230
+ );
231
+ }
232
+ if (type.valueType.typeId === DuckDBTypeId.ANY) {
233
+ throw new Error(
234
+ 'Cannot create maps with value type of ANY. Specify a specific type.'
235
+ );
236
+ }
237
+ return duckdb.create_map_value(
238
+ type.toLogicalType().logical_type,
239
+ input.entries.map((entry) => createValue(type.keyType, entry.key)),
240
+ input.entries.map((entry) => createValue(type.valueType, entry.value))
241
+ );
242
+ }
243
+ throw new Error(`input is not a DuckDBMapValue`);
244
+ case DuckDBTypeId.ARRAY:
245
+ if (input instanceof DuckDBArrayValue) {
246
+ if (type.valueType.typeId === DuckDBTypeId.ANY) {
247
+ throw new Error(
248
+ 'Cannot create arrays with item type of ANY. Specify a specific type.'
249
+ );
250
+ }
251
+ return duckdb.create_array_value(
252
+ type.valueType.toLogicalType().logical_type,
253
+ input.items.map((item) => createValue(type.valueType, item))
254
+ );
255
+ }
256
+ throw new Error(`input is not a DuckDBArrayValue`);
257
+ case DuckDBTypeId.UUID:
258
+ if (input instanceof DuckDBUUIDValue) {
259
+ return duckdb.create_uuid(input.toUint128());
260
+ }
261
+ throw new Error(`input is not a bigint`);
262
+ case DuckDBTypeId.UNION:
263
+ if (input instanceof DuckDBUnionValue) {
264
+ const tagIndex = type.memberIndexForTag(input.tag);
265
+ const memberType = type.memberTypes[tagIndex];
266
+ if (memberType.typeId === DuckDBTypeId.ANY) {
267
+ throw new Error('Cannot create union values with type of ANY.');
268
+ }
269
+ return duckdb.create_union_value(
270
+ type.toLogicalType().logical_type,
271
+ tagIndex,
272
+ createValue(memberType, input.value)
273
+ );
274
+ }
275
+ throw new Error(`input is not a DuckDBUnionValue`);
276
+ case DuckDBTypeId.BIT:
277
+ if (input instanceof DuckDBBitValue) {
278
+ return duckdb.create_bit(input.data);
279
+ }
280
+ throw new Error(`input is not a DuckDBBitValue`);
281
+ case DuckDBTypeId.TIME_TZ:
282
+ if (input instanceof DuckDBTimeTZValue) {
283
+ return duckdb.create_time_tz_value(input);
284
+ }
285
+ throw new Error(`input is not a DuckDBTimeTZValue`);
286
+ case DuckDBTypeId.TIMESTAMP_TZ:
287
+ if (input instanceof DuckDBTimestampTZValue) {
288
+ return duckdb.create_timestamp_tz(input);
289
+ }
290
+ throw new Error(`input is not a DuckDBTimestampTZValue`);
291
+ case DuckDBTypeId.TIMESTAMP_TZ_NS:
292
+ if (input instanceof DuckDBTimestampTZNanosecondsValue) {
293
+ return duckdb.create_timestamp_tz_ns(input);
294
+ }
295
+ throw new Error(`input is not a DuckDBTimestampTZNanosecondsValue`);
296
+ case DuckDBTypeId.ANY:
297
+ throw new Error(
298
+ `Cannot create values of type ANY. Specify a specific type.`
299
+ );
300
+ case DuckDBTypeId.BIGNUM:
301
+ if (typeof input === 'bigint') {
302
+ return duckdb.create_bignum(input);
303
+ }
304
+ throw new Error(`input is not a bigint`);
305
+ case DuckDBTypeId.SQLNULL:
306
+ return duckdb.create_null_value();
307
+ case DuckDBTypeId.STRING_LITERAL:
308
+ throw new Error(`Cannot create values of type STRING_LITERAL.`);
309
+ case DuckDBTypeId.INTEGER_LITERAL:
310
+ throw new Error(`Cannot create values of type INTEGER_LITERAL.`);
311
+ case DuckDBTypeId.TIME_NS:
312
+ if (input instanceof DuckDBTimeNSValue) {
313
+ return duckdb.create_time_ns(input);
314
+ }
315
+ throw new Error(`input is not a DuckDBTimeNSValue`);
316
+ case DuckDBTypeId.GEOMETRY:
317
+ if (input instanceof DuckDBGeometryValue) {
318
+ throw new Error(`Creating values of type GEOMETRY is not yet supported.`);
319
+ // TODO: create_geometry doesn't exist; create_blob results in Failed to cast value: Unimplemented type for cast (BLOB -> GEOMETRY)
320
+ // return duckdb.create_blob(input.bytes);
321
+ }
322
+ throw new Error(`input is not a DuckDBGeometryValue`);
323
+ case DuckDBTypeId.VARIANT: {
324
+ // VARIANT has no direct create primitive in the C API; DuckDB
325
+ // implicitly casts from any compatible type when the target column
326
+ // or parameter is VARIANT. Recurse on the input's natural type so
327
+ // we hand DuckDB a Value it can cast.
328
+ //
329
+ // If the input is a DuckDBVariantValue, prefer its embedded `.type`
330
+ // (set by the decoder from the on-disk variant tag) so heterogeneous
331
+ // content round-trips faithfully. Fall back to `typeForValue` when
332
+ // no type hint is attached. The recursion is wrapped so a
333
+ // mismatched wrapper (e.g. `variantValue('hello', INTEGER)`)
334
+ // surfaces a VARIANT-flavored error rather than a confusing
335
+ // `input is not a number` from a sibling case.
336
+ const inner =
337
+ input instanceof DuckDBVariantValue ? input.value : input;
338
+ const innerType =
339
+ input instanceof DuckDBVariantValue && input.type
340
+ ? input.type
341
+ : typeForValue(inner);
342
+ try {
343
+ return createValue(innerType, inner);
344
+ } catch (err) {
345
+ throw new Error(
346
+ `Failed to create VARIANT value (inner type ${innerType}): ${
347
+ (err as Error).message
348
+ }`
349
+ );
350
+ }
351
+ }
352
+ default:
353
+ throw new Error(`unrecognized type id ${typeId}`);
354
+ }
355
+ }
@@ -0,0 +1,51 @@
1
+ export {
2
+ double_to_hugeint,
3
+ double_to_uhugeint,
4
+ hugeint_to_double,
5
+ uhugeint_to_double
6
+ } from "../../../src/bindings/index.ts";
7
+ export * from './configurationOptionDescriptions';
8
+ export * from './createDuckDBValueConverter';
9
+ export * from './DuckDBAppender';
10
+ export * from './DuckDBClientContext';
11
+ export * from './DuckDBConnection';
12
+ export * from './DuckDBDataChunk';
13
+ export * from './DuckDBDataChunkWriter';
14
+ export * from './DuckDBExtractedStatements';
15
+ export * from './DuckDBInstance';
16
+ export * from './DuckDBInstanceCache';
17
+ export * from './DuckDBLogicalType';
18
+ export * from './DuckDBMaterializedResult';
19
+ export * from './DuckDBPendingResult';
20
+ export * from './DuckDBPreparedStatement';
21
+ export * from './DuckDBPreparedStatementCollection';
22
+ export * from './DuckDBResult';
23
+ export * from './DuckDBResultReader';
24
+ export * from './DuckDBScalarFunction';
25
+ export * from './DuckDBScalarFunctionBindInfo';
26
+ export * from './DuckDBScalarFunctionInfo';
27
+ export * from './DuckDBScalarFunctionInitInfo';
28
+ export * from './DuckDBTableFunction';
29
+ export * from './DuckDBTableFunctionBindInfo';
30
+ export * from './DuckDBTableFunctionInfo';
31
+ export * from './DuckDBTableFunctionInitInfo';
32
+ export * from './DuckDBType';
33
+ export * from './DuckDBTypeId';
34
+ export * from './DuckDBValueConverter';
35
+ export * from './DuckDBValueConverters';
36
+ export * from './DuckDBVector';
37
+ export * from './ToDuckDBValueConverter';
38
+ export * from './ToDuckDBValueConverters';
39
+ export * from './enums';
40
+ export * from './JS';
41
+ export * from './JSDuckDBValueConverter';
42
+ export * from './JSInputTypeForTypeId';
43
+ export * from './JSToDuckDBValueConverter';
44
+ export * from './JSTypeForTypeId';
45
+ export * from './Json';
46
+ export * from './JsonDuckDBValueConverter';
47
+ export * from './JsonTypeForTypeId';
48
+ export * from './readValue';
49
+ export * from './sql';
50
+ export * from './values';
51
+ export * from './version';
@@ -0,0 +1,7 @@
1
+ import duckdb from "../../../src/bindings/index.ts";
2
+
3
+ export type ResultReturnType = duckdb.ResultType;
4
+ export const ResultReturnType = duckdb.ResultType;
5
+
6
+ export type StatementType = duckdb.StatementType;
7
+ export const StatementType = duckdb.StatementType;
@@ -0,0 +1,13 @@
1
+ import { DuckDBDataChunk } from './DuckDBDataChunk';
2
+ import { DuckDBValue } from './values';
3
+
4
+ export function getColumnsFromChunks(
5
+ chunks: readonly DuckDBDataChunk[],
6
+ columnCount: number
7
+ ): DuckDBValue[][] {
8
+ const columns: DuckDBValue[][] = Array.from({ length: columnCount }, () => []);
9
+ for (const chunk of chunks) {
10
+ chunk.appendToColumns(columns);
11
+ }
12
+ return columns;
13
+ }
@@ -0,0 +1,16 @@
1
+ import { DuckDBDataChunk } from './DuckDBDataChunk';
2
+ import { DuckDBValue } from './values';
3
+
4
+ export function getColumnsObjectFromChunks(
5
+ chunks: readonly DuckDBDataChunk[],
6
+ columnNames: readonly string[]
7
+ ): Record<string, DuckDBValue[]> {
8
+ const columnsObject: Record<string, DuckDBValue[]> = {};
9
+ for (const columnName of columnNames) {
10
+ columnsObject[columnName] = [];
11
+ }
12
+ for (const chunk of chunks) {
13
+ chunk.appendToColumnsObject(columnNames, columnsObject);
14
+ }
15
+ return columnsObject;
16
+ }
@@ -0,0 +1,13 @@
1
+ import { DuckDBDataChunk } from './DuckDBDataChunk';
2
+ import { DuckDBValue } from './values';
3
+
4
+ export function getRowObjectsFromChunks(
5
+ chunks: readonly DuckDBDataChunk[],
6
+ columnNames: readonly string[]
7
+ ): Record<string, DuckDBValue>[] {
8
+ const rowObjects: Record<string, DuckDBValue>[] = [];
9
+ for (const chunk of chunks) {
10
+ chunk.appendToRowObjects(columnNames, rowObjects);
11
+ }
12
+ return rowObjects;
13
+ }
@@ -0,0 +1,12 @@
1
+ import { DuckDBDataChunk } from './DuckDBDataChunk';
2
+ import { DuckDBValue } from './values';
3
+
4
+ export function getRowsFromChunks(
5
+ chunks: readonly DuckDBDataChunk[]
6
+ ): DuckDBValue[][] {
7
+ const rows: DuckDBValue[][] = [];
8
+ for (const chunk of chunks) {
9
+ chunk.appendToRows(rows);
10
+ }
11
+ return rows;
12
+ }
@@ -0,0 +1,3 @@
1
+ import * as duckdb from './duckdb';
2
+ export default duckdb;
3
+ export * from './duckdb';
@@ -0,0 +1,31 @@
1
+ import duckdb, { Value } from "../../../src/bindings/index.ts";
2
+ import { DuckDBVector } from './DuckDBVector';
3
+ import { DuckDBValue } from './values';
4
+
5
+ /**
6
+ * Converts a `duckdb.Value` into a `DuckDBValue`.
7
+ *
8
+ * Results normally arrive as vectors rather than values, so this is for the
9
+ * places that hand back a value instead: table function parameters, and
10
+ * `duckdb_get_table_names`.
11
+ *
12
+ * It works by referencing the value into a vector of its own and reading the one
13
+ * element back, which reuses the vector reading path rather than duplicating it.
14
+ * That matters for more than tidiness: the value accessors cannot reach inside an
15
+ * ARRAY or a UNION at all, because `duckdb_get_list_child` and
16
+ * `duckdb_get_struct_child` guard on the exact logical type id and return null
17
+ * for both. Going through a vector covers every type, and leaves one
18
+ * implementation of how each type is represented rather than two that can drift.
19
+ *
20
+ * The cost is roughly an extra microsecond per scalar value, which is fine here
21
+ * and would not be in a per-row path. Per-row data already arrives as vectors and
22
+ * never comes through here.
23
+ */
24
+ export function readValue(value: Value): DuckDBValue {
25
+ // Capacity of one: the vector exists only to hold this single value. It is
26
+ // destroyed when collected, and getItem materializes what it returns, so
27
+ // nothing handed back keeps a reference to the vector's memory.
28
+ const vector = duckdb.create_vector(duckdb.get_value_type(value), 1);
29
+ duckdb.vector_reference_value(vector, value);
30
+ return DuckDBVector.create(vector, 1).getItem(0);
31
+ }
@@ -0,0 +1,5 @@
1
+ export async function sleep(ms: number) {
2
+ return new Promise((resolve) => {
3
+ setTimeout(resolve, ms);
4
+ });
5
+ }
@@ -0,0 +1,7 @@
1
+ export function quotedString(input: string): string {
2
+ return `'${input.replaceAll(`'`, `''`)}'`;
3
+ }
4
+
5
+ export function quotedIdentifier(input: string): string {
6
+ return `"${input.replaceAll(`"`, `""`)}"`;
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.library.json",
3
+ "compilerOptions": {
4
+ "outDir": "../pkgs/@duckdb/node-api/lib",
5
+ "types": ["node"]
6
+ }
7
+ }
@@ -0,0 +1,144 @@
1
+ import {
2
+ ANY,
3
+ ARRAY,
4
+ BIGINT,
5
+ BIT,
6
+ BLOB,
7
+ BOOLEAN,
8
+ DATE,
9
+ DECIMAL,
10
+ DOUBLE,
11
+ DuckDBType,
12
+ HUGEINT,
13
+ INTEGER,
14
+ INTERVAL,
15
+ LIST,
16
+ MAP,
17
+ SQLNULL,
18
+ STRUCT,
19
+ TIME,
20
+ TIME_NS,
21
+ TIMESTAMP,
22
+ TIMESTAMP_MS,
23
+ TIMESTAMP_NS,
24
+ TIMESTAMP_S,
25
+ TIMESTAMPTZ,
26
+ TIMESTAMPTZ_NS,
27
+ TIMETZ,
28
+ TUPLE,
29
+ UNION,
30
+ UUID,
31
+ VARCHAR,
32
+ VARIANT,
33
+ } from './DuckDBType';
34
+ import {
35
+ DuckDBArrayValue,
36
+ DuckDBBitValue,
37
+ DuckDBBlobValue,
38
+ DuckDBDateValue,
39
+ DuckDBDecimalValue,
40
+ DuckDBIntervalValue,
41
+ DuckDBListValue,
42
+ DuckDBMapValue,
43
+ DuckDBStructValue,
44
+ DuckDBTimeNSValue,
45
+ DuckDBTimestampMillisecondsValue,
46
+ DuckDBTimestampNanosecondsValue,
47
+ DuckDBTimestampSecondsValue,
48
+ DuckDBTimestampTZValue,
49
+ DuckDBTimestampTZNanosecondsValue,
50
+ DuckDBTimestampValue,
51
+ DuckDBTimeTZValue,
52
+ DuckDBTimeValue,
53
+ DuckDBTupleValue,
54
+ DuckDBUnionValue,
55
+ DuckDBUUIDValue,
56
+ DuckDBValue,
57
+ DuckDBVariantValue,
58
+ } from './values';
59
+
60
+ export function typeForValue(value: DuckDBValue): DuckDBType {
61
+ if (value === null) {
62
+ return SQLNULL;
63
+ } else {
64
+ switch (typeof value) {
65
+ case 'boolean':
66
+ return BOOLEAN;
67
+ case 'number':
68
+ if (Number.isInteger(value)) {
69
+ if (value >= -2_147_483_648 && value <= 2_147_483_647) {
70
+ return INTEGER;
71
+ }
72
+ return BIGINT;
73
+ } else {
74
+ return DOUBLE;
75
+ }
76
+ case 'bigint':
77
+ return HUGEINT;
78
+ case 'string':
79
+ return VARCHAR;
80
+ case 'object':
81
+ if (value instanceof DuckDBArrayValue) {
82
+ return ARRAY(typeForValue(value.items[0]), value.items.length);
83
+ } else if (value instanceof DuckDBBitValue) {
84
+ return BIT;
85
+ } else if (value instanceof DuckDBBlobValue) {
86
+ return BLOB;
87
+ } else if (value instanceof DuckDBDateValue) {
88
+ return DATE;
89
+ } else if (value instanceof DuckDBDecimalValue) {
90
+ return DECIMAL(value.width, value.scale);
91
+ } else if (value instanceof DuckDBIntervalValue) {
92
+ return INTERVAL;
93
+ } else if (value instanceof DuckDBListValue) {
94
+ return LIST(typeForValue(value.items[0]));
95
+ } else if (value instanceof DuckDBMapValue) {
96
+ if (value.entries.length === 0) {
97
+ // An empty map carries no entries to infer key/value types from.
98
+ // Mirror the empty-list path (LIST(ANY)) so createValue raises the
99
+ // same "Cannot create maps with key type of ANY" error, instead of
100
+ // a cryptic "Cannot read properties of undefined (reading 'key')".
101
+ return MAP(ANY, ANY);
102
+ }
103
+ return MAP(
104
+ typeForValue(value.entries[0].key),
105
+ typeForValue(value.entries[0].value)
106
+ );
107
+ } else if (value instanceof DuckDBStructValue) {
108
+ const entryTypes: Record<string, DuckDBType> = {};
109
+ for (const key in value.entries) {
110
+ entryTypes[key] = typeForValue(value.entries[key]);
111
+ }
112
+ return STRUCT(entryTypes);
113
+ } else if (value instanceof DuckDBTimestampMillisecondsValue) {
114
+ return TIMESTAMP_MS;
115
+ } else if (value instanceof DuckDBTimestampNanosecondsValue) {
116
+ return TIMESTAMP_NS;
117
+ } else if (value instanceof DuckDBTimestampSecondsValue) {
118
+ return TIMESTAMP_S;
119
+ } else if (value instanceof DuckDBTimestampTZValue) {
120
+ return TIMESTAMPTZ;
121
+ } else if (value instanceof DuckDBTimestampTZNanosecondsValue) {
122
+ return TIMESTAMPTZ_NS;
123
+ } else if (value instanceof DuckDBTimestampValue) {
124
+ return TIMESTAMP;
125
+ } else if (value instanceof DuckDBTimeTZValue) {
126
+ return TIMETZ;
127
+ } else if (value instanceof DuckDBTimeValue) {
128
+ return TIME;
129
+ } else if (value instanceof DuckDBTimeNSValue) {
130
+ return TIME_NS;
131
+ } else if (value instanceof DuckDBTupleValue) {
132
+ return TUPLE(value.items.map(typeForValue));
133
+ } else if (value instanceof DuckDBUnionValue) {
134
+ return UNION({ [value.tag]: typeForValue(value.value) });
135
+ } else if (value instanceof DuckDBUUIDValue) {
136
+ return UUID;
137
+ } else if (value instanceof DuckDBVariantValue) {
138
+ return VARIANT;
139
+ }
140
+ break;
141
+ }
142
+ }
143
+ return ANY;
144
+ }