@flowblade/sqlduck 0.0.1 → 0.0.4

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.cjs CHANGED
@@ -50,7 +50,13 @@ async function* rowsToColumnsChunks(rows, chunkSize) {
50
50
  }
51
51
  if (rowsInChunk > 0) yield columns;
52
52
  }
53
- const getTableCreateFromZod = (table, schema) => {
53
+ const createMap = {
54
+ CREATE: "CREATE TABLE",
55
+ CREATE_OR_REPLACE: "CREATE OR REPLACE TABLE",
56
+ IF_NOT_EXISTS: "CREATE TABLE IF NOT EXISTS"
57
+ };
58
+ const getTableCreateFromZod = (table, schema, options) => {
59
+ const { create = "CREATE" } = options ?? {};
54
60
  const fqTable = table.getFullyQualifiedTableName();
55
61
  const json = schema.toJSONSchema({ target: "openapi-3.0" });
56
62
  const columns = [];
@@ -83,7 +89,7 @@ const getTableCreateFromZod = (table, schema) => {
83
89
  }
84
90
  return {
85
91
  ddl: [
86
- `CREATE OR REPLACE TABLE ${fqTable} (\n`,
92
+ `${createMap[create]} ${fqTable} (\n`,
87
93
  columns.map((colDDL) => {
88
94
  const { name, duckdbType, constraint } = colDDL;
89
95
  return ` ${[
@@ -98,8 +104,8 @@ const getTableCreateFromZod = (table, schema) => {
98
104
  };
99
105
  };
100
106
  const createTableFromZod = async (params) => {
101
- const { conn, table, schema } = params;
102
- const { ddl, columnTypes } = getTableCreateFromZod(table, schema);
107
+ const { conn, table, schema, options } = params;
108
+ const { ddl, columnTypes } = getTableCreateFromZod(table, schema, options);
103
109
  try {
104
110
  await conn.run(ddl);
105
111
  } catch (e) {
@@ -118,11 +124,12 @@ var SqlDuck = class {
118
124
  this.#logger = params.logger;
119
125
  }
120
126
  toTable = async (params) => {
121
- const { table, schema, chunkSize, rowStream } = params;
127
+ const { table, schema, chunkSize, rowStream, createOptions } = params;
122
128
  const { columnTypes } = await createTableFromZod({
123
129
  conn: this.#duck,
124
130
  schema,
125
- table
131
+ table,
132
+ options: createOptions
126
133
  });
127
134
  const appender = await this.#duck.createAppender(table.fqTable.name, table.fqTable.schema, table.fqTable.database);
128
135
  const chunkTypes = columnTypes.map((v) => v[1]);
package/dist/index.d.cts CHANGED
@@ -27,6 +27,15 @@ declare class Table {
27
27
  withSchema: (schema: string) => Table;
28
28
  }
29
29
  //#endregion
30
+ //#region src/table/get-table-create-from-zod.d.ts
31
+ type TableCreateOptions = {
32
+ create?: 'CREATE' | 'CREATE_OR_REPLACE' | 'IF_NOT_EXISTS';
33
+ };
34
+ declare const getTableCreateFromZod: <T extends ZodObject>(table: Table, schema: T, options?: TableCreateOptions) => {
35
+ ddl: string;
36
+ columnTypes: [name: string, type: DuckDBType][];
37
+ };
38
+ //#endregion
30
39
  //#region src/table/table-schema-zod.type.d.ts
31
40
  type TableSchemaZod = ZodObject;
32
41
  //#endregion
@@ -40,6 +49,7 @@ type ToTableParams<TSchema extends TableSchemaZod> = {
40
49
  schema: TSchema;
41
50
  rowStream: AsyncIterableIterator<z.infer<TSchema>>;
42
51
  chunkSize?: number;
52
+ createOptions?: TableCreateOptions;
43
53
  };
44
54
  declare class SqlDuck {
45
55
  #private;
@@ -47,12 +57,6 @@ declare class SqlDuck {
47
57
  toTable: <TSchema extends ZodObject>(params: ToTableParams<TSchema>) => Promise<undefined>;
48
58
  }
49
59
  //#endregion
50
- //#region src/table/get-table-create-from-zod.d.ts
51
- declare const getTableCreateFromZod: <T extends ZodObject>(table: Table, schema: T) => {
52
- ddl: string;
53
- columnTypes: [name: string, type: DuckDBType][];
54
- };
55
- //#endregion
56
60
  //#region src/utils/zod-codecs.d.ts
57
61
  declare const zodCodecs: {
58
62
  readonly dateToString: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
package/dist/index.d.mts CHANGED
@@ -27,6 +27,15 @@ declare class Table {
27
27
  withSchema: (schema: string) => Table;
28
28
  }
29
29
  //#endregion
30
+ //#region src/table/get-table-create-from-zod.d.ts
31
+ type TableCreateOptions = {
32
+ create?: 'CREATE' | 'CREATE_OR_REPLACE' | 'IF_NOT_EXISTS';
33
+ };
34
+ declare const getTableCreateFromZod: <T extends ZodObject>(table: Table, schema: T, options?: TableCreateOptions) => {
35
+ ddl: string;
36
+ columnTypes: [name: string, type: DuckDBType][];
37
+ };
38
+ //#endregion
30
39
  //#region src/table/table-schema-zod.type.d.ts
31
40
  type TableSchemaZod = ZodObject;
32
41
  //#endregion
@@ -40,6 +49,7 @@ type ToTableParams<TSchema extends TableSchemaZod> = {
40
49
  schema: TSchema;
41
50
  rowStream: AsyncIterableIterator<z.infer<TSchema>>;
42
51
  chunkSize?: number;
52
+ createOptions?: TableCreateOptions;
43
53
  };
44
54
  declare class SqlDuck {
45
55
  #private;
@@ -47,12 +57,6 @@ declare class SqlDuck {
47
57
  toTable: <TSchema extends ZodObject>(params: ToTableParams<TSchema>) => Promise<undefined>;
48
58
  }
49
59
  //#endregion
50
- //#region src/table/get-table-create-from-zod.d.ts
51
- declare const getTableCreateFromZod: <T extends ZodObject>(table: Table, schema: T) => {
52
- ddl: string;
53
- columnTypes: [name: string, type: DuckDBType][];
54
- };
55
- //#endregion
56
60
  //#region src/utils/zod-codecs.d.ts
57
61
  declare const zodCodecs: {
58
62
  readonly dateToString: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
package/dist/index.mjs CHANGED
@@ -29,7 +29,13 @@ async function* rowsToColumnsChunks(rows, chunkSize) {
29
29
  }
30
30
  if (rowsInChunk > 0) yield columns;
31
31
  }
32
- const getTableCreateFromZod = (table, schema) => {
32
+ const createMap = {
33
+ CREATE: "CREATE TABLE",
34
+ CREATE_OR_REPLACE: "CREATE OR REPLACE TABLE",
35
+ IF_NOT_EXISTS: "CREATE TABLE IF NOT EXISTS"
36
+ };
37
+ const getTableCreateFromZod = (table, schema, options) => {
38
+ const { create = "CREATE" } = options ?? {};
33
39
  const fqTable = table.getFullyQualifiedTableName();
34
40
  const json = schema.toJSONSchema({ target: "openapi-3.0" });
35
41
  const columns = [];
@@ -62,7 +68,7 @@ const getTableCreateFromZod = (table, schema) => {
62
68
  }
63
69
  return {
64
70
  ddl: [
65
- `CREATE OR REPLACE TABLE ${fqTable} (\n`,
71
+ `${createMap[create]} ${fqTable} (\n`,
66
72
  columns.map((colDDL) => {
67
73
  const { name, duckdbType, constraint } = colDDL;
68
74
  return ` ${[
@@ -77,8 +83,8 @@ const getTableCreateFromZod = (table, schema) => {
77
83
  };
78
84
  };
79
85
  const createTableFromZod = async (params) => {
80
- const { conn, table, schema } = params;
81
- const { ddl, columnTypes } = getTableCreateFromZod(table, schema);
86
+ const { conn, table, schema, options } = params;
87
+ const { ddl, columnTypes } = getTableCreateFromZod(table, schema, options);
82
88
  try {
83
89
  await conn.run(ddl);
84
90
  } catch (e) {
@@ -97,11 +103,12 @@ var SqlDuck = class {
97
103
  this.#logger = params.logger;
98
104
  }
99
105
  toTable = async (params) => {
100
- const { table, schema, chunkSize, rowStream } = params;
106
+ const { table, schema, chunkSize, rowStream, createOptions } = params;
101
107
  const { columnTypes } = await createTableFromZod({
102
108
  conn: this.#duck,
103
109
  schema,
104
- table
110
+ table,
111
+ options: createOptions
105
112
  });
106
113
  const appender = await this.#duck.createAppender(table.fqTable.name, table.fqTable.schema, table.fqTable.database);
107
114
  const chunkTypes = columnTypes.map((v) => v[1]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowblade/sqlduck",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -33,8 +33,10 @@
33
33
  "build-release": "yarn build && rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
34
34
  "test": "vitest run",
35
35
  "test-unit": "vitest run",
36
+ "test-unit-bun": "bun --bun run vitest run",
36
37
  "test-unit-watch": "vitest --ui",
37
38
  "test-e2e": "vitest -c vitest.e2e.config.ts run",
39
+ "test-e2e-bun": "bun --bun run vitest -c vitest.e2e.config.ts run",
38
40
  "test-e2e-watch": "vitest -c vitest.e2e.config.ts --ui",
39
41
  "typecheck": "tsc --project tsconfig.json --noEmit",
40
42
  "lint": "eslint . --ext .ts,.tsx,.js,.jsx,.mjs,.cjs,.mts,.cts --cache --cache-location ../../../.cache/eslint/sqlduck.eslintcache",
@@ -44,9 +46,9 @@
44
46
  "check-size": "size-limit"
45
47
  },
46
48
  "dependencies": {
47
- "@flowblade/core": "workspace:^",
48
- "@flowblade/source-duckdb": "workspace:^",
49
- "@flowblade/sql-tag": "workspace:^",
49
+ "@flowblade/core": "^0.2.24",
50
+ "@flowblade/source-duckdb": "^0.16.2",
51
+ "@flowblade/sql-tag": "^0.1.18",
50
52
  "@standard-schema/spec": "^1.1.0",
51
53
  "p-mutex": "^1.0.0",
52
54
  "valibot": "^1.2.0",
@@ -58,18 +60,18 @@
58
60
  "devDependencies": {
59
61
  "@belgattitude/eslint-config-bases": "8.8.0",
60
62
  "@dotenvx/dotenvx": "1.51.2",
61
- "@duckdb/node-api": "1.4.3-r.1",
63
+ "@duckdb/node-api": "1.4.3-r.2",
62
64
  "@faker-js/faker": "10.1.0",
63
- "@flowblade/source-kysely": "workspace:^",
65
+ "@flowblade/source-kysely": "^0.17.2",
64
66
  "@httpx/assert": "0.16.7",
65
67
  "@size-limit/esbuild": "12.0.0",
66
68
  "@size-limit/file": "12.0.0",
67
- "@testcontainers/mssqlserver": "11.10.0",
69
+ "@testcontainers/mssqlserver": "11.11.0",
68
70
  "@total-typescript/ts-reset": "0.6.1",
69
71
  "@traversable/zod": "0.0.57",
70
72
  "@types/node": "25.0.3",
71
- "@typescript-eslint/eslint-plugin": "8.50.1",
72
- "@typescript-eslint/parser": "8.50.1",
73
+ "@typescript-eslint/eslint-plugin": "8.51.0",
74
+ "@typescript-eslint/parser": "8.51.0",
73
75
  "@vitest/coverage-v8": "4.0.16",
74
76
  "@vitest/ui": "4.0.16",
75
77
  "ansis": "4.2.0",
@@ -90,9 +92,9 @@
90
92
  "size-limit": "12.0.0",
91
93
  "sql-formatter": "15.6.12",
92
94
  "tarn": "3.0.2",
93
- "tedious": "19.1.3",
94
- "testcontainers": "11.10.0",
95
- "tsdown": "0.18.2",
95
+ "tedious": "19.2.0",
96
+ "testcontainers": "11.11.0",
97
+ "tsdown": "0.18.3",
96
98
  "tsx": "4.21.0",
97
99
  "typescript": "5.9.3",
98
100
  "vite-tsconfig-paths": "6.0.3",
@@ -104,4 +106,4 @@
104
106
  "publishConfig": {
105
107
  "directory": "_release/package"
106
108
  }
107
- }
109
+ }