dzql 0.10.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/README.md +6 -6
- package/package.json +1 -1
- package/src/compile/cascades.ts +6 -6
- package/src/compile/columns.ts +7 -8
- package/src/compile/holders.ts +5 -11
- package/src/compile/holds.ts +4 -5
- package/src/compile/ledger.ts +7 -8
- package/src/compile/lookups.ts +118 -0
- package/src/compile/opens.ts +6 -0
- package/src/compile/resolve.ts +4 -4
- package/src/compile/root.ts +4 -4
- package/src/compile/rows.ts +18 -17
- package/src/compile/scope.ts +5 -4
- package/src/compile/told.ts +5 -4
- package/src/postgres/codegen.ts +2 -1
- package/src/postgres/listener.ts +50 -35
- package/src/postgres/pglite.ts +4 -1
- package/src/sql/001a-delta-meta.sql +52 -19
- package/src/sql/001b-delta-scope.sql +18 -477
- package/src/sql/001c-delta-read.sql +14 -291
- package/src/sql/001d-delta-write.sql +64 -379
- package/src/sql/001e-delta-ops.sql +4 -62
- package/src/sql/001g-delta-ledger.sql +6 -29
|
@@ -254,40 +254,17 @@ $$;
|
|
|
254
254
|
-- A field of a collection's row the same in two values: a timestamptz by the
|
|
255
255
|
-- instant it names, whatever zone its text was written in (a ledger's entry
|
|
256
256
|
-- keeps the session's TimeZone of its write), anything else as _delta_same.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
SELECT CASE
|
|
260
|
-
WHEN jsonb_typeof(a) = 'string' AND jsonb_typeof(b) = 'string'
|
|
261
|
-
AND (SELECT _delta_cols(collection_key, columns_def)->p_field->>'type' FROM _delta_collections WHERE collection_key = p_coll) = 'timestamptz'
|
|
262
|
-
THEN (a #>> '{}')::timestamptz = (b #>> '{}')::timestamptz
|
|
263
|
-
ELSE _delta_same(a, b)
|
|
264
|
-
END;
|
|
265
|
-
$$;
|
|
266
|
-
|
|
267
|
-
-- the framework's, until dzql's compiler (`compileLedger`) writes each
|
|
268
|
-
-- collection's time fields in
|
|
257
|
+
-- generateSql writes each collection's time fields in (compileLedger); before
|
|
258
|
+
-- it is applied there is no collection, and values are the same as JSON.
|
|
269
259
|
CREATE OR REPLACE FUNCTION _delta_same(p_coll TEXT, p_field TEXT, a JSONB, b JSONB)
|
|
270
|
-
RETURNS BOOLEAN LANGUAGE sql STABLE AS $$ SELECT
|
|
260
|
+
RETURNS BOOLEAN LANGUAGE sql STABLE AS $$ SELECT _delta_same(a, b); $$;
|
|
271
261
|
|
|
272
262
|
-- _delta_row_standing: row `p_id` of a collection as it stands, without its
|
|
273
263
|
-- validity, as {row} (row null: not there); NULL for a collection there is not.
|
|
274
|
-
-- What a walk guards a row beyond its document by.
|
|
275
|
-
|
|
276
|
-
RETURNS JSONB AS $$
|
|
277
|
-
DECLARE
|
|
278
|
-
v_coll RECORD;
|
|
279
|
-
v_row JSONB;
|
|
280
|
-
BEGIN
|
|
281
|
-
SELECT * INTO v_coll FROM _delta_collections WHERE collection_key = p_coll;
|
|
282
|
-
IF NOT FOUND THEN RETURN NULL; END IF;
|
|
283
|
-
EXECUTE format('SELECT _delta_strip_temporal(to_jsonb(t.*)) FROM %I t WHERE t.id = $1', _delta_source_view(v_coll.table_name, v_coll.temporal))
|
|
284
|
-
INTO v_row USING p_id;
|
|
285
|
-
RETURN jsonb_build_object('row', v_row);
|
|
286
|
-
END;
|
|
287
|
-
$$ LANGUAGE plpgsql STABLE;
|
|
288
|
-
|
|
264
|
+
-- What a walk guards a row beyond its document by. generateSql writes one for
|
|
265
|
+
-- each collection (compileLedger).
|
|
289
266
|
CREATE OR REPLACE FUNCTION _delta_row_standing(p_coll TEXT, p_id BIGINT)
|
|
290
|
-
RETURNS JSONB LANGUAGE sql STABLE AS $$ SELECT
|
|
267
|
+
RETURNS JSONB LANGUAGE sql STABLE AS $$ SELECT NULL::jsonb; $$;
|
|
291
268
|
|
|
292
269
|
-- _delta_walk_key: a row's key in a walk -- the keyOf of planWalk in
|
|
293
270
|
-- src/server/ledger.ts. A single document's root is one row at two paths,
|