@flowblade/sqlduck 0.9.0 → 0.11.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 CHANGED
@@ -1,4 +1,7 @@
1
+ import * as _duckdb_node_api0 from "@duckdb/node-api";
1
2
  import { DuckDBConnection, DuckDBType } from "@duckdb/node-api";
3
+ import * as _logtape_logtape0 from "@logtape/logtape";
4
+ import { Logger } from "@logtape/logtape";
2
5
  import * as z from "zod";
3
6
  import { ZodObject } from "zod";
4
7
 
@@ -49,7 +52,7 @@ declare class DuckMemory {
49
52
  getSummary: () => Promise<DuckMemorySummary>;
50
53
  }
51
54
  //#endregion
52
- //#region src/table/table.d.ts
55
+ //#region src/objects/table.d.ts
53
56
  /**
54
57
  * Fully qualified table information
55
58
  */
@@ -99,9 +102,14 @@ declare const getTableCreateFromZod: <TSchema extends TableSchemaZod>(params: Ge
99
102
  //#region src/sql-duck.d.ts
100
103
  type SqlDuckParams = {
101
104
  conn: DuckDBConnection;
102
- logger?: (msg: string) => void;
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;
103
111
  };
104
- type RowStream<T> = AsyncIterableIterator<T>;
112
+ type RowStream<T> = AsyncIterableIterator<T> | AsyncGenerator<T> | Generator<T>;
105
113
  type ToTableParams<TSchema extends TableSchemaZod> = {
106
114
  /**
107
115
  * Used to create and fill the data into the table
@@ -193,4 +201,145 @@ declare const zodCodecs: {
193
201
  readonly bigintToString: z.ZodCodec<z.ZodBigInt, z.ZodString>;
194
202
  };
195
203
  //#endregion
196
- export { DuckMemory, DuckMemoryTag, type OnDataAppendedCb, type OnDataAppendedStats, SqlDuck, type SqlDuckParams, Table, type ToTableParams, getTableCreateFromZod, zodCodecs };
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 };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,7 @@
1
+ import * as _duckdb_node_api0 from "@duckdb/node-api";
1
2
  import { DuckDBConnection, DuckDBType } from "@duckdb/node-api";
3
+ import * as _logtape_logtape0 from "@logtape/logtape";
4
+ import { Logger } from "@logtape/logtape";
2
5
  import * as z from "zod";
3
6
  import { ZodObject } from "zod";
4
7
 
@@ -49,7 +52,7 @@ declare class DuckMemory {
49
52
  getSummary: () => Promise<DuckMemorySummary>;
50
53
  }
51
54
  //#endregion
52
- //#region src/table/table.d.ts
55
+ //#region src/objects/table.d.ts
53
56
  /**
54
57
  * Fully qualified table information
55
58
  */
@@ -99,9 +102,14 @@ declare const getTableCreateFromZod: <TSchema extends TableSchemaZod>(params: Ge
99
102
  //#region src/sql-duck.d.ts
100
103
  type SqlDuckParams = {
101
104
  conn: DuckDBConnection;
102
- logger?: (msg: string) => void;
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;
103
111
  };
104
- type RowStream<T> = AsyncIterableIterator<T>;
112
+ type RowStream<T> = AsyncIterableIterator<T> | AsyncGenerator<T> | Generator<T>;
105
113
  type ToTableParams<TSchema extends TableSchemaZod> = {
106
114
  /**
107
115
  * Used to create and fill the data into the table
@@ -193,4 +201,145 @@ declare const zodCodecs: {
193
201
  readonly bigintToString: z.ZodCodec<z.ZodBigInt, z.ZodString>;
194
202
  };
195
203
  //#endregion
196
- export { DuckMemory, type DuckMemoryTag, type OnDataAppendedCb, type OnDataAppendedStats, SqlDuck, type SqlDuckParams, Table, type ToTableParams, getTableCreateFromZod, zodCodecs };
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, type DuckMemoryTag, type DuckdbReservedKeywords, type OnDataAppendedCb, type OnDataAppendedStats, SqlDuck, type SqlDuckParams, Table, type ToTableParams, duckDatabaseManagerDbParamsSchema, duckTableAliasSchema, duckTableNameSchema, duckdbReservedKeywords, flowbladeLogtapeSqlduckConfig, getTableCreateFromZod, sqlduckDefaultLogtapeLogger, zodCodecs };