@avidian/duckdb-bun 0.0.0-stage → 1.0.1

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 +286 -2
  3. package/package.json +96 -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 +213 -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 +153 -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,376 @@
1
+ import duckdb from "../../../src/bindings/index.ts";
2
+ import { createValue } from './createValue';
3
+ import { DuckDBLogicalType } from './DuckDBLogicalType';
4
+ import { DuckDBMaterializedResult } from './DuckDBMaterializedResult';
5
+ import { DuckDBPendingResult } from './DuckDBPendingResult';
6
+ import { DuckDBResult } from './DuckDBResult';
7
+ import { DuckDBResultReader } from './DuckDBResultReader';
8
+ import {
9
+ BIGNUM,
10
+ BIT,
11
+ DuckDBArrayType,
12
+ DuckDBEnumType,
13
+ DuckDBListType,
14
+ DuckDBMapType,
15
+ DuckDBStructType,
16
+ DuckDBType,
17
+ DuckDBUnionType,
18
+ TIMESTAMP_MS,
19
+ TIMESTAMP_NS,
20
+ TIMESTAMP_S,
21
+ TIMESTAMPTZ,
22
+ TIMESTAMPTZ_NS,
23
+ TIMETZ,
24
+ UUID,
25
+ VARIANT,
26
+ } from './DuckDBType';
27
+ import { DuckDBTypeId } from './DuckDBTypeId';
28
+ import { StatementType } from './enums';
29
+ import { typeForValue } from './typeForValue';
30
+ import {
31
+ arrayValue,
32
+ DuckDBArrayValue,
33
+ DuckDBBitValue,
34
+ DuckDBDateValue,
35
+ DuckDBDecimalValue,
36
+ DuckDBIntervalValue,
37
+ DuckDBListValue,
38
+ DuckDBMapValue,
39
+ DuckDBStructValue,
40
+ DuckDBTimestampMillisecondsValue,
41
+ DuckDBTimestampNanosecondsValue,
42
+ DuckDBTimestampSecondsValue,
43
+ DuckDBTimestampTZValue,
44
+ DuckDBTimestampTZNanosecondsValue,
45
+ DuckDBTimestampValue,
46
+ DuckDBTimeTZValue,
47
+ DuckDBTimeValue,
48
+ DuckDBTupleValue,
49
+ DuckDBUnionValue,
50
+ DuckDBUUIDValue,
51
+ DuckDBValue,
52
+ DuckDBVariantValue,
53
+ listValue,
54
+ structValue,
55
+ tupleValue,
56
+ } from './values';
57
+
58
+ export class DuckDBPreparedStatement {
59
+ private readonly prepared_statement: duckdb.PreparedStatement;
60
+ constructor(prepared_statement: duckdb.PreparedStatement) {
61
+ this.prepared_statement = prepared_statement;
62
+ }
63
+ public destroySync() {
64
+ return duckdb.destroy_prepare_sync(this.prepared_statement);
65
+ }
66
+ public get statementType(): StatementType {
67
+ return duckdb.prepared_statement_type(this.prepared_statement);
68
+ }
69
+ public get parameterCount(): number {
70
+ return duckdb.nparams(this.prepared_statement);
71
+ }
72
+ public parameterName(parameterIndex: number): string {
73
+ return duckdb.parameter_name(this.prepared_statement, parameterIndex);
74
+ }
75
+ public parameterTypeId(parameterIndex: number): DuckDBTypeId {
76
+ return duckdb.param_type(
77
+ this.prepared_statement,
78
+ parameterIndex
79
+ ) as number as DuckDBTypeId;
80
+ }
81
+ public parameterType(parameterIndex: number): DuckDBType {
82
+ return DuckDBLogicalType.create(
83
+ duckdb.param_logical_type(this.prepared_statement, parameterIndex)
84
+ ).asType();
85
+ }
86
+ public get columnCount(): number {
87
+ return duckdb.prepared_statement_column_count(this.prepared_statement);
88
+ }
89
+ public columnName(columnIndex: number): string {
90
+ return duckdb.prepared_statement_column_name(
91
+ this.prepared_statement,
92
+ columnIndex
93
+ );
94
+ }
95
+ public columnTypeId(columnIndex: number): DuckDBTypeId {
96
+ return duckdb.prepared_statement_column_type(
97
+ this.prepared_statement,
98
+ columnIndex
99
+ ) as number as DuckDBTypeId;
100
+ }
101
+ public columnType(columnIndex: number): DuckDBType {
102
+ return DuckDBLogicalType.create(
103
+ duckdb.prepared_statement_column_logical_type(
104
+ this.prepared_statement,
105
+ columnIndex
106
+ )
107
+ ).asType();
108
+ }
109
+ public clearBindings() {
110
+ duckdb.clear_bindings(this.prepared_statement);
111
+ }
112
+ public parameterIndex(parameterName: string): number {
113
+ return duckdb.bind_parameter_index(this.prepared_statement, parameterName);
114
+ }
115
+ public bindBoolean(parameterIndex: number, value: boolean) {
116
+ duckdb.bind_boolean(this.prepared_statement, parameterIndex, value);
117
+ }
118
+ public bindTinyInt(parameterIndex: number, value: number) {
119
+ duckdb.bind_int8(this.prepared_statement, parameterIndex, value);
120
+ }
121
+ public bindSmallInt(parameterIndex: number, value: number) {
122
+ duckdb.bind_int16(this.prepared_statement, parameterIndex, value);
123
+ }
124
+ public bindInteger(parameterIndex: number, value: number) {
125
+ duckdb.bind_int32(this.prepared_statement, parameterIndex, value);
126
+ }
127
+ public bindBigInt(parameterIndex: number, value: bigint) {
128
+ duckdb.bind_int64(this.prepared_statement, parameterIndex, value);
129
+ }
130
+ public bindHugeInt(parameterIndex: number, value: bigint) {
131
+ duckdb.bind_hugeint(this.prepared_statement, parameterIndex, value);
132
+ }
133
+ public bindUTinyInt(parameterIndex: number, value: number) {
134
+ duckdb.bind_uint8(this.prepared_statement, parameterIndex, value);
135
+ }
136
+ public bindUSmallInt(parameterIndex: number, value: number) {
137
+ duckdb.bind_uint16(this.prepared_statement, parameterIndex, value);
138
+ }
139
+ public bindUInteger(parameterIndex: number, value: number) {
140
+ duckdb.bind_uint32(this.prepared_statement, parameterIndex, value);
141
+ }
142
+ public bindUBigInt(parameterIndex: number, value: bigint) {
143
+ duckdb.bind_uint64(this.prepared_statement, parameterIndex, value);
144
+ }
145
+ public bindUHugeInt(parameterIndex: number, value: bigint) {
146
+ duckdb.bind_uhugeint(this.prepared_statement, parameterIndex, value);
147
+ }
148
+ public bindBigNum(parameterIndex: number, value: bigint) {
149
+ this.bindValue(parameterIndex, value, BIGNUM);
150
+ }
151
+ public bindDecimal(parameterIndex: number, value: DuckDBDecimalValue) {
152
+ duckdb.bind_decimal(this.prepared_statement, parameterIndex, value);
153
+ }
154
+ public bindFloat(parameterIndex: number, value: number) {
155
+ duckdb.bind_float(this.prepared_statement, parameterIndex, value);
156
+ }
157
+ public bindDouble(parameterIndex: number, value: number) {
158
+ duckdb.bind_double(this.prepared_statement, parameterIndex, value);
159
+ }
160
+ public bindDate(parameterIndex: number, value: DuckDBDateValue) {
161
+ duckdb.bind_date(this.prepared_statement, parameterIndex, value);
162
+ }
163
+ public bindTime(parameterIndex: number, value: DuckDBTimeValue) {
164
+ duckdb.bind_time(this.prepared_statement, parameterIndex, value);
165
+ }
166
+ public bindTimeTZ(parameterIndex: number, value: DuckDBTimeTZValue) {
167
+ this.bindValue(parameterIndex, value, TIMETZ);
168
+ }
169
+ public bindTimestamp(parameterIndex: number, value: DuckDBTimestampValue) {
170
+ duckdb.bind_timestamp(this.prepared_statement, parameterIndex, value);
171
+ }
172
+ public bindTimestampTZ(
173
+ parameterIndex: number,
174
+ value: DuckDBTimestampTZValue
175
+ ) {
176
+ this.bindValue(parameterIndex, value, TIMESTAMPTZ);
177
+ }
178
+ public bindTimestampTZNanoseconds(
179
+ parameterIndex: number,
180
+ value: DuckDBTimestampTZNanosecondsValue
181
+ ) {
182
+ this.bindValue(parameterIndex, value, TIMESTAMPTZ_NS);
183
+ }
184
+ public bindTimestampSeconds(
185
+ parameterIndex: number,
186
+ value: DuckDBTimestampSecondsValue
187
+ ) {
188
+ this.bindValue(parameterIndex, value, TIMESTAMP_S);
189
+ }
190
+ public bindTimestampMilliseconds(
191
+ parameterIndex: number,
192
+ value: DuckDBTimestampMillisecondsValue
193
+ ) {
194
+ this.bindValue(parameterIndex, value, TIMESTAMP_MS);
195
+ }
196
+ public bindTimestampNanoseconds(
197
+ parameterIndex: number,
198
+ value: DuckDBTimestampNanosecondsValue
199
+ ) {
200
+ this.bindValue(parameterIndex, value, TIMESTAMP_NS);
201
+ }
202
+ public bindInterval(parameterIndex: number, value: DuckDBIntervalValue) {
203
+ duckdb.bind_interval(this.prepared_statement, parameterIndex, value);
204
+ }
205
+ public bindVarchar(parameterIndex: number, value: string) {
206
+ duckdb.bind_varchar(this.prepared_statement, parameterIndex, value);
207
+ }
208
+ public bindBlob(parameterIndex: number, value: Uint8Array) {
209
+ duckdb.bind_blob(this.prepared_statement, parameterIndex, value);
210
+ }
211
+ public bindEnum(parameterIndex: number, value: string, type: DuckDBEnumType) {
212
+ this.bindValue(parameterIndex, value, type);
213
+ }
214
+ public bindArray(
215
+ parameterIndex: number,
216
+ value: DuckDBArrayValue | readonly DuckDBValue[],
217
+ type?: DuckDBArrayType
218
+ ) {
219
+ this.bindValue(
220
+ parameterIndex,
221
+ value instanceof DuckDBArrayValue ? value : arrayValue(value),
222
+ type
223
+ );
224
+ }
225
+ public bindList(
226
+ parameterIndex: number,
227
+ value: DuckDBListValue | readonly DuckDBValue[],
228
+ type?: DuckDBListType
229
+ ) {
230
+ this.bindValue(
231
+ parameterIndex,
232
+ value instanceof DuckDBListValue ? value : listValue(value),
233
+ type
234
+ );
235
+ }
236
+ public bindStruct(
237
+ parameterIndex: number,
238
+ value: DuckDBStructValue | Readonly<Record<string, DuckDBValue>>,
239
+ type?: DuckDBStructType
240
+ ) {
241
+ this.bindValue(
242
+ parameterIndex,
243
+ value instanceof DuckDBStructValue ? value : structValue(value),
244
+ type
245
+ );
246
+ }
247
+ public bindTuple(
248
+ parameterIndex: number,
249
+ value: DuckDBTupleValue | readonly DuckDBValue[],
250
+ type?: DuckDBStructType
251
+ ) {
252
+ this.bindValue(
253
+ parameterIndex,
254
+ value instanceof DuckDBTupleValue ? value : tupleValue(value),
255
+ type
256
+ );
257
+ }
258
+ public bindMap(
259
+ parameterIndex: number,
260
+ value: DuckDBMapValue,
261
+ type?: DuckDBMapType
262
+ ) {
263
+ this.bindValue(parameterIndex, value, type);
264
+ }
265
+ public bindUnion(
266
+ parameterIndex: number,
267
+ value: DuckDBUnionValue,
268
+ type?: DuckDBUnionType
269
+ ) {
270
+ this.bindValue(parameterIndex, value, type);
271
+ }
272
+ public bindUUID(parameterIndex: number, value: DuckDBUUIDValue) {
273
+ this.bindValue(parameterIndex, value, UUID);
274
+ }
275
+ public bindBit(parameterIndex: number, value: DuckDBBitValue) {
276
+ this.bindValue(parameterIndex, value, BIT);
277
+ }
278
+ public bindVariant(
279
+ parameterIndex: number,
280
+ value: DuckDBVariantValue | null
281
+ ) {
282
+ if (value === null) {
283
+ this.bindNull(parameterIndex);
284
+ return;
285
+ }
286
+ this.bindValue(parameterIndex, value, VARIANT);
287
+ }
288
+ public bindNull(parameterIndex: number) {
289
+ duckdb.bind_null(this.prepared_statement, parameterIndex);
290
+ }
291
+ public bindValue(
292
+ parameterIndex: number,
293
+ value: DuckDBValue,
294
+ type?: DuckDBType
295
+ ) {
296
+ duckdb.bind_value(
297
+ this.prepared_statement,
298
+ parameterIndex,
299
+ createValue(type ? type : typeForValue(value), value)
300
+ );
301
+ }
302
+ public bind(
303
+ values: DuckDBValue[] | Record<string, DuckDBValue>,
304
+ types?: DuckDBType[] | Record<string, DuckDBType | undefined>
305
+ ) {
306
+ if (Array.isArray(values)) {
307
+ const typesIsArray = Array.isArray(types);
308
+ for (let i = 0; i < values.length; i++) {
309
+ this.bindValue(i + 1, values[i], typesIsArray ? types[i] : undefined);
310
+ }
311
+ } else {
312
+ const typesIsRecord = types && !Array.isArray(types);
313
+ for (const key in values) {
314
+ this.bindValue(
315
+ this.parameterIndex(key),
316
+ values[key],
317
+ typesIsRecord ? types[key] : undefined
318
+ );
319
+ }
320
+ }
321
+ }
322
+ public async run(): Promise<DuckDBMaterializedResult> {
323
+ return new DuckDBMaterializedResult(
324
+ await duckdb.execute_prepared(this.prepared_statement),
325
+ this.statementType
326
+ );
327
+ }
328
+ public async runAndRead(): Promise<DuckDBResultReader> {
329
+ return new DuckDBResultReader(await this.run());
330
+ }
331
+ public async runAndReadAll(): Promise<DuckDBResultReader> {
332
+ const reader = new DuckDBResultReader(await this.run());
333
+ await reader.readAll();
334
+ return reader;
335
+ }
336
+ public async runAndReadUntil(
337
+ targetRowCount: number
338
+ ): Promise<DuckDBResultReader> {
339
+ const reader = new DuckDBResultReader(await this.run());
340
+ await reader.readUntil(targetRowCount);
341
+ return reader;
342
+ }
343
+ public async stream(): Promise<DuckDBResult> {
344
+ return new DuckDBResult(
345
+ await duckdb.execute_prepared_streaming(this.prepared_statement),
346
+ this.statementType
347
+ );
348
+ }
349
+ public async streamAndRead(): Promise<DuckDBResultReader> {
350
+ return new DuckDBResultReader(await this.stream());
351
+ }
352
+ public async streamAndReadAll(): Promise<DuckDBResultReader> {
353
+ const reader = new DuckDBResultReader(await this.stream());
354
+ await reader.readAll();
355
+ return reader;
356
+ }
357
+ public async streamAndReadUntil(
358
+ targetRowCount: number
359
+ ): Promise<DuckDBResultReader> {
360
+ const reader = new DuckDBResultReader(await this.stream());
361
+ await reader.readUntil(targetRowCount);
362
+ return reader;
363
+ }
364
+ public start(): DuckDBPendingResult {
365
+ return new DuckDBPendingResult(
366
+ duckdb.pending_prepared(this.prepared_statement),
367
+ this.statementType
368
+ );
369
+ }
370
+ public startStream(): DuckDBPendingResult {
371
+ return new DuckDBPendingResult(
372
+ duckdb.pending_prepared_streaming(this.prepared_statement),
373
+ this.statementType
374
+ );
375
+ }
376
+ }
@@ -0,0 +1,5 @@
1
+ import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
2
+
3
+ export interface DuckDBPreparedStatementCollection {
4
+ add(prepared: DuckDBPreparedStatement): void;
5
+ }
@@ -0,0 +1,31 @@
1
+ import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
2
+ import { DuckDBPreparedStatementCollection } from './DuckDBPreparedStatementCollection';
3
+
4
+ export class DuckDBPreparedStatementWeakRefCollection
5
+ implements DuckDBPreparedStatementCollection
6
+ {
7
+ preparedStatements: WeakRef<DuckDBPreparedStatement>[] = [];
8
+ lastPruneTime: number = 0;
9
+ public add(prepared: DuckDBPreparedStatement) {
10
+ const now = performance.now();
11
+ if (now - this.lastPruneTime > 1000) {
12
+ this.lastPruneTime = now;
13
+ this.prune();
14
+ }
15
+ this.preparedStatements.push(new WeakRef(prepared));
16
+ }
17
+ public destroySync() {
18
+ for (const preparedRef of this.preparedStatements) {
19
+ const prepared = preparedRef.deref();
20
+ if (prepared) {
21
+ prepared.destroySync();
22
+ }
23
+ }
24
+ this.preparedStatements = [];
25
+ }
26
+ private prune() {
27
+ this.preparedStatements = this.preparedStatements.filter(
28
+ (ref) => !!ref.deref()
29
+ );
30
+ }
31
+ }