@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,104 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import type { DuckDBType } from './DuckDBType';
3
+ import { DuckDBLogicalType } from '../DuckDBLogicalType';
4
+ import { DuckDBTypeId } from '../DuckDBTypeId';
5
+ import { Json } from '../Json';
6
+ import { quotedIdentifier } from '../sql';
7
+
8
+ export class DuckDBStructType extends BaseDuckDBType<DuckDBTypeId.STRUCT> {
9
+ public readonly entryNames: readonly string[];
10
+ public readonly entryTypes: readonly DuckDBType[];
11
+ public readonly entryIndexes: Readonly<Record<string, number>>;
12
+ public constructor(
13
+ entryNames: readonly string[],
14
+ entryTypes: readonly DuckDBType[],
15
+ alias?: string
16
+ ) {
17
+ super(DuckDBTypeId.STRUCT, alias);
18
+ if (entryNames.length !== entryTypes.length) {
19
+ throw new Error(`Could not create DuckDBStructType: \
20
+ entryNames length (${entryNames.length}) does not match entryTypes length (${entryTypes.length})`);
21
+ }
22
+ this.entryNames = entryNames;
23
+ this.entryTypes = entryTypes;
24
+ const entryIndexes: Record<string, number> = {};
25
+ for (let i = 0; i < entryNames.length; i++) {
26
+ entryIndexes[entryNames[i]] = i;
27
+ }
28
+ this.entryIndexes = entryIndexes;
29
+ }
30
+ public get entryCount() {
31
+ return this.entryNames.length;
32
+ }
33
+ /**
34
+ * Whether this is an unnamed struct, i.e. a tuple, such as the type of
35
+ * `(1, 'a')` or `row(1, 'a')`. DuckDB reports these as STRUCTs whose entry
36
+ * names are all empty. A STRUCT with no entries is not a tuple.
37
+ *
38
+ * Values of a tuple type are `DuckDBTupleValue`s, whose items are
39
+ * positional, rather than `DuckDBStructValue`s.
40
+ */
41
+ public get isTuple(): boolean {
42
+ return (
43
+ this.entryNames.length > 0 && this.entryNames.every((name) => name === '')
44
+ );
45
+ }
46
+ public indexForEntry(entryName: string): number {
47
+ return this.entryIndexes[entryName];
48
+ }
49
+ public typeForEntry(entryName: string): DuckDBType {
50
+ return this.entryTypes[this.entryIndexes[entryName]];
51
+ }
52
+ public toString(): string {
53
+ if (this.entryNames.length === 0) {
54
+ return 'STRUCT';
55
+ }
56
+ if (this.isTuple) {
57
+ return `TUPLE(${this.entryTypes.join(', ')})`;
58
+ }
59
+ const parts: string[] = [];
60
+ for (let i = 0; i < this.entryNames.length; i++) {
61
+ parts.push(
62
+ `${quotedIdentifier(this.entryNames[i])} ${this.entryTypes[i]}`
63
+ );
64
+ }
65
+ return `STRUCT(${parts.join(', ')})`;
66
+ }
67
+ public override toLogicalType(): DuckDBLogicalType {
68
+ const logicalType = DuckDBLogicalType.createStruct(
69
+ this.entryNames,
70
+ this.entryTypes.map((t) => t.toLogicalType())
71
+ );
72
+ if (this.alias) {
73
+ logicalType.alias = this.alias;
74
+ }
75
+ return logicalType;
76
+ }
77
+ public override toJson(): Json {
78
+ return {
79
+ typeId: this.typeId,
80
+ entryNames: [...this.entryNames],
81
+ entryTypes: this.entryTypes.map(t => t.toJson()),
82
+ ...(this.alias ? { alias: this.alias } : {}),
83
+ };
84
+ }
85
+ }
86
+ export function STRUCT(
87
+ entries: Record<string, DuckDBType>,
88
+ alias?: string
89
+ ): DuckDBStructType {
90
+ const entryNames = Object.keys(entries);
91
+ const entryTypes = Object.values(entries);
92
+ return new DuckDBStructType(entryNames, entryTypes, alias);
93
+ }
94
+ /** Creates a tuple type: an unnamed STRUCT with the given entry types. */
95
+ export function TUPLE(
96
+ entryTypes: readonly DuckDBType[],
97
+ alias?: string
98
+ ): DuckDBStructType {
99
+ return new DuckDBStructType(
100
+ entryTypes.map(() => ''),
101
+ entryTypes,
102
+ alias
103
+ );
104
+ }
@@ -0,0 +1,20 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimeNSValue } from '../values';
4
+
5
+ export class DuckDBTimeNSType extends BaseDuckDBType<DuckDBTypeId.TIME_NS> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIME_NS, alias);
8
+ }
9
+ public static readonly instance = new DuckDBTimeNSType();
10
+ public static create(alias?: string): DuckDBTimeNSType {
11
+ return alias ? new DuckDBTimeNSType(alias) : DuckDBTimeNSType.instance;
12
+ }
13
+ public get max() {
14
+ return DuckDBTimeNSValue.Max;
15
+ }
16
+ public get min() {
17
+ return DuckDBTimeNSValue.Min;
18
+ }
19
+ }
20
+ export const TIME_NS = DuckDBTimeNSType.instance;
@@ -0,0 +1,23 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimeTZValue } from '../values';
4
+
5
+ export class DuckDBTimeTZType extends BaseDuckDBType<DuckDBTypeId.TIME_TZ> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIME_TZ, alias);
8
+ }
9
+ public toString(): string {
10
+ return 'TIME WITH TIME ZONE';
11
+ }
12
+ public static readonly instance = new DuckDBTimeTZType();
13
+ public static create(alias?: string): DuckDBTimeTZType {
14
+ return alias ? new DuckDBTimeTZType(alias) : DuckDBTimeTZType.instance;
15
+ }
16
+ public get max() {
17
+ return DuckDBTimeTZValue.Max;
18
+ }
19
+ public get min() {
20
+ return DuckDBTimeTZValue.Min;
21
+ }
22
+ }
23
+ export const TIMETZ = DuckDBTimeTZType.instance;
@@ -0,0 +1,20 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimeValue } from '../values';
4
+
5
+ export class DuckDBTimeType extends BaseDuckDBType<DuckDBTypeId.TIME> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIME, alias);
8
+ }
9
+ public static readonly instance = new DuckDBTimeType();
10
+ public static create(alias?: string): DuckDBTimeType {
11
+ return alias ? new DuckDBTimeType(alias) : DuckDBTimeType.instance;
12
+ }
13
+ public get max() {
14
+ return DuckDBTimeValue.Max;
15
+ }
16
+ public get min() {
17
+ return DuckDBTimeValue.Min;
18
+ }
19
+ }
20
+ export const TIME = DuckDBTimeType.instance;
@@ -0,0 +1,29 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimestampMillisecondsValue } from '../values';
4
+
5
+ export class DuckDBTimestampMillisecondsType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP_MS> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIMESTAMP_MS, alias);
8
+ }
9
+ public static readonly instance = new DuckDBTimestampMillisecondsType();
10
+ public static create(alias?: string): DuckDBTimestampMillisecondsType {
11
+ return alias ? new DuckDBTimestampMillisecondsType(alias) : DuckDBTimestampMillisecondsType.instance;
12
+ }
13
+ public get epoch() {
14
+ return DuckDBTimestampMillisecondsValue.Epoch;
15
+ }
16
+ public get max() {
17
+ return DuckDBTimestampMillisecondsValue.Max;
18
+ }
19
+ public get min() {
20
+ return DuckDBTimestampMillisecondsValue.Min;
21
+ }
22
+ public get posInf() {
23
+ return DuckDBTimestampMillisecondsValue.PosInf;
24
+ }
25
+ public get negInf() {
26
+ return DuckDBTimestampMillisecondsValue.NegInf;
27
+ }
28
+ }
29
+ export const TIMESTAMP_MS = DuckDBTimestampMillisecondsType.instance;
@@ -0,0 +1,29 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimestampNanosecondsValue } from '../values';
4
+
5
+ export class DuckDBTimestampNanosecondsType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP_NS> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIMESTAMP_NS, alias);
8
+ }
9
+ public static readonly instance = new DuckDBTimestampNanosecondsType();
10
+ public static create(alias?: string): DuckDBTimestampNanosecondsType {
11
+ return alias ? new DuckDBTimestampNanosecondsType(alias) : DuckDBTimestampNanosecondsType.instance;
12
+ }
13
+ public get epoch() {
14
+ return DuckDBTimestampNanosecondsValue.Epoch;
15
+ }
16
+ public get max() {
17
+ return DuckDBTimestampNanosecondsValue.Max;
18
+ }
19
+ public get min() {
20
+ return DuckDBTimestampNanosecondsValue.Min;
21
+ }
22
+ public get posInf() {
23
+ return DuckDBTimestampNanosecondsValue.PosInf;
24
+ }
25
+ public get negInf() {
26
+ return DuckDBTimestampNanosecondsValue.NegInf;
27
+ }
28
+ }
29
+ export const TIMESTAMP_NS = DuckDBTimestampNanosecondsType.instance;
@@ -0,0 +1,29 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimestampSecondsValue } from '../values';
4
+
5
+ export class DuckDBTimestampSecondsType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP_S> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIMESTAMP_S, alias);
8
+ }
9
+ public static readonly instance = new DuckDBTimestampSecondsType();
10
+ public static create(alias?: string): DuckDBTimestampSecondsType {
11
+ return alias ? new DuckDBTimestampSecondsType(alias) : DuckDBTimestampSecondsType.instance;
12
+ }
13
+ public get epoch() {
14
+ return DuckDBTimestampSecondsValue.Epoch;
15
+ }
16
+ public get max() {
17
+ return DuckDBTimestampSecondsValue.Max;
18
+ }
19
+ public get min() {
20
+ return DuckDBTimestampSecondsValue.Min;
21
+ }
22
+ public get posInf() {
23
+ return DuckDBTimestampSecondsValue.PosInf;
24
+ }
25
+ public get negInf() {
26
+ return DuckDBTimestampSecondsValue.NegInf;
27
+ }
28
+ }
29
+ export const TIMESTAMP_S = DuckDBTimestampSecondsType.instance;
@@ -0,0 +1,32 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimestampTZNanosecondsValue } from '../values';
4
+
5
+ export class DuckDBTimestampTZNanosecondsType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP_TZ_NS> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIMESTAMP_TZ_NS, alias);
8
+ }
9
+ public toString(): string {
10
+ return 'TIMESTAMPTZ_NS';
11
+ }
12
+ public static readonly instance = new DuckDBTimestampTZNanosecondsType();
13
+ public static create(alias?: string): DuckDBTimestampTZNanosecondsType {
14
+ return alias ? new DuckDBTimestampTZNanosecondsType(alias) : DuckDBTimestampTZNanosecondsType.instance;
15
+ }
16
+ public get epoch() {
17
+ return DuckDBTimestampTZNanosecondsValue.Epoch;
18
+ }
19
+ public get max() {
20
+ return DuckDBTimestampTZNanosecondsValue.Max;
21
+ }
22
+ public get min() {
23
+ return DuckDBTimestampTZNanosecondsValue.Min;
24
+ }
25
+ public get posInf() {
26
+ return DuckDBTimestampTZNanosecondsValue.PosInf;
27
+ }
28
+ public get negInf() {
29
+ return DuckDBTimestampTZNanosecondsValue.NegInf;
30
+ }
31
+ }
32
+ export const TIMESTAMPTZ_NS = DuckDBTimestampTZNanosecondsType.instance;
@@ -0,0 +1,32 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimestampTZValue } from '../values';
4
+
5
+ export class DuckDBTimestampTZType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP_TZ> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIMESTAMP_TZ, alias);
8
+ }
9
+ public toString(): string {
10
+ return 'TIMESTAMP WITH TIME ZONE';
11
+ }
12
+ public static readonly instance = new DuckDBTimestampTZType();
13
+ public static create(alias?: string): DuckDBTimestampTZType {
14
+ return alias ? new DuckDBTimestampTZType(alias) : DuckDBTimestampTZType.instance;
15
+ }
16
+ public get epoch() {
17
+ return DuckDBTimestampTZValue.Epoch;
18
+ }
19
+ public get max() {
20
+ return DuckDBTimestampTZValue.Max;
21
+ }
22
+ public get min() {
23
+ return DuckDBTimestampTZValue.Min;
24
+ }
25
+ public get posInf() {
26
+ return DuckDBTimestampTZValue.PosInf;
27
+ }
28
+ public get negInf() {
29
+ return DuckDBTimestampTZValue.NegInf;
30
+ }
31
+ }
32
+ export const TIMESTAMPTZ = DuckDBTimestampTZType.instance;
@@ -0,0 +1,32 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBTimestampValue } from '../values';
4
+
5
+ export class DuckDBTimestampType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.TIMESTAMP, alias);
8
+ }
9
+ public static readonly instance = new DuckDBTimestampType();
10
+ public static create(alias?: string): DuckDBTimestampType {
11
+ return alias ? new DuckDBTimestampType(alias) : DuckDBTimestampType.instance;
12
+ }
13
+ public get epoch() {
14
+ return DuckDBTimestampValue.Epoch;
15
+ }
16
+ public get max() {
17
+ return DuckDBTimestampValue.Max;
18
+ }
19
+ public get min() {
20
+ return DuckDBTimestampValue.Min;
21
+ }
22
+ public get posInf() {
23
+ return DuckDBTimestampValue.PosInf;
24
+ }
25
+ public get negInf() {
26
+ return DuckDBTimestampValue.NegInf;
27
+ }
28
+ }
29
+ export const TIMESTAMP = DuckDBTimestampType.instance;
30
+
31
+ export type DuckDBTimestampMicrosecondsType = DuckDBTimestampType;
32
+ export const DuckDBTimestampMicrosecondsType = DuckDBTimestampType;
@@ -0,0 +1,21 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+
4
+ export class DuckDBTinyIntType extends BaseDuckDBType<DuckDBTypeId.TINYINT> {
5
+ public constructor(alias?: string) {
6
+ super(DuckDBTypeId.TINYINT, alias);
7
+ }
8
+ public static readonly instance = new DuckDBTinyIntType();
9
+ public static create(alias?: string): DuckDBTinyIntType {
10
+ return alias ? new DuckDBTinyIntType(alias) : DuckDBTinyIntType.instance;
11
+ }
12
+ public static readonly Max = 2 ** 7 - 1;
13
+ public static readonly Min = -(2 ** 7);
14
+ public get max() {
15
+ return DuckDBTinyIntType.Max;
16
+ }
17
+ public get min() {
18
+ return DuckDBTinyIntType.Min;
19
+ }
20
+ }
21
+ export const TINYINT = DuckDBTinyIntType.instance;
@@ -0,0 +1,86 @@
1
+ import type { DuckDBAnyType } from './DuckDBAnyType';
2
+ import type { DuckDBArrayType } from './DuckDBArrayType';
3
+ import type { DuckDBBigIntType } from './DuckDBBigIntType';
4
+ import type { DuckDBBigNumType } from './DuckDBBigNumType';
5
+ import type { DuckDBBitType } from './DuckDBBitType';
6
+ import type { DuckDBBlobType } from './DuckDBBlobType';
7
+ import type { DuckDBBooleanType } from './DuckDBBooleanType';
8
+ import type { DuckDBDateType } from './DuckDBDateType';
9
+ import type { DuckDBDecimalType } from './DuckDBDecimalType';
10
+ import type { DuckDBDoubleType } from './DuckDBDoubleType';
11
+ import type { DuckDBEnumType } from './DuckDBEnumType';
12
+ import type { DuckDBFloatType } from './DuckDBFloatType';
13
+ import type { DuckDBGeometryType } from './DuckDBGeometryType';
14
+ import type { DuckDBHugeIntType } from './DuckDBHugeIntType';
15
+ import type { DuckDBIntegerLiteralType } from './DuckDBIntegerLiteralType';
16
+ import type { DuckDBIntegerType } from './DuckDBIntegerType';
17
+ import type { DuckDBIntervalType } from './DuckDBIntervalType';
18
+ import type { DuckDBListType } from './DuckDBListType';
19
+ import type { DuckDBMapType } from './DuckDBMapType';
20
+ import type { DuckDBSQLNullType } from './DuckDBSQLNullType';
21
+ import type { DuckDBSmallIntType } from './DuckDBSmallIntType';
22
+ import type { DuckDBStringLiteralType } from './DuckDBStringLiteralType';
23
+ import type { DuckDBStructType } from './DuckDBStructType';
24
+ import type { DuckDBTimeNSType } from './DuckDBTimeNSType';
25
+ import type { DuckDBTimeTZType } from './DuckDBTimeTZType';
26
+ import type { DuckDBTimeType } from './DuckDBTimeType';
27
+ import type { DuckDBTimestampMillisecondsType } from './DuckDBTimestampMillisecondsType';
28
+ import type { DuckDBTimestampNanosecondsType } from './DuckDBTimestampNanosecondsType';
29
+ import type { DuckDBTimestampSecondsType } from './DuckDBTimestampSecondsType';
30
+ import type { DuckDBTimestampTZType } from './DuckDBTimestampTZType';
31
+ import type { DuckDBTimestampTZNanosecondsType } from './DuckDBTimestampTZNanosecondsType';
32
+ import type { DuckDBTimestampType } from './DuckDBTimestampType';
33
+ import type { DuckDBTinyIntType } from './DuckDBTinyIntType';
34
+ import type { DuckDBUnionType } from './DuckDBUnionType';
35
+ import type { DuckDBUBigIntType } from './DuckDBUBigIntType';
36
+ import type { DuckDBUHugeIntType } from './DuckDBUHugeIntType';
37
+ import type { DuckDBUIntegerType } from './DuckDBUIntegerType';
38
+ import type { DuckDBUSmallIntType } from './DuckDBUSmallIntType';
39
+ import type { DuckDBUTinyIntType } from './DuckDBUTinyIntType';
40
+ import type { DuckDBUUIDType } from './DuckDBUUIDType';
41
+ import type { DuckDBVarCharType } from './DuckDBVarCharType';
42
+ import type { DuckDBVariantType } from './DuckDBVariantType';
43
+
44
+ export type DuckDBType =
45
+ | DuckDBBooleanType
46
+ | DuckDBTinyIntType
47
+ | DuckDBSmallIntType
48
+ | DuckDBIntegerType
49
+ | DuckDBBigIntType
50
+ | DuckDBUTinyIntType
51
+ | DuckDBUSmallIntType
52
+ | DuckDBUIntegerType
53
+ | DuckDBUBigIntType
54
+ | DuckDBFloatType
55
+ | DuckDBDoubleType
56
+ | DuckDBTimestampType
57
+ | DuckDBDateType
58
+ | DuckDBTimeType
59
+ | DuckDBIntervalType
60
+ | DuckDBHugeIntType
61
+ | DuckDBUHugeIntType
62
+ | DuckDBVarCharType
63
+ | DuckDBBlobType
64
+ | DuckDBDecimalType
65
+ | DuckDBTimestampSecondsType
66
+ | DuckDBTimestampMillisecondsType
67
+ | DuckDBTimestampNanosecondsType
68
+ | DuckDBEnumType
69
+ | DuckDBListType
70
+ | DuckDBStructType
71
+ | DuckDBMapType
72
+ | DuckDBArrayType
73
+ | DuckDBUUIDType
74
+ | DuckDBUnionType
75
+ | DuckDBBitType
76
+ | DuckDBTimeTZType
77
+ | DuckDBTimestampTZType
78
+ | DuckDBAnyType
79
+ | DuckDBBigNumType
80
+ | DuckDBSQLNullType
81
+ | DuckDBStringLiteralType
82
+ | DuckDBIntegerLiteralType
83
+ | DuckDBTimeNSType
84
+ | DuckDBGeometryType
85
+ | DuckDBVariantType
86
+ | DuckDBTimestampTZNanosecondsType;
@@ -0,0 +1,21 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+
4
+ export class DuckDBUBigIntType extends BaseDuckDBType<DuckDBTypeId.UBIGINT> {
5
+ public constructor(alias?: string) {
6
+ super(DuckDBTypeId.UBIGINT, alias);
7
+ }
8
+ public static readonly instance = new DuckDBUBigIntType();
9
+ public static create(alias?: string): DuckDBUBigIntType {
10
+ return alias ? new DuckDBUBigIntType(alias) : DuckDBUBigIntType.instance;
11
+ }
12
+ public static readonly Max: bigint = 2n ** 64n - 1n;
13
+ public static readonly Min: bigint = 0n;
14
+ public get max() {
15
+ return DuckDBUBigIntType.Max;
16
+ }
17
+ public get min() {
18
+ return DuckDBUBigIntType.Min;
19
+ }
20
+ }
21
+ export const UBIGINT = DuckDBUBigIntType.instance;
@@ -0,0 +1,21 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+
4
+ export class DuckDBUHugeIntType extends BaseDuckDBType<DuckDBTypeId.UHUGEINT> {
5
+ public constructor(alias?: string) {
6
+ super(DuckDBTypeId.UHUGEINT, alias);
7
+ }
8
+ public static readonly instance = new DuckDBUHugeIntType();
9
+ public static create(alias?: string): DuckDBUHugeIntType {
10
+ return alias ? new DuckDBUHugeIntType(alias) : DuckDBUHugeIntType.instance;
11
+ }
12
+ public static readonly Max: bigint = 2n ** 128n - 1n;
13
+ public static readonly Min: bigint = 0n;
14
+ public get max() {
15
+ return DuckDBUHugeIntType.Max;
16
+ }
17
+ public get min() {
18
+ return DuckDBUHugeIntType.Min;
19
+ }
20
+ }
21
+ export const UHUGEINT = DuckDBUHugeIntType.instance;
@@ -0,0 +1,21 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+
4
+ export class DuckDBUIntegerType extends BaseDuckDBType<DuckDBTypeId.UINTEGER> {
5
+ public constructor(alias?: string) {
6
+ super(DuckDBTypeId.UINTEGER, alias);
7
+ }
8
+ public static readonly instance = new DuckDBUIntegerType();
9
+ public static create(alias?: string): DuckDBUIntegerType {
10
+ return alias ? new DuckDBUIntegerType(alias) : DuckDBUIntegerType.instance;
11
+ }
12
+ public static readonly Max = 2 ** 32 - 1;
13
+ public static readonly Min = 0;
14
+ public get max() {
15
+ return DuckDBUIntegerType.Max;
16
+ }
17
+ public get min() {
18
+ return DuckDBUIntegerType.Min;
19
+ }
20
+ }
21
+ export const UINTEGER = DuckDBUIntegerType.instance;
@@ -0,0 +1,21 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+
4
+ export class DuckDBUSmallIntType extends BaseDuckDBType<DuckDBTypeId.USMALLINT> {
5
+ public constructor(alias?: string) {
6
+ super(DuckDBTypeId.USMALLINT, alias);
7
+ }
8
+ public static readonly instance = new DuckDBUSmallIntType();
9
+ public static create(alias?: string): DuckDBUSmallIntType {
10
+ return alias ? new DuckDBUSmallIntType(alias) : DuckDBUSmallIntType.instance;
11
+ }
12
+ public static readonly Max = 2 ** 16 - 1;
13
+ public static readonly Min = 0;
14
+ public get max() {
15
+ return DuckDBUSmallIntType.Max;
16
+ }
17
+ public get min() {
18
+ return DuckDBUSmallIntType.Min;
19
+ }
20
+ }
21
+ export const USMALLINT = DuckDBUSmallIntType.instance;
@@ -0,0 +1,21 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+
4
+ export class DuckDBUTinyIntType extends BaseDuckDBType<DuckDBTypeId.UTINYINT> {
5
+ public constructor(alias?: string) {
6
+ super(DuckDBTypeId.UTINYINT, alias);
7
+ }
8
+ public static readonly instance = new DuckDBUTinyIntType();
9
+ public static create(alias?: string): DuckDBUTinyIntType {
10
+ return alias ? new DuckDBUTinyIntType(alias) : DuckDBUTinyIntType.instance;
11
+ }
12
+ public static readonly Max = 2 ** 8 - 1;
13
+ public static readonly Min = 0;
14
+ public get max() {
15
+ return DuckDBUTinyIntType.Max;
16
+ }
17
+ public get min() {
18
+ return DuckDBUTinyIntType.Min;
19
+ }
20
+ }
21
+ export const UTINYINT = DuckDBUTinyIntType.instance;
@@ -0,0 +1,20 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import { DuckDBTypeId } from '../DuckDBTypeId';
3
+ import { DuckDBUUIDValue } from '../values';
4
+
5
+ export class DuckDBUUIDType extends BaseDuckDBType<DuckDBTypeId.UUID> {
6
+ public constructor(alias?: string) {
7
+ super(DuckDBTypeId.UUID, alias);
8
+ }
9
+ public static readonly instance = new DuckDBUUIDType();
10
+ public static create(alias?: string): DuckDBUUIDType {
11
+ return alias ? new DuckDBUUIDType(alias) : DuckDBUUIDType.instance;
12
+ }
13
+ public get max() {
14
+ return DuckDBUUIDValue.Max;
15
+ }
16
+ public get min() {
17
+ return DuckDBUUIDValue.Min;
18
+ }
19
+ }
20
+ export const UUID = DuckDBUUIDType.instance;
@@ -0,0 +1,74 @@
1
+ import { BaseDuckDBType } from './BaseDuckDBType';
2
+ import type { DuckDBType } from './DuckDBType';
3
+ import { DuckDBLogicalType } from '../DuckDBLogicalType';
4
+ import { DuckDBTypeId } from '../DuckDBTypeId';
5
+ import { Json } from '../Json';
6
+ import { quotedIdentifier } from '../sql';
7
+
8
+ export class DuckDBUnionType extends BaseDuckDBType<DuckDBTypeId.UNION> {
9
+ public readonly memberTags: readonly string[];
10
+ public readonly tagMemberIndexes: Readonly<Record<string, number>>;
11
+ public readonly memberTypes: readonly DuckDBType[];
12
+ public constructor(
13
+ memberTags: readonly string[],
14
+ memberTypes: readonly DuckDBType[],
15
+ alias?: string
16
+ ) {
17
+ super(DuckDBTypeId.UNION, alias);
18
+ if (memberTags.length !== memberTypes.length) {
19
+ throw new Error(`Could not create DuckDBUnionType: \
20
+ tags length (${memberTags.length}) does not match valueTypes length (${memberTypes.length})`);
21
+ }
22
+ this.memberTags = memberTags;
23
+ const tagMemberIndexes: Record<string, number> = {};
24
+ for (let i = 0; i < memberTags.length; i++) {
25
+ tagMemberIndexes[memberTags[i]] = i;
26
+ }
27
+ this.tagMemberIndexes = tagMemberIndexes;
28
+ this.memberTypes = memberTypes;
29
+ }
30
+ public memberIndexForTag(tag: string): number {
31
+ return this.tagMemberIndexes[tag];
32
+ }
33
+ public memberTypeForTag(tag: string): DuckDBType {
34
+ return this.memberTypes[this.tagMemberIndexes[tag]];
35
+ }
36
+ public get memberCount() {
37
+ return this.memberTags.length;
38
+ }
39
+ public toString(): string {
40
+ const parts: string[] = [];
41
+ for (let i = 0; i < this.memberTags.length; i++) {
42
+ parts.push(
43
+ `${quotedIdentifier(this.memberTags[i])} ${this.memberTypes[i]}`
44
+ );
45
+ }
46
+ return `UNION(${parts.join(', ')})`;
47
+ }
48
+ public override toLogicalType(): DuckDBLogicalType {
49
+ const logicalType = DuckDBLogicalType.createUnion(
50
+ this.memberTags,
51
+ this.memberTypes.map((t) => t.toLogicalType())
52
+ );
53
+ if (this.alias) {
54
+ logicalType.alias = this.alias;
55
+ }
56
+ return logicalType;
57
+ }
58
+ public override toJson(): Json {
59
+ return {
60
+ typeId: this.typeId,
61
+ memberTags: [...this.memberTags],
62
+ memberTypes: this.memberTypes.map(t => t.toJson()),
63
+ ...(this.alias ? { alias: this.alias } : {}),
64
+ };
65
+ }
66
+ }
67
+ export function UNION(
68
+ members: Record<string, DuckDBType>,
69
+ alias?: string
70
+ ): DuckDBUnionType {
71
+ const memberTags = Object.keys(members);
72
+ const memberTypes = Object.values(members);
73
+ return new DuckDBUnionType(memberTags, memberTypes, alias);
74
+ }