-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Improve type conversion and responses for raw queries #4569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @ivashog Can you please share the database schema of the above table with a sample row so that I can try reproducing the problem? Thanks! |
Sorry to barge in. But I have exact the same issue using $queryRaw. I'm using ulid to generate my ids.
My table:
I expect to get back something like:
Except when I console log the result of the raw query:
I should be receiving a buffer instead of an encoded string? Let me know what you need to solve this issue. Thanks |
Hey @paulm17 This is expected. Since your data is binary, raw query will return it as base64 encoded data. You will need to deserialize it like so: import { PrismaClient } from "@prisma/client";
async function main() {
const prisma = new PrismaClient();
let data = await prisma.$queryRaw<Array<{ id: string; name: string }>>(
"select * from anki_lists"
);
data = data.map((d) => ({
...d,
id: Buffer.from(d.id, "base64").toString(),
}));
console.log(data);
prisma.$disconnect();
}
main(); I would suggest you rather use the client api directly as it supports binary type and correctly encodes it into a buffer: import { PrismaClient } from "@prisma/client";
async function main() {
const prisma = new PrismaClient();
let data = await prisma.anki_lists.findMany();
let transformed = data.map((d) => ({
...d,
id: d.id.toString(), // id is `Buffer` so converting into a string for printing
}));
console.log(transformed);
prisma.$disconnect();
}
main(); |
Thank you! I was using an incorrect buffer encoding. I tried all of them except base64 lol. |
We'll be extending the raw api into something that returns type info in the protocol back to the client. Talked with @timsuchanek we should always add the type to the return values, so the client could then wrap it into an object if needed. Now the migrate GA and native types GA are bringing too much heat, so we agreed that we'll just do this in the next sprint. |
Example:
You get the point. |
Changed the title and labels to reflect this is a feature request now. |
Hey folks, This feature was implemented in prisma/prisma-engines#2847. It will be available in the next release under the Beware that enabling Thanks for reporting 🙏 |
Bug description
I am using

prisma.$queryRaw
for creating mapbox vector tiles from db using PostgreSQL and PostGISI expect get node.js Buffer in
mvt
field but prisma query engine serialize the db response to text and I can't correctly convert it to a bufferis not help!
How to reproduce
Expected behavior
prism should return a Buffer in place of text for binary data
Prisma information
Environment & setup
The text was updated successfully, but these errors were encountered: