@crvouga/mockingbird-service-postgres 3.0.1 → 3.0.2
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 +6 -0
- package/dist/server.js +48 -3
- package/dist/server.js.map +2 -2
- package/dist/wire/cli.js +48 -3
- package/dist/wire/cli.js.map +2 -2
- package/dist/wire/connection.d.ts +6 -3
- package/dist/wire/index.js +48 -3
- package/dist/wire/index.js.map +2 -2
- package/package.json +1 -1
package/dist/wire/cli.js
CHANGED
|
@@ -25620,6 +25620,46 @@ var decodeParam = (oid, format, bytes) => {
|
|
|
25620
25620
|
throw pgError2("internal", `binary parameter format is not supported for type oid ${oid}`, "0A000");
|
|
25621
25621
|
}
|
|
25622
25622
|
};
|
|
25623
|
+
function returningShape(db, sql) {
|
|
25624
|
+
let statements;
|
|
25625
|
+
try {
|
|
25626
|
+
statements = parse(sql);
|
|
25627
|
+
} catch {
|
|
25628
|
+
return null;
|
|
25629
|
+
}
|
|
25630
|
+
const stmt = statements.length === 1 ? statements[0] : void 0;
|
|
25631
|
+
if (!stmt || stmt.type !== "insert" && stmt.type !== "update" && stmt.type !== "delete") return null;
|
|
25632
|
+
const targets = stmt.returning;
|
|
25633
|
+
if (!targets || targets.length === 0) return null;
|
|
25634
|
+
const table = db.state.findTable(stmt.table);
|
|
25635
|
+
if (!table) return null;
|
|
25636
|
+
const label = stmt.alias ?? table.name;
|
|
25637
|
+
const columns = [];
|
|
25638
|
+
const columnTypes = [];
|
|
25639
|
+
for (const target of targets) {
|
|
25640
|
+
if (target.expr.type === "star") {
|
|
25641
|
+
const qualifier = target.expr.table?.at(-1);
|
|
25642
|
+
if (qualifier !== void 0 && qualifier !== label && qualifier !== table.name) return null;
|
|
25643
|
+
for (const column of table.columns) {
|
|
25644
|
+
columns.push(column.name);
|
|
25645
|
+
columnTypes.push(column.type.id);
|
|
25646
|
+
}
|
|
25647
|
+
continue;
|
|
25648
|
+
}
|
|
25649
|
+
if (target.expr.type === "colref") {
|
|
25650
|
+
const name = target.expr.parts.at(-1) ?? "?column?";
|
|
25651
|
+
const column = table.columns.find((item) => item.name === name);
|
|
25652
|
+
columns.push(target.alias ?? name);
|
|
25653
|
+
columnTypes.push(column?.type.id ?? "text");
|
|
25654
|
+
continue;
|
|
25655
|
+
}
|
|
25656
|
+
columns.push(target.alias ?? inferColumnName(target.expr));
|
|
25657
|
+
columnTypes.push("text");
|
|
25658
|
+
}
|
|
25659
|
+
if (columns.length === 0) return null;
|
|
25660
|
+
const command2 = stmt.type === "insert" ? "INSERT" : stmt.type === "update" ? "UPDATE" : "DELETE";
|
|
25661
|
+
return { columns, columnTypes, rows: [], rowCount: 0, command: command2 };
|
|
25662
|
+
}
|
|
25623
25663
|
var Connection = class {
|
|
25624
25664
|
constructor(socket, cluster, options2) {
|
|
25625
25665
|
this.socket = socket;
|
|
@@ -26500,11 +26540,16 @@ var Connection = class {
|
|
|
26500
26540
|
else this.write(backend.rowDescription(this.fields(outcome.result, portal.resultFormats)));
|
|
26501
26541
|
}
|
|
26502
26542
|
/**
|
|
26503
|
-
* The row shape of a statement that returns rows, for Describe on a statement
|
|
26504
|
-
*
|
|
26505
|
-
* fails
|
|
26543
|
+
* The row shape of a statement that returns rows, for Describe on a statement.
|
|
26544
|
+
* `INSERT`/`UPDATE`/`DELETE ... RETURNING` is described from the catalog: a trial run binds
|
|
26545
|
+
* nulls and fails NOT NULL, and Describe would answer NoData. Bun then reads one DataRow cell
|
|
26546
|
+
* and treats the rest of the message as a broken protocol frame.
|
|
26547
|
+
* Other row-returning statements are a trial run with null parameters, rolled back. A trial
|
|
26548
|
+
* that fails is described as returning no data.
|
|
26506
26549
|
*/
|
|
26507
26550
|
async shapeOf(prepared) {
|
|
26551
|
+
const described = returningShape(this.database, prepared.sql);
|
|
26552
|
+
if (described) return described;
|
|
26508
26553
|
if (!RETURNS_ROWS.test(prepared.sql)) return null;
|
|
26509
26554
|
const db = this.database;
|
|
26510
26555
|
await this.cluster.acquireTurn(this);
|