You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PostgreSQL, MySQL and SQLite provide capabilities to store binary blobs:
SQLite has a BLOB data type
PostgreSQL has bytea and a Large Object feature, which stores the binary data in a separate table in a special format, and refers to that table by storing a value of type OID in your table.
Hi folks, I'm looking to store and access large arrays of binary data using PostgreSQL and Prisma, but it doesn't seem like the type that would make the most sense for my use case here (bytea) is supported by Prisma. Is there some possible workaround or plans to add this as a supported type?
Reacted by Ben Schattinger, Mikaël Vaivre, Marcel, Rod, Daniel, bergold, Jan Loewe, Eric Capps, Takeshi, Nick Pappas and 11 more
Same question here. We need it for user avatars and it doesn't make sense to me to keep around a postgres (pg) connection just to fetch the avatars once in a while...
Reacted by timgriffin89, Bojan Mitic, kooa, Simon Reinisch and toph
@onmyflow I think it's common practice to offload image storing to a filesystem, i.e. S3 and store the URL or file path in the DB. Is there any particular reason you have decided to store these images in the DB itself?
@timgriffin89 Is this data of a specific type, i.e. images? How large is this binary data? Have you considered storing this outside of the data? If you have discarded this option, can you expand on why?
@albertoperdomo I can't speak to their use cases, but I can say that for quick prototypes or internal apps it can be convenient to centralize everything in postgres, particularly if file storage needs are limited and file sizes small and there are not many concurrent users. I'm not aware of any scenario where this is the best thing to do, but there are places where it makes sense to save effort. It would be nice to have blobs as a supported type in Prisma.
@albertoperdomo what @cappslock said. I'm aware of the implications that come with storing any kind of largish file in the db. But just because that might be a bad idea most of the times, the few times where one really needs to do stuff like this should be at least supported natively by just passing a Buffer to the field name and prisma handling the rest.
My current solution is to base64 encode files, concatenate a raw query with that string and do a decode() inside of the SQL query. This solution, while working perfectly fine, has quite some performance overhead. That being said, i myself aren't too sure how one would implement it in a better way.
The workaround described by @onmyflow seems sensitive, albeit having performance overheads, for sure.
I think support for binary type could be covered by future work on native types to support binary among others.
Update: changed my comment as #3447 does not seem to cover adding new types. This would be addressed in a separate issue.
Update: We actually consider #3447 the main issue to address native types. Will leave this issue around to track the request for binary especifically./
I second this, same case as @onmyflow's. Is this part of any roadmap? Or is this "included" in #3447 and supposed to be not be addressed in particular?
@simonwep@onmyflow : Binary types are available as part of the effort for native types. They have been shipped in Preview with the 2.11.0 release. Feedback is very much appreciated!
Reacted by Simon Reinisch, Emanuel Jöbstl and Eric Capps
Activity
dnlsndr commentedon Jun 26, 2020
Same question here. We need it for user avatars and it doesn't make sense to me to keep around a postgres (pg) connection just to fetch the avatars once in a while...
albertoperdomo commentedon Sep 4, 2020
@onmyflow I think it's common practice to offload image storing to a filesystem, i.e. S3 and store the URL or file path in the DB. Is there any particular reason you have decided to store these images in the DB itself?
albertoperdomo commentedon Sep 4, 2020
@timgriffin89 Is this data of a specific type, i.e. images? How large is this binary data? Have you considered storing this outside of the data? If you have discarded this option, can you expand on why?
cappslock commentedon Sep 4, 2020
@albertoperdomo I can't speak to their use cases, but I can say that for quick prototypes or internal apps it can be convenient to centralize everything in postgres, particularly if file storage needs are limited and file sizes small and there are not many concurrent users. I'm not aware of any scenario where this is the best thing to do, but there are places where it makes sense to save effort. It would be nice to have blobs as a supported type in Prisma.
EDIT: I guess this is a use case: https://wiki.postgresql.org/wiki/BinaryFilesInDB#When_should_files_be_stored_in_the_database.3F
dnlsndr commentedon Sep 4, 2020
@albertoperdomo what @cappslock said. I'm aware of the implications that come with storing any kind of largish file in the db. But just because that might be a bad idea most of the times, the few times where one really needs to do stuff like this should be at least supported natively by just passing a Buffer to the field name and prisma handling the rest.
My current solution is to base64 encode files, concatenate a raw query with that string and do a
decode()inside of the SQL query. This solution, while working perfectly fine, has quite some performance overhead. That being said, i myself aren't too sure how one would implement it in a better way.albertoperdomo commentedon Sep 4, 2020
Thanks for following up with additional context @cappslock @onmyflow.
albertoperdomo commentedon Sep 4, 2020
The workaround described by @onmyflow seems sensitive, albeit having performance overheads, for sure.
I think support for binary type could be covered by future work on native types to support binary among others.
Update: changed my comment as #3447 does not seem to cover adding new types. This would be addressed in a separate issue.
[-]Storing and Accessing Binary Data Using PostgreSQL/Prisma[/-][+]Support for binary type [/+]albertoperdomo commentedon Sep 9, 2020
Update: We actually consider #3447 the main issue to address native types. Will leave this issue around to track the request for binary especifically./
simonwep commentedon Nov 20, 2020
I second this, same case as @onmyflow's. Is this part of any roadmap? Or is this "included" in #3447 and supposed to be not be addressed in particular?
mavilein commentedon Nov 20, 2020
@simonwep @onmyflow : Binary types are available as part of the effort for native types. They have been shipped in Preview with the 2.11.0 release. Feedback is very much appreciated!
albertoperdomo commentedon Feb 3, 2021
Binary types are now also supported in Prisma Migrate since 2.15.0 (in Preview). Documentation can be found here.
albertoperdomo commentedon Feb 3, 2021
Feedback for the native types feature can be shared here: #4045
kentcdodds commentedon Jul 14, 2021
New URL for the byte type: https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#bytes
lambrospetrou commentedon Nov 24, 2021
Why is SQLite's

BLOBnot supported? I can see that it's the only one missing...pantharshit00 commentedon Nov 29, 2021
@lambrospetrou Please open a feature request for it. Then we can track that and add the mapping.
lambrospetrou commentedon Dec 2, 2021
I opened #10537 for tracking this. Thanks :)