@flowblade/sqlduck 0.12.0 → 0.13.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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as duckValidatorsZod, l as duckReservedKeywords, r as assertValidAliasName, s as duckConnectionParamsZodSchema } from "./zod-DcIc8xQC.mjs";
|
|
2
2
|
import { BIGINT, BOOLEAN, DOUBLE, DuckDBDataChunk, DuckDBTimestampValue, FLOAT, HUGEINT, INTEGER, SMALLINT, TIMESTAMP, TINYINT, UBIGINT, UHUGEINT, UINTEGER, USMALLINT, UTINYINT, UUID, VARCHAR } from "@duckdb/node-api";
|
|
3
3
|
import { getLogger } from "@logtape/logtape";
|
|
4
4
|
import * as z from "zod";
|
|
@@ -516,6 +516,8 @@ var SqlDuck = class {
|
|
|
516
516
|
toTable = async (params) => {
|
|
517
517
|
const { table, schema, chunkSize = 2048, rowStream, createOptions, onDataAppended, autoCheckpoint = true } = params;
|
|
518
518
|
if (!Number.isSafeInteger(chunkSize) || chunkSize < 1 || chunkSize > 2048) throw new Error("chunkSize must be a number between 1 and 2048");
|
|
519
|
+
if (autoCheckpoint && typeof table.databaseName !== "string") throw new Error("autoCheckpoint requires table.databaseName to be provided.");
|
|
520
|
+
const dbManager = new DuckDatabaseManager(this.#conn);
|
|
519
521
|
const timeStart = Date.now();
|
|
520
522
|
const { columnTypes, ddl } = await createTableFromZod({
|
|
521
523
|
conn: this.#conn,
|
|
@@ -544,16 +546,18 @@ var SqlDuck = class {
|
|
|
544
546
|
if (isOnDataAppendedAsyncCb(onDataAppended)) await onDataAppended(payload);
|
|
545
547
|
else onDataAppended(payload);
|
|
546
548
|
}
|
|
547
|
-
|
|
548
|
-
appender.closeSync();
|
|
549
|
-
if (autoCheckpoint && typeof table.databaseName === "string") {
|
|
550
|
-
const dbManager = new DuckDatabaseManager(this.#conn);
|
|
551
|
-
try {
|
|
549
|
+
if (autoCheckpoint && typeof table.databaseName === "string") try {
|
|
552
550
|
await dbManager.checkpoint(table.databaseName);
|
|
553
551
|
} catch (e) {
|
|
554
|
-
this.#logger.warning(`Failed to checkpoint database '${table.databaseName}' after appending
|
|
552
|
+
this.#logger.warning(`Failed to checkpoint database '${table.databaseName}' after appending chunk into table '${table.getFullName()}' - ${e?.message ?? ""}`, { table: table.getFullName() });
|
|
555
553
|
}
|
|
556
554
|
}
|
|
555
|
+
appender.closeSync();
|
|
556
|
+
if (autoCheckpoint && typeof table.databaseName === "string") try {
|
|
557
|
+
await dbManager.checkpoint(table.databaseName);
|
|
558
|
+
} catch (e) {
|
|
559
|
+
this.#logger.warning(`Failed to checkpoint database '${table.databaseName}' after appending data into table '${table.getFullName()}' - ${e?.message ?? ""}`, { table: table.getFullName() });
|
|
560
|
+
}
|
|
557
561
|
const timeMs = Math.round(Date.now() - timeStart);
|
|
558
562
|
this.#logger.info(`Successfully appended ${totalRows} rows into '${table.getFullName()}' in ${timeMs}ms`, {
|
|
559
563
|
table: table.getFullName(),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as assertValidTableName, c as duckValidatorsZod, i as assertValidSchemaName, n as parseDuckDSNZod, o as duckAllConnectionOptionsZodSchema, r as assertValidAliasName, s as duckConnectionParamsZodSchema, t as isParsableDuckDsnZod } from "../../zod-DcIc8xQC.mjs";
|
|
2
2
|
export { assertValidAliasName, assertValidSchemaName, assertValidTableName, duckAllConnectionOptionsZodSchema, duckConnectionParamsZodSchema, duckValidatorsZod, isParsableDuckDsnZod, parseDuckDSNZod };
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
import { parseDsn } from "@httpx/dsn-parser";
|
|
3
|
-
//#region src/validation/core/create-assert-error.ts
|
|
4
|
-
const createAssertError = (msgOrErrorFactory, fallbackMsg) => {
|
|
5
|
-
if (typeof msgOrErrorFactory === "string" || msgOrErrorFactory === void 0) return new TypeError(msgOrErrorFactory ?? fallbackMsg ?? "Assertion did not pass.");
|
|
6
|
-
return msgOrErrorFactory();
|
|
7
|
-
};
|
|
8
|
-
//#endregion
|
|
9
3
|
//#region src/validation/core/base-validators.ts
|
|
10
4
|
const duckIdentifierNameRegex = /^[a-z_]\w*$/i;
|
|
11
5
|
const duckStorageVersionRegexp = /^v?\d{1,4}\.\d{1,4}\.\d{1,4}$/;
|
|
@@ -139,20 +133,6 @@ const duckValidatorsZod = {
|
|
|
139
133
|
tableName: duckIdentifierZodSchema
|
|
140
134
|
};
|
|
141
135
|
//#endregion
|
|
142
|
-
//#region src/validation/zod/duck-asserts-zod.ts
|
|
143
|
-
function assertValidAliasName(aliasName) {
|
|
144
|
-
const parsed = z.safeParse(duckValidatorsZod.aliasName, aliasName);
|
|
145
|
-
if (parsed.error) throw createAssertError(`'${aliasName}' is not a valid alias name: ${parsed.error.message}`);
|
|
146
|
-
}
|
|
147
|
-
function assertValidSchemaName(schemaName) {
|
|
148
|
-
const parsed = z.safeParse(duckValidatorsZod.schemaName, schemaName);
|
|
149
|
-
if (parsed.error) throw createAssertError(`'${schemaName}' is not a valid schema name: ${parsed.error.message}`);
|
|
150
|
-
}
|
|
151
|
-
function assertValidTableName(tableName) {
|
|
152
|
-
const parsed = z.safeParse(duckValidatorsZod.tableName, tableName);
|
|
153
|
-
if (parsed.error) throw createAssertError(`'${tableName}' is not a valid table name: ${parsed.error.message}`);
|
|
154
|
-
}
|
|
155
|
-
//#endregion
|
|
156
136
|
//#region src/validation/zod/duck-connection-params-zod-schema.ts
|
|
157
137
|
const duckAllConnectionOptionsZodSchema = z.strictObject({
|
|
158
138
|
accessMode: z.optional(z.enum(["READ_ONLY", "READ_WRITE"])),
|
|
@@ -179,6 +159,26 @@ const duckConnectionParamsZodSchema = z.discriminatedUnion("type", [z.strictObje
|
|
|
179
159
|
options: z.optional(duckAllConnectionOptionsZodSchema)
|
|
180
160
|
})]);
|
|
181
161
|
//#endregion
|
|
162
|
+
//#region src/validation/core/create-assert-error.ts
|
|
163
|
+
const createAssertError = (msgOrErrorFactory, fallbackMsg) => {
|
|
164
|
+
if (typeof msgOrErrorFactory === "string" || msgOrErrorFactory === void 0) return new TypeError(msgOrErrorFactory ?? fallbackMsg ?? "Assertion did not pass.");
|
|
165
|
+
return msgOrErrorFactory();
|
|
166
|
+
};
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/validation/zod/duck-asserts-zod.ts
|
|
169
|
+
function assertValidAliasName(aliasName) {
|
|
170
|
+
const parsed = z.safeParse(duckValidatorsZod.aliasName, aliasName);
|
|
171
|
+
if (parsed.error) throw createAssertError(`'${aliasName}' is not a valid alias name: ${parsed.error.message}`);
|
|
172
|
+
}
|
|
173
|
+
function assertValidSchemaName(schemaName) {
|
|
174
|
+
const parsed = z.safeParse(duckValidatorsZod.schemaName, schemaName);
|
|
175
|
+
if (parsed.error) throw createAssertError(`'${schemaName}' is not a valid schema name: ${parsed.error.message}`);
|
|
176
|
+
}
|
|
177
|
+
function assertValidTableName(tableName) {
|
|
178
|
+
const parsed = z.safeParse(duckValidatorsZod.tableName, tableName);
|
|
179
|
+
if (parsed.error) throw createAssertError(`'${tableName}' is not a valid table name: ${parsed.error.message}`);
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
182
|
//#region src/validation/zod/parse-duck-dsn-zod.ts
|
|
183
183
|
const parseDuckDSNZod = (dsn) => {
|
|
184
184
|
const result = parseDsn(dsn);
|
|
@@ -204,4 +204,4 @@ const isParsableDuckDsnZod = (dsn) => {
|
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
206
|
//#endregion
|
|
207
|
-
export {
|
|
207
|
+
export { assertValidTableName as a, duckValidatorsZod as c, assertValidSchemaName as i, duckReservedKeywords as l, parseDuckDSNZod as n, duckAllConnectionOptionsZodSchema as o, assertValidAliasName as r, duckConnectionParamsZodSchema as s, isParsableDuckDsnZod as t };
|