@voltro/plugin-analytics-postgres 0.86.0 → 0.87.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/CHANGELOG.md +5321 -0
- package/README.md +28 -1
- package/THIRD-PARTY-NOTICES.md +860 -221
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/sink.js +34 -9
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export declare interface PostgresAnalyticsOptions {
|
|
|
79
79
|
*/
|
|
80
80
|
export declare interface PostgresAnalyticsSpec {
|
|
81
81
|
readonly kind: 'postgres-analytics';
|
|
82
|
+
readonly sql: 'required';
|
|
82
83
|
readonly options: PostgresAnalyticsOptions;
|
|
83
84
|
/** Internal — the cli calls this with the resolved SqlClient. */
|
|
84
85
|
readonly build: (sqlClient: SqlClient.SqlClient) => AnalyticsSinkImpl;
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var o = (e = {}) => (i({
|
|
|
9
9
|
ttlMs: a(process.env.VOLTRO_EVENTS_TTL_HOURS, 8760)
|
|
10
10
|
}), {
|
|
11
11
|
kind: "postgres-analytics",
|
|
12
|
+
sql: "required",
|
|
12
13
|
options: e,
|
|
13
14
|
build: (t) => r(e.sqlClient ?? t, {
|
|
14
15
|
...e.mirrorTables === void 0 ? {} : { mirrorTables: e.mirrorTables },
|
package/dist/sink.js
CHANGED
|
@@ -19,16 +19,41 @@ var o = "postgres-analytics", s = "_voltro_events", c = (e, t) => e.onDialectOrE
|
|
|
19
19
|
operation: e,
|
|
20
20
|
cause: t instanceof Error ? `${t.name}: ${t.message}` : String(t)
|
|
21
21
|
})), c = (n, r, a, o, s) => i.gen(function* () {
|
|
22
|
-
let i = e(n)
|
|
23
|
-
|
|
22
|
+
let i = e(n), c = t.onDialectOrElse({
|
|
23
|
+
sqlite: () => +!!s,
|
|
24
|
+
orElse: () => s
|
|
25
|
+
});
|
|
26
|
+
yield* t.onDialectOrElse({
|
|
27
|
+
mysql: () => t`
|
|
24
28
|
INSERT INTO ${t(i)} (${t("id")}, ${t("data")}, ${t("version")}, ${t("is_deleted")})
|
|
25
|
-
VALUES (${r}, ${a}, ${o}, ${
|
|
26
|
-
ON
|
|
27
|
-
${t("data")} = ${a},
|
|
28
|
-
${t("
|
|
29
|
-
${t("
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
VALUES (${r}, ${a}, ${o}, ${c})
|
|
30
|
+
ON DUPLICATE KEY UPDATE
|
|
31
|
+
${t("data")} = IF(${t("version")} < ${o}, ${a}, ${t("data")}),
|
|
32
|
+
${t("is_deleted")} = IF(${t("version")} < ${o}, ${c}, ${t("is_deleted")}),
|
|
33
|
+
${t("version")} = IF(${t("version")} < ${o}, ${o}, ${t("version")})
|
|
34
|
+
`,
|
|
35
|
+
mssql: () => t`
|
|
36
|
+
MERGE INTO ${t(i)} WITH (HOLDLOCK) AS target
|
|
37
|
+
USING (SELECT ${r} AS ${t("id")}, ${a} AS ${t("data")},
|
|
38
|
+
${o} AS ${t("version")}, ${c} AS ${t("is_deleted")}) AS source
|
|
39
|
+
ON target.${t("id")} = source.${t("id")}
|
|
40
|
+
WHEN MATCHED AND target.${t("version")} < source.${t("version")} THEN
|
|
41
|
+
UPDATE SET ${t("data")} = source.${t("data")},
|
|
42
|
+
${t("is_deleted")} = source.${t("is_deleted")}, ${t("version")} = source.${t("version")}
|
|
43
|
+
WHEN NOT MATCHED THEN
|
|
44
|
+
INSERT (${t("id")}, ${t("data")}, ${t("version")}, ${t("is_deleted")})
|
|
45
|
+
VALUES (source.${t("id")}, source.${t("data")}, source.${t("version")}, source.${t("is_deleted")});
|
|
46
|
+
`,
|
|
47
|
+
orElse: () => t`
|
|
48
|
+
INSERT INTO ${t(i)} (${t("id")}, ${t("data")}, ${t("version")}, ${t("is_deleted")})
|
|
49
|
+
VALUES (${r}, ${a}, ${o}, ${c})
|
|
50
|
+
ON CONFLICT (${t("id")}) DO UPDATE SET
|
|
51
|
+
${t("data")} = ${a},
|
|
52
|
+
${t("version")} = ${o},
|
|
53
|
+
${t("is_deleted")} = ${c}
|
|
54
|
+
WHERE ${t(i)}.${t("version")} < ${o}
|
|
55
|
+
`
|
|
56
|
+
});
|
|
32
57
|
});
|
|
33
58
|
return {
|
|
34
59
|
tables: n,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-analytics-postgres",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "First-party AnalyticsSink
|
|
3
|
+
"version": "0.87.0",
|
|
4
|
+
"description": "First-party SQL AnalyticsSink for events and version-guarded CDC mirrors. Throughput depends on the schema, workload and database; no capacity ceiling is verified.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
7
7
|
"typescript",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"node": ">=24.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@voltro/database": "0.
|
|
37
|
-
"@voltro/runtime": "0.
|
|
36
|
+
"@voltro/database": "0.87.0",
|
|
37
|
+
"@voltro/runtime": "0.87.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"effect": "4.0.1"
|