Skip to content

Commit 22f936f

Browse files
fix: bytea formatting for new ff (#80)
1 parent ca753db commit 22f936f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/formatter/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ export class QueryFormatter {
136136
}
137137

138138
private escapeBuffer(param: Buffer) {
139-
return "'\\x" + param.toString("hex") + "'";
139+
const bytesFormatted = [];
140+
for (let i = 0; i < param.length; i++) {
141+
bytesFormatted.push("\\x" + param[i].toString(16).padStart(2, "0"));
142+
}
143+
return "E'" + bytesFormatted.join("") + "'";
140144
}
141145

142146
private escapeArray(param: unknown[], prefix = "[", suffix = "]") {

test/unit/statement.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ describe("format query", () => {
273273
const formattedQuery = queryFormatter.formatQuery(query, [buffer]);
274274
// Jest escaping rules are different, so we need to double the amount of quotes compared to .toEqual()
275275
expect(formattedQuery).toMatchInlineSnapshot(
276-
`"SELECT 'hello_world'::bytea == '\\\\x68656c6c6f5f776f726c64'"`
276+
`"SELECT 'hello_world'::bytea == E'\\\\x68\\\\x65\\\\x6c\\\\x6c\\\\x6f\\\\x5f\\\\x77\\\\x6f\\\\x72\\\\x6c\\\\x64'"`
277277
);
278278
});
279279
});

0 commit comments

Comments
 (0)