@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,88 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBTimestampTZNanosecondsType,
4
+ } from '../DuckDBType';
5
+ import {
6
+ DuckDBTimestampTZNanosecondsValue,
7
+ } from '../values';
8
+ import { DuckDBVector } from './DuckDBVector';
9
+ import { DuckDBValidity } from './DuckDBValidity';
10
+ import {
11
+ vectorData,
12
+ } from './dataAccessors';
13
+
14
+ export class DuckDBTimestampTZNanosecondsVector extends DuckDBVector<DuckDBTimestampTZNanosecondsValue> {
15
+ private readonly items: BigInt64Array;
16
+ private readonly validity: DuckDBValidity;
17
+ private readonly vector: duckdb.Vector;
18
+ constructor(
19
+ items: BigInt64Array,
20
+ validity: DuckDBValidity,
21
+ vector: duckdb.Vector
22
+ ) {
23
+ super();
24
+ this.items = items;
25
+ this.validity = validity;
26
+ this.vector = vector;
27
+ }
28
+ static fromRawVector(
29
+ vector: duckdb.Vector,
30
+ itemCount: number
31
+ ): DuckDBTimestampTZNanosecondsVector {
32
+ const data = vectorData(
33
+ vector,
34
+ itemCount * BigInt64Array.BYTES_PER_ELEMENT
35
+ );
36
+ const items = new BigInt64Array(data.buffer, data.byteOffset, itemCount);
37
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
38
+ return new DuckDBTimestampTZNanosecondsVector(items, validity, vector);
39
+ }
40
+ public override get type(): DuckDBTimestampTZNanosecondsType {
41
+ return DuckDBTimestampTZNanosecondsType.instance;
42
+ }
43
+ public override get itemCount(): number {
44
+ return this.items.length;
45
+ }
46
+ public override getItem(
47
+ itemIndex: number
48
+ ): DuckDBTimestampTZNanosecondsValue | null {
49
+ return this.validity.itemValid(itemIndex)
50
+ ? new DuckDBTimestampTZNanosecondsValue(this.items[itemIndex])
51
+ : null;
52
+ }
53
+ public override setItem(
54
+ itemIndex: number,
55
+ value: DuckDBTimestampTZNanosecondsValue | null
56
+ ) {
57
+ if (value != null) {
58
+ // Checked inline for bulk-write throughput; see dataAccessors.ts.
59
+ if (BigInt.asIntN(64, value.nanos) !== value.nanos) {
60
+ throw new Error(`bigint out of int64 range`);
61
+ }
62
+ this.items[itemIndex] = value.nanos;
63
+ this.validity.setItemValid(itemIndex, true);
64
+ } else {
65
+ this.validity.setItemValid(itemIndex, false);
66
+ }
67
+ }
68
+ public override flush() {
69
+ duckdb.copy_data_to_vector(
70
+ this.vector,
71
+ 0,
72
+ this.items.buffer as ArrayBuffer,
73
+ this.items.byteOffset,
74
+ this.items.byteLength
75
+ );
76
+ this.validity.flush(this.vector);
77
+ }
78
+ public override slice(
79
+ offset: number,
80
+ length: number
81
+ ): DuckDBTimestampTZNanosecondsVector {
82
+ return new DuckDBTimestampTZNanosecondsVector(
83
+ this.items.slice(offset, offset + length),
84
+ this.validity.slice(offset, length),
85
+ this.vector
86
+ );
87
+ }
88
+ }
@@ -0,0 +1,86 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBTimestampTZType,
4
+ } from '../DuckDBType';
5
+ import {
6
+ DuckDBTimestampTZValue,
7
+ } from '../values';
8
+ import { DuckDBVector } from './DuckDBVector';
9
+ import { DuckDBValidity } from './DuckDBValidity';
10
+ import {
11
+ vectorData,
12
+ } from './dataAccessors';
13
+
14
+ export class DuckDBTimestampTZVector extends DuckDBVector<DuckDBTimestampTZValue> {
15
+ private readonly items: BigInt64Array;
16
+ private readonly validity: DuckDBValidity;
17
+ private readonly vector: duckdb.Vector;
18
+ constructor(
19
+ items: BigInt64Array,
20
+ validity: DuckDBValidity,
21
+ vector: duckdb.Vector
22
+ ) {
23
+ super();
24
+ this.items = items;
25
+ this.validity = validity;
26
+ this.vector = vector;
27
+ }
28
+ static fromRawVector(
29
+ vector: duckdb.Vector,
30
+ itemCount: number
31
+ ): DuckDBTimestampTZVector {
32
+ const data = vectorData(
33
+ vector,
34
+ itemCount * BigInt64Array.BYTES_PER_ELEMENT
35
+ );
36
+ const items = new BigInt64Array(data.buffer, data.byteOffset, itemCount);
37
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
38
+ return new DuckDBTimestampTZVector(items, validity, vector);
39
+ }
40
+ public override get type(): DuckDBTimestampTZType {
41
+ return DuckDBTimestampTZType.instance;
42
+ }
43
+ public override get itemCount(): number {
44
+ return this.items.length;
45
+ }
46
+ public override getItem(itemIndex: number): DuckDBTimestampTZValue | null {
47
+ return this.validity.itemValid(itemIndex)
48
+ ? new DuckDBTimestampTZValue(this.items[itemIndex])
49
+ : null;
50
+ }
51
+ public override setItem(
52
+ itemIndex: number,
53
+ value: DuckDBTimestampTZValue | null
54
+ ) {
55
+ if (value != null) {
56
+ // Checked inline for bulk-write throughput; see dataAccessors.ts.
57
+ if (BigInt.asIntN(64, value.micros) !== value.micros) {
58
+ throw new Error(`bigint out of int64 range`);
59
+ }
60
+ this.items[itemIndex] = value.micros;
61
+ this.validity.setItemValid(itemIndex, true);
62
+ } else {
63
+ this.validity.setItemValid(itemIndex, false);
64
+ }
65
+ }
66
+ public override flush() {
67
+ duckdb.copy_data_to_vector(
68
+ this.vector,
69
+ 0,
70
+ this.items.buffer as ArrayBuffer,
71
+ this.items.byteOffset,
72
+ this.items.byteLength
73
+ );
74
+ this.validity.flush(this.vector);
75
+ }
76
+ public override slice(
77
+ offset: number,
78
+ length: number
79
+ ): DuckDBTimestampTZVector {
80
+ return new DuckDBTimestampTZVector(
81
+ this.items.slice(offset, offset + length),
82
+ this.validity.slice(offset, length),
83
+ this.vector
84
+ );
85
+ }
86
+ }
@@ -0,0 +1,83 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBTimestampType,
4
+ } from '../DuckDBType';
5
+ import {
6
+ DuckDBTimestampValue,
7
+ } from '../values';
8
+ import { DuckDBVector } from './DuckDBVector';
9
+ import { DuckDBValidity } from './DuckDBValidity';
10
+ import {
11
+ vectorData,
12
+ } from './dataAccessors';
13
+
14
+ export class DuckDBTimestampVector extends DuckDBVector<DuckDBTimestampValue> {
15
+ private readonly items: BigInt64Array;
16
+ private readonly validity: DuckDBValidity;
17
+ private readonly vector: duckdb.Vector;
18
+ constructor(
19
+ items: BigInt64Array,
20
+ validity: DuckDBValidity,
21
+ vector: duckdb.Vector
22
+ ) {
23
+ super();
24
+ this.items = items;
25
+ this.validity = validity;
26
+ this.vector = vector;
27
+ }
28
+ static fromRawVector(
29
+ vector: duckdb.Vector,
30
+ itemCount: number
31
+ ): DuckDBTimestampVector {
32
+ const data = vectorData(
33
+ vector,
34
+ itemCount * BigInt64Array.BYTES_PER_ELEMENT
35
+ );
36
+ const items = new BigInt64Array(data.buffer, data.byteOffset, itemCount);
37
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
38
+ return new DuckDBTimestampVector(items, validity, vector);
39
+ }
40
+ public override get type(): DuckDBTimestampType {
41
+ return DuckDBTimestampType.instance;
42
+ }
43
+ public override get itemCount(): number {
44
+ return this.items.length;
45
+ }
46
+ public override getItem(itemIndex: number): DuckDBTimestampValue | null {
47
+ return this.validity.itemValid(itemIndex)
48
+ ? new DuckDBTimestampValue(this.items[itemIndex])
49
+ : null;
50
+ }
51
+ public override setItem(
52
+ itemIndex: number,
53
+ value: DuckDBTimestampValue | null
54
+ ) {
55
+ if (value != null) {
56
+ // Checked inline for bulk-write throughput; see dataAccessors.ts.
57
+ if (BigInt.asIntN(64, value.micros) !== value.micros) {
58
+ throw new Error(`bigint out of int64 range`);
59
+ }
60
+ this.items[itemIndex] = value.micros;
61
+ this.validity.setItemValid(itemIndex, true);
62
+ } else {
63
+ this.validity.setItemValid(itemIndex, false);
64
+ }
65
+ }
66
+ public override flush() {
67
+ duckdb.copy_data_to_vector(
68
+ this.vector,
69
+ 0,
70
+ this.items.buffer as ArrayBuffer,
71
+ this.items.byteOffset,
72
+ this.items.byteLength
73
+ );
74
+ this.validity.flush(this.vector);
75
+ }
76
+ public override slice(offset: number, length: number): DuckDBTimestampVector {
77
+ return new DuckDBTimestampVector(
78
+ this.items.slice(offset, offset + length),
79
+ this.validity.slice(offset, length),
80
+ this.vector
81
+ );
82
+ }
83
+ }
@@ -0,0 +1,75 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBTinyIntType,
4
+ } from '../DuckDBType';
5
+ import { DuckDBVector } from './DuckDBVector';
6
+ import { DuckDBValidity } from './DuckDBValidity';
7
+ import {
8
+ vectorData,
9
+ } from './dataAccessors';
10
+
11
+ export class DuckDBTinyIntVector extends DuckDBVector<number> {
12
+ private readonly items: Int8Array;
13
+ private readonly validity: DuckDBValidity;
14
+ private readonly vector: duckdb.Vector;
15
+ constructor(
16
+ items: Int8Array,
17
+ validity: DuckDBValidity,
18
+ vector: duckdb.Vector
19
+ ) {
20
+ super();
21
+ this.items = items;
22
+ this.validity = validity;
23
+ this.vector = vector;
24
+ }
25
+ static fromRawVector(
26
+ vector: duckdb.Vector,
27
+ itemCount: number
28
+ ): DuckDBTinyIntVector {
29
+ const data = vectorData(vector, itemCount * Int8Array.BYTES_PER_ELEMENT);
30
+ const items = new Int8Array(data.buffer, data.byteOffset, itemCount);
31
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
32
+ return new DuckDBTinyIntVector(items, validity, vector);
33
+ }
34
+ public override get type(): DuckDBTinyIntType {
35
+ return DuckDBTinyIntType.instance;
36
+ }
37
+ public override get itemCount(): number {
38
+ return this.items.length;
39
+ }
40
+ public override getItem(itemIndex: number): number | null {
41
+ return this.validity.itemValid(itemIndex) ? this.items[itemIndex] : null;
42
+ }
43
+ public override setItem(itemIndex: number, value: number | null) {
44
+ if (value != null) {
45
+ // Checked inline for bulk-write throughput; see dataAccessors.ts.
46
+ if (!Number.isInteger(value)) {
47
+ throw new Error(`number is not an integer`);
48
+ }
49
+ if (value < -128 || value > 127) {
50
+ throw new Error(`number out of int8 range`);
51
+ }
52
+ this.items[itemIndex] = value;
53
+ this.validity.setItemValid(itemIndex, true);
54
+ } else {
55
+ this.validity.setItemValid(itemIndex, false);
56
+ }
57
+ }
58
+ public override flush() {
59
+ duckdb.copy_data_to_vector(
60
+ this.vector,
61
+ 0,
62
+ this.items.buffer as ArrayBuffer,
63
+ this.items.byteOffset,
64
+ this.items.byteLength
65
+ );
66
+ this.validity.flush(this.vector);
67
+ }
68
+ public override slice(offset: number, length: number): DuckDBTinyIntVector {
69
+ return new DuckDBTinyIntVector(
70
+ this.items.slice(offset, offset + length),
71
+ this.validity.slice(offset, length),
72
+ this.vector
73
+ );
74
+ }
75
+ }
@@ -0,0 +1,125 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBStructType,
4
+ } from '../DuckDBType';
5
+ import {
6
+ DuckDBTupleValue,
7
+ DuckDBValue,
8
+ } from '../values';
9
+ import { DuckDBVector } from './DuckDBVector';
10
+ import { DuckDBValidity } from './DuckDBValidity';
11
+
12
+ /**
13
+ * A vector of a tuple type: a STRUCT whose entry names are all empty (see
14
+ * `DuckDBStructType.isTuple`). Items are `DuckDBTupleValue`s.
15
+ */
16
+ export class DuckDBTupleVector extends DuckDBVector<DuckDBTupleValue> {
17
+ private readonly tupleType: DuckDBStructType;
18
+ private readonly _itemCount: number;
19
+ private readonly entryVectors: readonly DuckDBVector[];
20
+ private readonly validity: DuckDBValidity;
21
+ private readonly vector: duckdb.Vector;
22
+ constructor(
23
+ tupleType: DuckDBStructType,
24
+ itemCount: number,
25
+ entryVectors: readonly DuckDBVector[],
26
+ validity: DuckDBValidity,
27
+ vector: duckdb.Vector
28
+ ) {
29
+ super();
30
+ this.tupleType = tupleType;
31
+ this._itemCount = itemCount;
32
+ this.entryVectors = entryVectors;
33
+ this.validity = validity;
34
+ this.vector = vector;
35
+ }
36
+ static fromRawVector(
37
+ tupleType: DuckDBStructType,
38
+ vector: duckdb.Vector,
39
+ itemCount: number
40
+ ): DuckDBTupleVector {
41
+ const entryCount = tupleType.entryCount;
42
+ const entryVectors: DuckDBVector[] = [];
43
+ for (let i = 0; i < entryCount; i++) {
44
+ const child_vector = duckdb.struct_vector_get_child(vector, i);
45
+ entryVectors.push(
46
+ DuckDBVector.create(child_vector, itemCount, tupleType.entryTypes[i])
47
+ );
48
+ }
49
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
50
+ return new DuckDBTupleVector(
51
+ tupleType,
52
+ itemCount,
53
+ entryVectors,
54
+ validity,
55
+ vector
56
+ );
57
+ }
58
+ public override get type(): DuckDBStructType {
59
+ return this.tupleType;
60
+ }
61
+ public override get itemCount(): number {
62
+ return this._itemCount;
63
+ }
64
+ public override getItem(itemIndex: number): DuckDBTupleValue | null {
65
+ if (!this.validity.itemValid(itemIndex)) {
66
+ return null;
67
+ }
68
+ return new DuckDBTupleValue(
69
+ this.entryVectors.map((entryVector) => entryVector.getItem(itemIndex))
70
+ );
71
+ }
72
+ public getItemValue(
73
+ itemIndex: number,
74
+ entryIndex: number
75
+ ): DuckDBValue | null {
76
+ if (!this.validity.itemValid(itemIndex)) {
77
+ return null;
78
+ }
79
+ return this.entryVectors[entryIndex].getItem(itemIndex);
80
+ }
81
+ public override setItem(itemIndex: number, value: DuckDBTupleValue | null) {
82
+ if (value != null) {
83
+ if (!(value instanceof DuckDBTupleValue)) {
84
+ throw new Error(`Expected DuckDBTupleValue for ${this.tupleType}`);
85
+ }
86
+ const entryCount = this.tupleType.entryCount;
87
+ if (value.items.length !== entryCount) {
88
+ throw new Error(
89
+ `Expected ${entryCount} items for ${this.tupleType}, got ${value.items.length}`
90
+ );
91
+ }
92
+ for (let i = 0; i < entryCount; i++) {
93
+ this.entryVectors[i].setItem(itemIndex, value.items[i]);
94
+ }
95
+ this.validity.setItemValid(itemIndex, true);
96
+ } else {
97
+ for (const entryVector of this.entryVectors) {
98
+ entryVector.setItem(itemIndex, null);
99
+ }
100
+ this.validity.setItemValid(itemIndex, false);
101
+ }
102
+ }
103
+ public setItemValue(
104
+ itemIndex: number,
105
+ entryIndex: number,
106
+ value: DuckDBValue
107
+ ) {
108
+ return this.entryVectors[entryIndex].setItem(itemIndex, value);
109
+ }
110
+ public override flush() {
111
+ for (const entryVector of this.entryVectors) {
112
+ entryVector.flush();
113
+ }
114
+ this.validity.flush(this.vector);
115
+ }
116
+ public override slice(offset: number, length: number): DuckDBTupleVector {
117
+ return new DuckDBTupleVector(
118
+ this.tupleType,
119
+ length,
120
+ this.entryVectors.map((entryVector) => entryVector.slice(offset, length)),
121
+ this.validity.slice(offset, length),
122
+ this.vector
123
+ );
124
+ }
125
+ }
@@ -0,0 +1,75 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBUBigIntType,
4
+ } from '../DuckDBType';
5
+ import { DuckDBVector } from './DuckDBVector';
6
+ import { DuckDBValidity } from './DuckDBValidity';
7
+ import {
8
+ vectorData,
9
+ } from './dataAccessors';
10
+
11
+ export class DuckDBUBigIntVector extends DuckDBVector<bigint> {
12
+ private readonly items: BigUint64Array;
13
+ private readonly validity: DuckDBValidity;
14
+ private readonly vector: duckdb.Vector;
15
+ constructor(
16
+ items: BigUint64Array,
17
+ validity: DuckDBValidity,
18
+ vector: duckdb.Vector
19
+ ) {
20
+ super();
21
+ this.items = items;
22
+ this.validity = validity;
23
+ this.vector = vector;
24
+ }
25
+ static fromRawVector(
26
+ vector: duckdb.Vector,
27
+ itemCount: number
28
+ ): DuckDBUBigIntVector {
29
+ const data = vectorData(
30
+ vector,
31
+ itemCount * BigUint64Array.BYTES_PER_ELEMENT
32
+ );
33
+ const items = new BigUint64Array(data.buffer, data.byteOffset, itemCount);
34
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
35
+ return new DuckDBUBigIntVector(items, validity, vector);
36
+ }
37
+ public override get type(): DuckDBUBigIntType {
38
+ return DuckDBUBigIntType.instance;
39
+ }
40
+ public override get itemCount(): number {
41
+ return this.items.length;
42
+ }
43
+ public override getItem(itemIndex: number): bigint | null {
44
+ return this.validity.itemValid(itemIndex) ? this.items[itemIndex] : null;
45
+ }
46
+ public override setItem(itemIndex: number, value: bigint | null) {
47
+ if (value != null) {
48
+ // Checked inline for bulk-write throughput; see dataAccessors.ts.
49
+ if (BigInt.asUintN(64, value) !== value) {
50
+ throw new Error(`bigint out of uint64 range`);
51
+ }
52
+ this.items[itemIndex] = value;
53
+ this.validity.setItemValid(itemIndex, true);
54
+ } else {
55
+ this.validity.setItemValid(itemIndex, false);
56
+ }
57
+ }
58
+ public override flush() {
59
+ duckdb.copy_data_to_vector(
60
+ this.vector,
61
+ 0,
62
+ this.items.buffer as ArrayBuffer,
63
+ this.items.byteOffset,
64
+ this.items.byteLength
65
+ );
66
+ this.validity.flush(this.vector);
67
+ }
68
+ public override slice(offset: number, length: number): DuckDBUBigIntVector {
69
+ return new DuckDBUBigIntVector(
70
+ this.items.slice(offset, offset + length),
71
+ this.validity.slice(offset, length),
72
+ this.vector
73
+ );
74
+ }
75
+ }
@@ -0,0 +1,89 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBUHugeIntType,
4
+ } from '../DuckDBType';
5
+ import { DuckDBVector } from './DuckDBVector';
6
+ import { DuckDBValidity } from './DuckDBValidity';
7
+ import {
8
+ getUInt128,
9
+ setUInt128,
10
+ vectorData,
11
+ } from './dataAccessors';
12
+
13
+ export class DuckDBUHugeIntVector extends DuckDBVector<bigint> {
14
+ private readonly dataView: DataView;
15
+ private readonly validity: DuckDBValidity;
16
+ private readonly vector: duckdb.Vector;
17
+ private readonly _itemCount: number;
18
+ constructor(
19
+ dataView: DataView,
20
+ validity: DuckDBValidity,
21
+ vector: duckdb.Vector,
22
+ itemCount: number
23
+ ) {
24
+ super();
25
+ this.dataView = dataView;
26
+ this.validity = validity;
27
+ this.vector = vector;
28
+ this._itemCount = itemCount;
29
+ }
30
+ static fromRawVector(
31
+ vector: duckdb.Vector,
32
+ itemCount: number
33
+ ): DuckDBUHugeIntVector {
34
+ const data = vectorData(vector, itemCount * 16);
35
+ const dataView = new DataView(
36
+ data.buffer,
37
+ data.byteOffset,
38
+ data.byteLength
39
+ );
40
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
41
+ return new DuckDBUHugeIntVector(dataView, validity, vector, itemCount);
42
+ }
43
+ public override get type(): DuckDBUHugeIntType {
44
+ return DuckDBUHugeIntType.instance;
45
+ }
46
+ public override get itemCount(): number {
47
+ return this._itemCount;
48
+ }
49
+ public override getItem(itemIndex: number): bigint | null {
50
+ return this.validity.itemValid(itemIndex)
51
+ ? getUInt128(this.dataView, itemIndex * 16)
52
+ : null;
53
+ }
54
+ public getDouble(itemIndex: number): number | null {
55
+ return this.validity.itemValid(itemIndex)
56
+ ? duckdb.uhugeint_to_double(getUInt128(this.dataView, itemIndex * 16))
57
+ : null;
58
+ }
59
+ public override setItem(itemIndex: number, value: bigint | null) {
60
+ if (value != null) {
61
+ setUInt128(this.dataView, itemIndex * 16, value);
62
+ this.validity.setItemValid(itemIndex, true);
63
+ } else {
64
+ this.validity.setItemValid(itemIndex, false);
65
+ }
66
+ }
67
+ public override flush() {
68
+ duckdb.copy_data_to_vector(
69
+ this.vector,
70
+ 0,
71
+ this.dataView.buffer as ArrayBuffer,
72
+ this.dataView.byteOffset,
73
+ this.dataView.byteLength
74
+ );
75
+ this.validity.flush(this.vector);
76
+ }
77
+ public override slice(offset: number, length: number): DuckDBUHugeIntVector {
78
+ return new DuckDBUHugeIntVector(
79
+ new DataView(
80
+ this.dataView.buffer,
81
+ this.dataView.byteOffset + offset * 16,
82
+ length * 16
83
+ ),
84
+ this.validity.slice(offset, length),
85
+ this.vector,
86
+ length
87
+ );
88
+ }
89
+ }
@@ -0,0 +1,75 @@
1
+ import duckdb from "../../../../src/bindings/index.ts";
2
+ import {
3
+ DuckDBUIntegerType,
4
+ } from '../DuckDBType';
5
+ import { DuckDBVector } from './DuckDBVector';
6
+ import { DuckDBValidity } from './DuckDBValidity';
7
+ import {
8
+ vectorData,
9
+ } from './dataAccessors';
10
+
11
+ export class DuckDBUIntegerVector extends DuckDBVector<number> {
12
+ private readonly items: Uint32Array;
13
+ private readonly validity: DuckDBValidity;
14
+ private readonly vector: duckdb.Vector;
15
+ constructor(
16
+ items: Uint32Array,
17
+ validity: DuckDBValidity,
18
+ vector: duckdb.Vector
19
+ ) {
20
+ super();
21
+ this.items = items;
22
+ this.validity = validity;
23
+ this.vector = vector;
24
+ }
25
+ static fromRawVector(
26
+ vector: duckdb.Vector,
27
+ itemCount: number
28
+ ): DuckDBUIntegerVector {
29
+ const data = vectorData(vector, itemCount * Uint32Array.BYTES_PER_ELEMENT);
30
+ const items = new Uint32Array(data.buffer, data.byteOffset, itemCount);
31
+ const validity = DuckDBValidity.fromVector(vector, itemCount);
32
+ return new DuckDBUIntegerVector(items, validity, vector);
33
+ }
34
+ public override get type(): DuckDBUIntegerType {
35
+ return DuckDBUIntegerType.instance;
36
+ }
37
+ public override get itemCount(): number {
38
+ return this.items.length;
39
+ }
40
+ public override getItem(itemIndex: number): number | null {
41
+ return this.validity.itemValid(itemIndex) ? this.items[itemIndex] : null;
42
+ }
43
+ public override setItem(itemIndex: number, value: number | null) {
44
+ if (value != null) {
45
+ // Checked inline for bulk-write throughput; see dataAccessors.ts.
46
+ if (!Number.isInteger(value)) {
47
+ throw new Error(`number is not an integer`);
48
+ }
49
+ if (value < 0 || value > 4294967295) {
50
+ throw new Error(`number out of uint32 range`);
51
+ }
52
+ this.items[itemIndex] = value;
53
+ this.validity.setItemValid(itemIndex, true);
54
+ } else {
55
+ this.validity.setItemValid(itemIndex, false);
56
+ }
57
+ }
58
+ public override flush() {
59
+ duckdb.copy_data_to_vector(
60
+ this.vector,
61
+ 0,
62
+ this.items.buffer as ArrayBuffer,
63
+ this.items.byteOffset,
64
+ this.items.byteLength
65
+ );
66
+ this.validity.flush(this.vector);
67
+ }
68
+ public override slice(offset: number, length: number): DuckDBUIntegerVector {
69
+ return new DuckDBUIntegerVector(
70
+ this.items.slice(offset, offset + length),
71
+ this.validity.slice(offset, length),
72
+ this.vector
73
+ );
74
+ }
75
+ }