@yydb/postgresql 0.0.13 → 0.0.14
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/bin/psql.mjs +23 -11
- package/package.json +4 -4
package/bin/psql.mjs
CHANGED
|
@@ -31,13 +31,15 @@ function argumentsFor(args) {
|
|
|
31
31
|
}
|
|
32
32
|
if (option === "-F" || option === "--field-separator") {
|
|
33
33
|
const value = args[++index];
|
|
34
|
-
if (value === undefined || value.includes("\0"))
|
|
34
|
+
if (value === undefined || value.includes("\0"))
|
|
35
|
+
throw new Error(`invalid value for ${option}`);
|
|
35
36
|
options.separator = value;
|
|
36
37
|
continue;
|
|
37
38
|
}
|
|
38
39
|
if (option === "-P" || option === "--pset") {
|
|
39
40
|
const value = args[++index];
|
|
40
|
-
if (value === undefined || !value.startsWith("null="))
|
|
41
|
+
if (value === undefined || !value.startsWith("null="))
|
|
42
|
+
throw new Error("only psql null output is configurable");
|
|
41
43
|
options.nullValue = value.slice(5);
|
|
42
44
|
continue;
|
|
43
45
|
}
|
|
@@ -174,7 +176,8 @@ function query(options) {
|
|
|
174
176
|
)
|
|
175
177
|
throw new Error("invalid ReadyForQuery");
|
|
176
178
|
if (started) {
|
|
177
|
-
if (currentResult !== null)
|
|
179
|
+
if (currentResult !== null)
|
|
180
|
+
throw new Error("PostgreSQL result ended before CommandComplete");
|
|
178
181
|
finish();
|
|
179
182
|
return;
|
|
180
183
|
}
|
|
@@ -184,14 +187,19 @@ function query(options) {
|
|
|
184
187
|
throw new Error("PostgreSQL query exceeds byte limit");
|
|
185
188
|
socket.write(message("Q", sql));
|
|
186
189
|
} else if (tag === "T") {
|
|
187
|
-
if (!started || currentResult !== null)
|
|
190
|
+
if (!started || currentResult !== null)
|
|
191
|
+
throw new Error("unexpected PostgreSQL RowDescription");
|
|
188
192
|
currentResult = { columns: columnsFrom(payload), rows: [], tag: "" };
|
|
189
193
|
} else if (tag === "D") {
|
|
190
|
-
if (!started || currentResult === null)
|
|
194
|
+
if (!started || currentResult === null)
|
|
195
|
+
throw new Error("DataRow without RowDescription");
|
|
191
196
|
currentResult.rows.push(rowFrom(payload, currentResult.columns.length));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
197
|
+
} else if (tag === "C") {
|
|
198
|
+
if (
|
|
199
|
+
!started ||
|
|
200
|
+
payload.length < 2 ||
|
|
201
|
+
payload.indexOf(0) !== payload.length - 1
|
|
202
|
+
)
|
|
195
203
|
throw new Error("invalid CommandComplete");
|
|
196
204
|
const result = currentResult ?? { columns: [], rows: [], tag: "" };
|
|
197
205
|
result.tag = payload.toString("utf8", 0, payload.length - 1);
|
|
@@ -218,14 +226,18 @@ async function main(args) {
|
|
|
218
226
|
return;
|
|
219
227
|
}
|
|
220
228
|
if (args.length === 1 && args[0] === "--help") {
|
|
221
|
-
console.log(
|
|
229
|
+
console.log(
|
|
230
|
+
"Usage: psql [-h HOST] [-p PORT] [-U USER] [-d DATABASE] [-t] [-F SEP] [-P null=TEXT] -c SQL",
|
|
231
|
+
);
|
|
222
232
|
return;
|
|
223
233
|
}
|
|
224
234
|
const options = argumentsFor(args);
|
|
225
235
|
const results = await query(options);
|
|
226
236
|
for (const result of results) {
|
|
227
|
-
if (options.headers && result.columns.length)
|
|
228
|
-
|
|
237
|
+
if (options.headers && result.columns.length)
|
|
238
|
+
console.log(result.columns.join(options.separator));
|
|
239
|
+
for (const row of result.rows)
|
|
240
|
+
console.log(row.map((value) => value ?? options.nullValue).join(options.separator));
|
|
229
241
|
if (result.columns.length === 0 && options.headers) console.log(result.tag);
|
|
230
242
|
}
|
|
231
243
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yydb/postgresql",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Pretend you installed PostgreSQL. YYDS scripting runtime underneath.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
35
35
|
"url": "git+https://github.com/yy-database/yyds.git",
|
|
36
|
-
"directory": "projects/
|
|
36
|
+
"directory": "projects/yyds.ts/emulators/postgresql"
|
|
37
37
|
},
|
|
38
|
-
"homepage": "https://github.com/yy-database/yyds/tree/dev/projects/
|
|
38
|
+
"homepage": "https://github.com/yy-database/yyds/tree/dev/projects/yyds.ts/emulators/postgresql#readme",
|
|
39
39
|
"bugs": {
|
|
40
40
|
"url": "https://github.com/yy-database/yyds/issues"
|
|
41
41
|
},
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@yydb/yyds": "0.0.
|
|
52
|
+
"@yydb/yyds": "0.0.14"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^22.15.0",
|