@fougere/adapter-duckdb 0.23.0-alpha.0 → 0.24.0-alpha.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.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +12 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Entity } from '@fougere/schema';
|
|
2
2
|
/** An entry of `sources:` as this reader sees it — what its own adapter declared, nothing added. */
|
|
3
3
|
export interface SourceEntry {
|
|
4
|
-
type
|
|
4
|
+
type: string;
|
|
5
5
|
path?: string;
|
|
6
6
|
url?: string;
|
|
7
7
|
entities?: string[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,MAAM,EAAmB,MAAM,iBAAiB,CAAC;AAI3E,oGAAoG;AACpG,MAAM,WAAW,WAAW;IAC1B,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,MAAM,EAAmB,MAAM,iBAAiB,CAAC;AAI3E,oGAAoG;AACpG,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,0EAA0E;IAC1E,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,kEAAkE;IAClE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACtC;AAED,2EAA2E;AAC3E,MAAM,WAAW,KAAK;IACpB,6DAA6D;IAC7D,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAChH,uEAAuE;IACvE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAeD,kDAAkD;AAClD,wBAAsB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CAgE5E"}
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ export async function connectSources(options) {
|
|
|
32
32
|
const name = lowerFirst(shape.name ?? '');
|
|
33
33
|
const alias = home.get(name) ?? fallback;
|
|
34
34
|
if (!alias)
|
|
35
|
-
throw new Error(`${name}
|
|
35
|
+
throw new Error(`${name} is in no source: none lists it, and none takes the rest. Add it to one in sources:.`);
|
|
36
36
|
wanted.add(alias);
|
|
37
37
|
placed.set(shape, { alias, table: resolve(name) });
|
|
38
38
|
}
|
|
@@ -42,17 +42,15 @@ export async function connectSources(options) {
|
|
|
42
42
|
for (const alias of wanted) {
|
|
43
43
|
const entry = options.sources[alias];
|
|
44
44
|
if (!entry)
|
|
45
|
-
throw new Error(`source '${alias}' is read but
|
|
46
|
-
const
|
|
47
|
-
const attachable = ATTACHABLE[type];
|
|
45
|
+
throw new Error(`source '${alias}' is read here but missing from sources:.`);
|
|
46
|
+
const attachable = ATTACHABLE[entry.type];
|
|
48
47
|
if (!attachable) {
|
|
49
|
-
throw new Error(`source '${alias}' is
|
|
50
|
-
|
|
51
|
-
`${Object.keys(ATTACHABLE).join(', ')}.`);
|
|
48
|
+
throw new Error(`source '${alias}' is ${entry.type}, which DuckDB cannot read. It reads `
|
|
49
|
+
+ `${Object.keys(ATTACHABLE).join(', ')}: copy the rows into one of those, or read them through their own repository.`);
|
|
52
50
|
}
|
|
53
51
|
const target = attachable.target(entry);
|
|
54
52
|
if (!target) {
|
|
55
|
-
throw new Error(`source '${alias}'
|
|
53
|
+
throw new Error(`source '${alias}' has no path or url, so DuckDB cannot open it.`);
|
|
56
54
|
}
|
|
57
55
|
await db.run(`INSTALL ${attachable.extension}; LOAD ${attachable.extension};`);
|
|
58
56
|
await db.run(`ATTACH '${target}' AS ${quote(attachedAs(alias))} (TYPE ${attachable.extension}, READ_ONLY);`);
|
|
@@ -83,13 +81,11 @@ function qualify(ref, placed) {
|
|
|
83
81
|
return `${quote(attachedAs(found.alias))}.${quote(found.table)}`;
|
|
84
82
|
const name = ref?.name;
|
|
85
83
|
if (name) {
|
|
86
|
-
throw new Error(`${name} is
|
|
87
|
-
`table does not exist in this connection. Add it to \`reads\`, or stop naming it.`);
|
|
84
|
+
throw new Error(`${name} is used in a query but is not in \`reads\`. Add it to \`reads\` in frond.config.ts.`);
|
|
88
85
|
}
|
|
89
86
|
// A plain value interpolated into SQL is refused: this tag substitutes ENTITIES, and
|
|
90
87
|
// accepting a value would be a string-built query with no binding in sight.
|
|
91
|
-
throw new Error(
|
|
92
|
-
`query text you write, or filter the result.`);
|
|
88
|
+
throw new Error('Only an entity can go inside ${…} in a source query. Write values in the query text, or filter the result.');
|
|
93
89
|
}
|
|
94
90
|
const quote = (identifier) => `"${identifier.replace(/"/g, '""')}"`;
|
|
95
91
|
/** The column set, checked ONCE against the shape. */
|
|
@@ -97,9 +93,9 @@ function refuseMismatch(shape, names, row, sql) {
|
|
|
97
93
|
const missing = names.filter((name) => !(toSnakeCase(name) in row) && !(name in row));
|
|
98
94
|
if (missing.length === 0)
|
|
99
95
|
return;
|
|
100
|
-
throw new Error(`${shape.name ?? 'the shape'}
|
|
101
|
-
`and the query
|
|
102
|
-
|
|
96
|
+
throw new Error(`${shape.name ?? 'the shape'} expects ${missing.map((m) => `\`${m}\``).join(', ')}, `
|
|
97
|
+
+ `and the query returns ${Object.keys(row).map((c) => `\`${c}\``).join(', ')}. Rename the column with \`as\`, `
|
|
98
|
+
+ `or remove the field.\n${sql.trim()}`);
|
|
103
99
|
}
|
|
104
100
|
/** Keep what the shape declares, converted — a column it does not name never leaves. */
|
|
105
101
|
function project(names, codecs, row) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAgC,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AA6BnF;;;GAGG;AACH,MAAM,UAAU,GAA8F;IAC5G,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE;IAC9D,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;IAC3D,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;CAC5D,CAAC;AAEF,2FAA2F;AAC3F,MAAM,UAAU,GAAG,CAAC,MAAc,EAAU,EAAE,CAAC,UAAU,MAAM,EAAE,CAAC;AAElE,kDAAkD;AAClD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAuB;IAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,WAAW,CAAC;IAE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AAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;UAC1G,yBAAyB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,mCAAmC;UAC9G,yBAAyB,GAAG,CAAC,IAAI,EAAE,EAAE,CACxC,CAAC;AACJ,CAAC;AAED,wFAAwF;AACxF,SAAS,OAAO,CACd,KAAe,EACf,MAAsD,EACtD,GAA4B;IAE5B,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpD,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;IACjD,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/adapter-duckdb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0-alpha.0",
|
|
4
4
|
"description": "Read across an app's sources — one SQL query over what DuckDB can attach.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"src"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@fougere/schema": "0.
|
|
33
|
-
"@fougere/adapter-sql": "0.
|
|
32
|
+
"@fougere/schema": "0.24.0-alpha.0",
|
|
33
|
+
"@fougere/adapter-sql": "0.24.0-alpha.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@duckdb/node-api": ">=1.4.0-0"
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { toTable, toTableName, toSnakeCase, codecsOf } from '@fougere/adapter-sq
|
|
|
6
6
|
|
|
7
7
|
/** An entry of `sources:` as this reader sees it — what its own adapter declared, nothing added. */
|
|
8
8
|
export interface SourceEntry {
|
|
9
|
-
type
|
|
9
|
+
type: string;
|
|
10
10
|
path?: string;
|
|
11
11
|
url?: string;
|
|
12
12
|
entities?: string[];
|
|
@@ -61,7 +61,7 @@ export async function connectSources(options: ConnectOptions): Promise<Reads> {
|
|
|
61
61
|
for (const shape of options.reads) {
|
|
62
62
|
const name = lowerFirst((shape as { name?: string }).name ?? '');
|
|
63
63
|
const alias = home.get(name) ?? fallback;
|
|
64
|
-
if (!alias) throw new Error(`${name}
|
|
64
|
+
if (!alias) throw new Error(`${name} is in no source: none lists it, and none takes the rest. Add it to one in sources:.`);
|
|
65
65
|
wanted.add(alias);
|
|
66
66
|
placed.set(shape, { alias, table: resolve(name) });
|
|
67
67
|
}
|
|
@@ -72,20 +72,18 @@ export async function connectSources(options: ConnectOptions): Promise<Reads> {
|
|
|
72
72
|
|
|
73
73
|
for (const alias of wanted) {
|
|
74
74
|
const entry = options.sources[alias];
|
|
75
|
-
if (!entry) throw new Error(`source '${alias}' is read but
|
|
75
|
+
if (!entry) throw new Error(`source '${alias}' is read here but missing from sources:.`);
|
|
76
76
|
|
|
77
|
-
const
|
|
78
|
-
const attachable = ATTACHABLE[type];
|
|
77
|
+
const attachable = ATTACHABLE[entry.type];
|
|
79
78
|
if (!attachable) {
|
|
80
79
|
throw new Error(
|
|
81
|
-
`source '${alias}' is
|
|
82
|
-
|
|
83
|
-
`${Object.keys(ATTACHABLE).join(', ')}.`,
|
|
80
|
+
`source '${alias}' is ${entry.type}, which DuckDB cannot read. It reads `
|
|
81
|
+
+ `${Object.keys(ATTACHABLE).join(', ')}: copy the rows into one of those, or read them through their own repository.`,
|
|
84
82
|
);
|
|
85
83
|
}
|
|
86
84
|
const target = attachable.target(entry);
|
|
87
85
|
if (!target) {
|
|
88
|
-
throw new Error(`source '${alias}'
|
|
86
|
+
throw new Error(`source '${alias}' has no path or url, so DuckDB cannot open it.`);
|
|
89
87
|
}
|
|
90
88
|
await db.run(`INSTALL ${attachable.extension}; LOAD ${attachable.extension};`);
|
|
91
89
|
await db.run(`ATTACH '${target}' AS ${quote(attachedAs(alias))} (TYPE ${attachable.extension}, READ_ONLY);`);
|
|
@@ -119,15 +117,13 @@ function qualify(ref: unknown, placed: Map<Entity, { alias: string; table: strin
|
|
|
119
117
|
const name = (ref as { name?: string } | undefined)?.name;
|
|
120
118
|
if (name) {
|
|
121
119
|
throw new Error(
|
|
122
|
-
`${name} is
|
|
123
|
-
`table does not exist in this connection. Add it to \`reads\`, or stop naming it.`,
|
|
120
|
+
`${name} is used in a query but is not in \`reads\`. Add it to \`reads\` in frond.config.ts.`,
|
|
124
121
|
);
|
|
125
122
|
}
|
|
126
123
|
// A plain value interpolated into SQL is refused: this tag substitutes ENTITIES, and
|
|
127
124
|
// accepting a value would be a string-built query with no binding in sight.
|
|
128
125
|
throw new Error(
|
|
129
|
-
|
|
130
|
-
`query text you write, or filter the result.`,
|
|
126
|
+
'Only an entity can go inside ${…} in a source query. Write values in the query text, or filter the result.',
|
|
131
127
|
);
|
|
132
128
|
}
|
|
133
129
|
|
|
@@ -138,9 +134,9 @@ function refuseMismatch(shape: Entity, names: string[], row: Record<string, unkn
|
|
|
138
134
|
const missing = names.filter((name) => !(toSnakeCase(name) in row) && !(name in row));
|
|
139
135
|
if (missing.length === 0) return;
|
|
140
136
|
throw new Error(
|
|
141
|
-
`${(shape as { name?: string }).name ?? 'the shape'}
|
|
142
|
-
`and the query
|
|
143
|
-
|
|
137
|
+
`${(shape as { name?: string }).name ?? 'the shape'} expects ${missing.map((m) => `\`${m}\``).join(', ')}, `
|
|
138
|
+
+ `and the query returns ${Object.keys(row).map((c) => `\`${c}\``).join(', ')}. Rename the column with \`as\`, `
|
|
139
|
+
+ `or remove the field.\n${sql.trim()}`,
|
|
144
140
|
);
|
|
145
141
|
}
|
|
146
142
|
|