@trytilde/ontology 5.0.0 → 6.0.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/mod.d.ts +4 -6
- package/dist/mod.js +5 -18
- package/package.json +1 -1
package/dist/mod.d.ts
CHANGED
|
@@ -54,13 +54,11 @@ export type Json = null | boolean | number | string | Json[] | {
|
|
|
54
54
|
export type SqlParam = string | number | boolean | null;
|
|
55
55
|
export type Key = string | number;
|
|
56
56
|
/** Where an ontology's data lives: `cell` (the default: SQLite cells for views, DuckLake for the
|
|
57
|
-
* lake)
|
|
58
|
-
|
|
59
|
-
* scale-to-zero tier; see CONTEXT.md, "SQLite storage"). */
|
|
60
|
-
export type Storage = "cell" | "postgres" | "sqlite";
|
|
57
|
+
* lake) or `postgres` (one Postgres schema for everything; see CONTEXT.md, "Postgres storage"). */
|
|
58
|
+
export type Storage = "cell" | "postgres";
|
|
61
59
|
/** The SQL dialect models and handler SQL are written in: DuckDB for `cell` storage, Postgres
|
|
62
|
-
* for `postgres
|
|
63
|
-
export type Dialect = "duckdb" | "postgres" | "
|
|
60
|
+
* for `postgres`; ClickHouse for the models of a ClickHouse destination. */
|
|
61
|
+
export type Dialect = "duckdb" | "postgres" | "clickhouse";
|
|
64
62
|
/** The kind of a named destination models can materialize to besides the storage. */
|
|
65
63
|
export type DestinationKind = "clickhouse";
|
|
66
64
|
/** A SQL text fragment (in the storage's dialect). */
|
package/dist/mod.js
CHANGED
|
@@ -265,14 +265,8 @@ function currentState(source, stream, of, o, newestByDefault, loc) {
|
|
|
265
265
|
materialization: "incremental",
|
|
266
266
|
uniqueKey: "_key",
|
|
267
267
|
incrementalStrategy: "delete+insert",
|
|
268
|
-
sql: ({ src, changes, isIncremental, self
|
|
269
|
-
|
|
270
|
-
dialect === "sqlite"
|
|
271
|
-
? sql `SELECT _key, _newest, _pos, payload FROM (
|
|
272
|
-
SELECT *, row_number() OVER (PARTITION BY _key ${raw("ORDER BY _newest DESC NULLS LAST, _pos DESC")}) AS __n FROM (${pick(src(of))}) every_row
|
|
273
|
-
) newest WHERE __n = 1 AND NOT _gone`
|
|
274
|
-
: isIncremental
|
|
275
|
-
? sql `WITH fresh AS (${pick(changes(of))})
|
|
268
|
+
sql: ({ src, changes, isIncremental, self }) => isIncremental
|
|
269
|
+
? sql `WITH fresh AS (${pick(changes(of))})
|
|
276
270
|
SELECT _key, _newest, _pos, payload, _gone AS _deleted FROM (
|
|
277
271
|
SELECT DISTINCT ON (_key) * FROM (
|
|
278
272
|
SELECT * FROM fresh
|
|
@@ -280,7 +274,7 @@ SELECT _key, _newest, _pos, payload, _gone AS _deleted FROM (
|
|
|
280
274
|
SELECT _key, _newest, _pos, payload, false AS _gone FROM ${self} WHERE _key IN (SELECT _key FROM fresh)
|
|
281
275
|
) both_ages ${order}
|
|
282
276
|
) newest`
|
|
283
|
-
|
|
277
|
+
: sql `SELECT _key, _newest, _pos, payload FROM (
|
|
284
278
|
SELECT DISTINCT ON (_key) * FROM (${pick(src(of))}) every_row ${order}
|
|
285
279
|
) newest WHERE NOT _gone`,
|
|
286
280
|
}, loc);
|
|
@@ -483,8 +477,6 @@ WHERE v._n = 1`;
|
|
|
483
477
|
uniqueKey: "_key",
|
|
484
478
|
incrementalStrategy: "delete+insert",
|
|
485
479
|
sql: ({ changes, isIncremental, self, dialect }) => {
|
|
486
|
-
if (dialect === "sqlite")
|
|
487
|
-
throw new Error(`${of.loc ?? ""} ${of.pipeline}.${of.stream}: a postgres.cdc stream's current state needs postgres or duckdb storage (sqlite storage ingests on demand, no CDC)`);
|
|
488
480
|
if (dialect === "postgres") {
|
|
489
481
|
return isIncremental
|
|
490
482
|
? pgBody(changes(of), sql `__current.payload`, sql `\nLEFT JOIN ${self} AS __current ON __current._key = v._key`)
|
|
@@ -1161,7 +1153,7 @@ export function toIR(o, root, readFile) {
|
|
|
1161
1153
|
: v && typeof v === "object"
|
|
1162
1154
|
? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, k === "loc" ? rel(x) : relDeep(x)]))
|
|
1163
1155
|
: v;
|
|
1164
|
-
const dialect = o.storage === "postgres" ? "postgres" :
|
|
1156
|
+
const dialect = o.storage === "postgres" ? "postgres" : "duckdb";
|
|
1165
1157
|
const decls = o.sources.map((x) => x.$source);
|
|
1166
1158
|
const seen = new Set();
|
|
1167
1159
|
for (const d of decls) {
|
|
@@ -1202,12 +1194,7 @@ export function toIR(o, root, readFile) {
|
|
|
1202
1194
|
const isIncremental = m.spec.materialization === "incremental" || m.spec.materialization === "cell";
|
|
1203
1195
|
const own = m.spec.destination ? "clickhouse" : dialect;
|
|
1204
1196
|
const full = evaluateModel(m, false, own, readFile, byName, sources);
|
|
1205
|
-
|
|
1206
|
-
const incremental = isIncremental && dialect !== "sqlite" ? evaluateModel(m, true, own, readFile, byName, sources) : null;
|
|
1207
|
-
// SQLite storage runs a model's full SQL only: hooks for incremental runs would never run.
|
|
1208
|
-
if (dialect === "sqlite" && ((m.spec.preHooks?.incremental?.length ?? 0) > 0 || (m.spec.postHooks?.incremental?.length ?? 0) > 0)) {
|
|
1209
|
-
throw new Error(`model ${m.spec.name}${m.loc ? ` (${m.loc})` : ""}: sqlite storage runs no hooks (it recomputes a model and writes the difference)`);
|
|
1210
|
-
}
|
|
1197
|
+
const incremental = isIncremental ? evaluateModel(m, true, own, readFile, byName, sources) : null;
|
|
1211
1198
|
evaluated.set(m.id, { full, incremental });
|
|
1212
1199
|
for (const r of [...full.found, ...(incremental?.found ?? [])]) {
|
|
1213
1200
|
if (r.kind === "model")
|
package/package.json
CHANGED