latticesql 1.6.1 → 1.6.3
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/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/postgres-worker.cjs +72 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6153,7 +6153,7 @@ var PostgresAdapter = class {
|
|
|
6153
6153
|
_opened = false;
|
|
6154
6154
|
constructor(connectionString, options = {}) {
|
|
6155
6155
|
this._connectionString = connectionString;
|
|
6156
|
-
this._workerPath = options.workerPath ?? path.join(__dirname2, "postgres-worker.
|
|
6156
|
+
this._workerPath = options.workerPath ?? path.join(__dirname2, "postgres-worker.cjs");
|
|
6157
6157
|
}
|
|
6158
6158
|
open() {
|
|
6159
6159
|
if (this._opened) return;
|
package/dist/index.cjs
CHANGED
|
@@ -5896,7 +5896,7 @@ var PostgresAdapter = class {
|
|
|
5896
5896
|
_opened = false;
|
|
5897
5897
|
constructor(connectionString, options = {}) {
|
|
5898
5898
|
this._connectionString = connectionString;
|
|
5899
|
-
this._workerPath = options.workerPath ?? import_node_path3.default.join(__dirname2, "postgres-worker.
|
|
5899
|
+
this._workerPath = options.workerPath ?? import_node_path3.default.join(__dirname2, "postgres-worker.cjs");
|
|
5900
5900
|
}
|
|
5901
5901
|
open() {
|
|
5902
5902
|
if (this._opened) return;
|
package/dist/index.js
CHANGED
|
@@ -5839,7 +5839,7 @@ var PostgresAdapter = class {
|
|
|
5839
5839
|
_opened = false;
|
|
5840
5840
|
constructor(connectionString, options = {}) {
|
|
5841
5841
|
this._connectionString = connectionString;
|
|
5842
|
-
this._workerPath = options.workerPath ?? path.join(__dirname2, "postgres-worker.
|
|
5842
|
+
this._workerPath = options.workerPath ?? path.join(__dirname2, "postgres-worker.cjs");
|
|
5843
5843
|
}
|
|
5844
5844
|
open() {
|
|
5845
5845
|
if (this._opened) return;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/db/postgres-worker.ts
|
|
4
|
+
var import_synckit = require("synckit");
|
|
5
|
+
var { Client } = require("pg");
|
|
6
|
+
var client = null;
|
|
7
|
+
function ensureClient() {
|
|
8
|
+
if (!client) throw new Error("PostgresAdapter worker: client not opened");
|
|
9
|
+
return client;
|
|
10
|
+
}
|
|
11
|
+
(0, import_synckit.runAsWorker)(async (action) => {
|
|
12
|
+
try {
|
|
13
|
+
switch (action.type) {
|
|
14
|
+
case "open": {
|
|
15
|
+
if (client) return { ok: true };
|
|
16
|
+
client = new Client({ connectionString: action.connectionString });
|
|
17
|
+
await client.connect();
|
|
18
|
+
try {
|
|
19
|
+
await client.query("CREATE EXTENSION IF NOT EXISTS pgcrypto");
|
|
20
|
+
} catch (extErr) {
|
|
21
|
+
console.warn(
|
|
22
|
+
"[PostgresAdapter] CREATE EXTENSION pgcrypto failed (may already be enabled by your provider):",
|
|
23
|
+
extErr instanceof Error ? extErr.message : extErr
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return { ok: true };
|
|
27
|
+
}
|
|
28
|
+
case "close": {
|
|
29
|
+
if (client) {
|
|
30
|
+
await client.end();
|
|
31
|
+
client = null;
|
|
32
|
+
}
|
|
33
|
+
return { ok: true };
|
|
34
|
+
}
|
|
35
|
+
case "run": {
|
|
36
|
+
const r = await ensureClient().query(action.sql, action.params);
|
|
37
|
+
return { ok: true, rowCount: r.rowCount ?? 0 };
|
|
38
|
+
}
|
|
39
|
+
case "get": {
|
|
40
|
+
const r = await ensureClient().query(action.sql, action.params);
|
|
41
|
+
return { ok: true, rows: r.rows.slice(0, 1) };
|
|
42
|
+
}
|
|
43
|
+
case "all": {
|
|
44
|
+
const r = await ensureClient().query(action.sql, action.params);
|
|
45
|
+
return { ok: true, rows: r.rows };
|
|
46
|
+
}
|
|
47
|
+
case "introspectColumns": {
|
|
48
|
+
const r = await ensureClient().query(
|
|
49
|
+
`SELECT column_name FROM information_schema.columns
|
|
50
|
+
WHERE table_schema = current_schema() AND table_name = $1
|
|
51
|
+
ORDER BY ordinal_position`,
|
|
52
|
+
[action.table]
|
|
53
|
+
);
|
|
54
|
+
return { ok: true, rows: r.rows };
|
|
55
|
+
}
|
|
56
|
+
case "addColumn": {
|
|
57
|
+
const upper = action.typeSpec.toUpperCase();
|
|
58
|
+
if (upper.includes("PRIMARY KEY")) return { ok: true };
|
|
59
|
+
const translated = translateTypeSpec(action.typeSpec);
|
|
60
|
+
await ensureClient().query(
|
|
61
|
+
`ALTER TABLE "${action.table}" ADD COLUMN IF NOT EXISTS "${action.column}" ${translated}`
|
|
62
|
+
);
|
|
63
|
+
return { ok: true };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
function translateTypeSpec(typeSpec) {
|
|
71
|
+
return typeSpec.replace(/\bBLOB\b/gi, "BYTEA").replace(/\bdatetime\(\s*'now'\s*\)/gi, "NOW()").replace(/\bRANDOM\(\)/gi, "random()");
|
|
72
|
+
}
|
package/package.json
CHANGED