@flowblade/sqlduck 0.11.0 → 0.12.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.
package/dist/index.d.cts DELETED
@@ -1,345 +0,0 @@
1
- import * as _duckdb_node_api0 from "@duckdb/node-api";
2
- import { DuckDBConnection, DuckDBType } from "@duckdb/node-api";
3
- import * as _logtape_logtape0 from "@logtape/logtape";
4
- import { Logger } from "@logtape/logtape";
5
- import * as z from "zod";
6
- import { ZodObject } from "zod";
7
-
8
- //#region src/appender/data-appender-callback.d.ts
9
- type OnDataAppendedStats = {
10
- /**
11
- * Total number of rows appended so far (all batches included)
12
- */
13
- totalRows: number;
14
- /**
15
- * Time taken to append the last batch in milliseconds
16
- */
17
- timeMs: number;
18
- /**
19
- * Estimated rows per seconds based on the current batch
20
- */
21
- rowsPerSecond: number;
22
- };
23
- type OnDataAppendedSyncCb = (stats: OnDataAppendedStats) => void;
24
- type OnDataAppendedAsyncCb = (stats: OnDataAppendedStats) => Promise<void>;
25
- type OnDataAppendedCb = OnDataAppendedSyncCb | OnDataAppendedAsyncCb;
26
- //#endregion
27
- //#region src/helpers/duck-memory.d.ts
28
- declare const duckMemoryTags: readonly ["BASE_TABLE", "HASH_TABLE", "PARQUET_READER", "CSV_READER", "ORDER_BY", "ART_INDEX", "COLUMN_DATA", "METADATA", "OVERFLOW_STRINGS", "IN_MEMORY_TABLE", "ALLOCATOR", "EXTENSION", "TRANSACTION", "EXTERNAL_FILE_CACHE", "WINDOW", "OBJECT_CACHE"];
29
- type DuckMemoryTag = (typeof duckMemoryTags)[number];
30
- type DuckMemoryRow = {
31
- tag: DuckMemoryTag;
32
- memory_usage_bytes: bigint;
33
- temporary_storage_bytes: bigint;
34
- };
35
- declare const orderByParams: {
36
- memory_usage_bytes_desc: string;
37
- tag_desc: string;
38
- tag_asc: string;
39
- };
40
- type OrderByParams = keyof typeof orderByParams;
41
- type DuckMemorySummary = {
42
- totalMB: number;
43
- totalTempMB: number;
44
- };
45
- declare class DuckMemory {
46
- #private;
47
- constructor(duckdbConn: DuckDBConnection);
48
- getAll: (params?: {
49
- orderBy?: OrderByParams;
50
- }) => Promise<DuckMemoryRow[]>;
51
- getByTag: (tag: DuckMemoryTag) => Promise<DuckMemoryRow | null>;
52
- getSummary: () => Promise<DuckMemorySummary>;
53
- }
54
- //#endregion
55
- //#region src/objects/table.d.ts
56
- /**
57
- * Fully qualified table information
58
- */
59
- type FQTable = {
60
- name: string;
61
- schema?: string;
62
- database?: string;
63
- };
64
- declare class Table {
65
- #private;
66
- get tableName(): string;
67
- get schemaName(): string | undefined;
68
- get databaseName(): string | undefined;
69
- constructor(fqTableOrName: FQTable | string);
70
- /**
71
- * Return fully qualified table name by concatenating
72
- * database, schema and table with a 'dot' separator.
73
- */
74
- getFullName: (options?: {
75
- defaultDatabase?: string;
76
- defaultSchema?: string;
77
- }) => string;
78
- withDatabase: (database: string) => Table;
79
- withSchema: (schema: string) => Table;
80
- }
81
- //#endregion
82
- //#region src/table/table-schema-zod.type.d.ts
83
- type ZodSchemaSupportedTypes = z.ZodString | z.ZodNumber | z.ZodInt | z.ZodInt32 | z.ZodUInt32 | z.ZodBigInt | z.ZodBoolean | z.ZodDate | z.ZodISODateTime | z.ZodISOTime | z.ZodISODate | z.ZodEmail | z.ZodURL | z.ZodUUID | z.ZodCUID | z.ZodCUID2 | z.ZodULID;
84
- type TableSchemaZod = z.ZodObject<Record<string, ZodSchemaSupportedTypes | z.ZodNullable<ZodSchemaSupportedTypes> | z.ZodCodec | z.ZodNullable<z.ZodCodec>>>;
85
- //#endregion
86
- //#region src/table/get-table-create-from-zod.d.ts
87
- type TableCreateOptions = {
88
- create?: 'CREATE' | 'CREATE_OR_REPLACE' | 'IF_NOT_EXISTS';
89
- };
90
- type DuckdbColumnTypeMap<TKeys extends string> = Map<TKeys, DuckDBType>;
91
- type TableCreateFromZodResult<TSchema extends TableSchemaZod> = {
92
- ddl: string;
93
- columnTypes: DuckdbColumnTypeMap<Exclude<keyof TSchema['shape'], symbol | number>>;
94
- };
95
- type GetTableCreateFromZodParams<TSchema extends TableSchemaZod> = {
96
- table: Table;
97
- schema: TSchema;
98
- options?: TableCreateOptions;
99
- };
100
- declare const getTableCreateFromZod: <TSchema extends TableSchemaZod>(params: GetTableCreateFromZodParams<TSchema>) => TableCreateFromZodResult<TSchema>;
101
- //#endregion
102
- //#region src/sql-duck.d.ts
103
- type SqlDuckParams = {
104
- conn: DuckDBConnection;
105
- /**
106
- * Optional logtape/logger to use for logging.
107
- * If not provided, a default logger will be used.
108
- * @see {@link https://github.com/logtape/logtape}
109
- */
110
- logger?: Logger;
111
- };
112
- type RowStream<T> = AsyncIterableIterator<T> | AsyncGenerator<T> | Generator<T>;
113
- type ToTableParams<TSchema extends TableSchemaZod> = {
114
- /**
115
- * Used to create and fill the data into the table
116
- */
117
- table: Table;
118
- /**
119
- * Schema describing the table structure and rowStream content
120
- */
121
- schema: TSchema;
122
- /**
123
- * Stream of rows to insert into the table
124
- */
125
- rowStream: RowStream<z.infer<TSchema>>;
126
- /**
127
- * Chunk size when using appender to insert data.
128
- * Valid numbers between 1 and 2048.
129
- * @default 2048
130
- */
131
- chunkSize?: number;
132
- /**
133
- * Extra options when creating the table
134
- */
135
- createOptions?: TableCreateOptions;
136
- /**
137
- * Callback called each time a datachunk is appended to the table
138
- */
139
- onDataAppended?: OnDataAppendedCb;
140
- };
141
- type ToTableResult = {
142
- /**
143
- * Total time taken to insert the data in milliseconds.
144
- */
145
- timeMs: number;
146
- /**
147
- * Total number of rows inserted into the table.
148
- */
149
- totalRows: number;
150
- /**
151
- * The DDL statement used to create the table.
152
- */
153
- createTableDDL: string;
154
- };
155
- declare class SqlDuck {
156
- #private;
157
- constructor(params: SqlDuckParams);
158
- /**
159
- * Create a table from a Zod schema and fill it with data from a row stream.
160
- *
161
- * @example
162
- * ```typescript
163
- * import * as z from 'zod';
164
- *
165
- * const sqlDuck = new SqlDuck({ conn: duckDbConnection });
166
- *
167
- * // Schema of the table, not that you can use meta to add information
168
- * const userSchema = z.object({
169
- * id: z.number().int().meta({ primaryKey: true }),
170
- * name: z.string(),
171
- * });
172
- *
173
- * // Async generator function that yields rows to insert
174
- * async function* getUserRows(): AsyncIterableIterator<z.infer<typeof userSchema>> {
175
- * // database or api call
176
- * }
177
- *
178
- * const result = sqlDuck.toTable({
179
- * table: new Table({ name: 'user', database: 'mydb' }),
180
- * schema: userSchema,
181
- * rowStream: getUserRows(),
182
- * chunkSize: 2048,
183
- * onDataAppended: ({ total }) => {
184
- * console.log(`Appended ${total} rows so far`);
185
- * },
186
- * createOptions: {
187
- * create: 'CREATE_OR_REPLACE',
188
- * },
189
- * });
190
- *
191
- * console.log(`Inserted ${result.totalRows} rows in ${result.timeMs}ms`);
192
- * console.log(`Table created with DDL: ${result.createTableDDL}`);
193
- * ```
194
- */
195
- toTable: <TSchema extends ZodObject>(params: ToTableParams<TSchema>) => Promise<ToTableResult>;
196
- }
197
- //#endregion
198
- //#region src/utils/zod-codecs.d.ts
199
- declare const zodCodecs: {
200
- readonly dateToString: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
201
- readonly bigintToString: z.ZodCodec<z.ZodBigInt, z.ZodString>;
202
- };
203
- //#endregion
204
- //#region src/objects/database.d.ts
205
- type DatabaseProperties = {
206
- alias: string;
207
- };
208
- declare class Database {
209
- #private;
210
- get alias(): string;
211
- constructor(params: DatabaseProperties);
212
- toJson(): {
213
- type: string;
214
- params: {
215
- alias: string;
216
- };
217
- };
218
- [Symbol.toStringTag](): string;
219
- }
220
- //#endregion
221
- //#region src/manager/database/duck-database-manager.schemas.d.ts
222
- declare const duckDatabaseManagerDbParamsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
223
- type: z.ZodLiteral<":memory:">;
224
- alias: z.ZodString;
225
- options: z.ZodOptional<z.ZodObject<{
226
- ACCESS_MODE: z.ZodOptional<z.ZodEnum<{
227
- READ_ONLY: "READ_ONLY";
228
- READ_WRITE: "READ_WRITE";
229
- AUTOMATIC: "AUTOMATIC";
230
- }>>;
231
- COMPRESS: z.ZodOptional<z.ZodEnum<{
232
- true: "true";
233
- false: "false";
234
- }>>;
235
- TYPE: z.ZodOptional<z.ZodEnum<{
236
- DUCKDB: "DUCKDB";
237
- SQLITE: "SQLITE";
238
- }>>;
239
- BLOCK_SIZE: z.ZodOptional<z.ZodInt32>;
240
- ROW_GROUP_SIZE: z.ZodOptional<z.ZodInt32>;
241
- STORAGE_VERSION: z.ZodOptional<z.ZodString>;
242
- ENCRYPTION_KEY: z.ZodOptional<z.ZodString>;
243
- ENCRYPTION_CIPHER: z.ZodOptional<z.ZodEnum<{
244
- CBC: "CBC";
245
- CTR: "CTR";
246
- GCM: "GCM";
247
- }>>;
248
- }, z.core.$strict>>;
249
- }, z.core.$strict>, z.ZodObject<{
250
- type: z.ZodLiteral<"duckdb">;
251
- path: z.ZodString;
252
- alias: z.ZodString;
253
- options: z.ZodOptional<z.ZodObject<{
254
- ACCESS_MODE: z.ZodOptional<z.ZodEnum<{
255
- READ_ONLY: "READ_ONLY";
256
- READ_WRITE: "READ_WRITE";
257
- AUTOMATIC: "AUTOMATIC";
258
- }>>;
259
- COMPRESS: z.ZodOptional<z.ZodEnum<{
260
- true: "true";
261
- false: "false";
262
- }>>;
263
- TYPE: z.ZodOptional<z.ZodEnum<{
264
- DUCKDB: "DUCKDB";
265
- SQLITE: "SQLITE";
266
- }>>;
267
- BLOCK_SIZE: z.ZodOptional<z.ZodInt32>;
268
- ROW_GROUP_SIZE: z.ZodOptional<z.ZodInt32>;
269
- STORAGE_VERSION: z.ZodOptional<z.ZodString>;
270
- ENCRYPTION_KEY: z.ZodOptional<z.ZodString>;
271
- ENCRYPTION_CIPHER: z.ZodOptional<z.ZodEnum<{
272
- CBC: "CBC";
273
- CTR: "CTR";
274
- GCM: "GCM";
275
- }>>;
276
- }, z.core.$strict>>;
277
- }, z.core.$strict>], "type">;
278
- type DuckDatabaseManagerDbParams = z.infer<typeof duckDatabaseManagerDbParamsSchema>;
279
- //#endregion
280
- //#region src/manager/database/commands/duck-database-attach-command.d.ts
281
- type Behaviour = 'OR REPLACE' | 'IF NOT EXISTS';
282
- type DuckDatabaseAttachCommandOptions = {
283
- behaviour?: Behaviour;
284
- };
285
- //#endregion
286
- //#region src/manager/database/duck-database-manager.d.ts
287
- declare class DuckDatabaseManager {
288
- #private;
289
- constructor(conn: DuckDBConnection, params?: {
290
- logger?: Logger;
291
- });
292
- /**
293
- * Attach a database to the current connection
294
- *
295
- * @example
296
- * ```typescript
297
- * const dbManager = new DuckDatabaseManager(conn);
298
- * const database = dbManager.attach({
299
- * type: ':memory:', // can be 'duckdb', 's3'...
300
- * alias: 'mydb',
301
- * options: { COMPRESS: 'true' }
302
- * });
303
- *
304
- * console.log(database.alias); // 'mydb'
305
- * ```
306
- */
307
- attach: (dbParams: DuckDatabaseManagerDbParams, options?: DuckDatabaseAttachCommandOptions) => Promise<Database>;
308
- attachOrReplace: (dbParams: DuckDatabaseManagerDbParams) => Promise<Database>;
309
- attachIfNotExists: (dbParams: DuckDatabaseManagerDbParams) => Promise<Database>;
310
- showDatabases: () => Promise<Record<string, _duckdb_node_api0.JS>[]>;
311
- detach: (dbAlias: string) => Promise<boolean>;
312
- detachIfExists: (dbAlias: string) => Promise<boolean>;
313
- /**
314
- * The statistics recomputed by the ANALYZE statement are only used for join order optimization.
315
- *
316
- * It is therefore recommended to recompute these statistics for improved join orders,
317
- * especially after performing large updates (inserts and/or deletes).
318
- *
319
- * @link https://duckdb.org/docs/stable/sql/statements/analyze
320
- */
321
- analyze: () => Promise<boolean>;
322
- checkpoint: (dbAlias: string) => Promise<boolean>;
323
- }
324
- //#endregion
325
- //#region src/validation/core/duckdb-reserved-keywords.d.ts
326
- /**
327
- * DuckDB reserved keywords that cannot be used as unquoted identifiers.
328
- * @see https://duckdb.org/docs/sql/keywords-and-identifiers.html
329
- */
330
- declare const duckdbReservedKeywords: readonly ["ALL", "ANALYSE", "ANALYZE", "AND", "ANY", "ARRAY", "AS", "ASC", "ASYMMETRIC", "BOTH", "CASE", "CAST", "CHECK", "COLLATE", "COLUMN", "CONSTRAINT", "CREATE", "CROSS", "CURRENT_CATALOG", "CURRENT_DATE", "CURRENT_ROLE", "CURRENT_SCHEMA", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "DEFAULT", "DEFERRABLE", "DESC", "DISTINCT", "DO", "ELSE", "END", "EXCEPT", "EXISTS", "EXTRACT", "FALSE", "FETCH", "FOR", "FOREIGN", "FROM", "GRANT", "GROUP", "HAVING", "IF", "ILIKE", "IN", "INITIALLY", "INNER", "INTERSECT", "INTO", "IS", "ISNULL", "JOIN", "LATERAL", "LEADING", "LEFT", "LIKE", "LIMIT", "LOCALTIME", "LOCALTIMESTAMP", "NATURAL", "NOT", "NOTNULL", "NULL", "OFFSET", "ON", "ONLY", "OR", "ORDER", "OUTER", "OVERLAPS", "PLACING", "PRIMARY", "REFERENCES", "RETURNING", "RIGHT", "ROW", "SELECT", "SESSION_USER", "SIMILAR", "SOME", "SYMMETRIC", "TABLE", "THEN", "TO", "TRAILING", "TRUE", "UNION", "UNIQUE", "USING", "VARIADIC", "VERBOSE", "WHEN", "WHERE", "WINDOW", "WITH"];
331
- type DuckdbReservedKeywords = (typeof duckdbReservedKeywords)[number];
332
- //#endregion
333
- //#region src/validation/zod/duckdb-valid-names.schemas.d.ts
334
- declare const duckTableNameSchema: z.ZodString;
335
- declare const duckTableAliasSchema: z.ZodString;
336
- //#endregion
337
- //#region src/config/flowblade-logtape-sqlduck.config.d.ts
338
- declare const flowbladeLogtapeSqlduckConfig: {
339
- categories: string[];
340
- };
341
- //#endregion
342
- //#region src/logger/sqlduck-default-logtape-logger.d.ts
343
- declare const sqlduckDefaultLogtapeLogger: _logtape_logtape0.Logger;
344
- //#endregion
345
- export { Database, DuckDatabaseManager, type DuckDatabaseManagerDbParams, DuckMemory, DuckMemoryTag, type DuckdbReservedKeywords, type OnDataAppendedCb, type OnDataAppendedStats, SqlDuck, type SqlDuckParams, Table, type ToTableParams, duckDatabaseManagerDbParamsSchema, duckTableAliasSchema, duckTableNameSchema, duckdbReservedKeywords, flowbladeLogtapeSqlduckConfig, getTableCreateFromZod, sqlduckDefaultLogtapeLogger, zodCodecs };