Skip to content

Support for binary type  #1747

Closed
Closed

Description

@timgriffin89

Problem

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.
  • MySQL has BINARY and VARBINARY

Prisma does not support these data types.

Suggested solution

Add support for a binary type in PSL.

Alternatives

@onmyflow describes a workaround below.

Additional context

Original issue

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?

Activity

  1. added
    topic: client types
    on Mar 2, 2020
  2. added
    kind/feature
    on Mar 4, 2020
  3. dnlsndr commented on Jun 26, 2020

    @dnlsndr

    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...

  4. albertoperdomo commented on Sep 4, 2020

    @albertoperdomo
    Contributor

    @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?

  5. albertoperdomo commented on Sep 4, 2020

    @albertoperdomo
    Contributor

    @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?

  6. cappslock commented on Sep 4, 2020

    @cappslock

    @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

  7. dnlsndr commented on Sep 4, 2020

    @dnlsndr

    @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.

  8. albertoperdomo commented on Sep 4, 2020

    @albertoperdomo
    Contributor

    Thanks for following up with additional context @cappslock @onmyflow.

  9. albertoperdomo commented on Sep 4, 2020

    @albertoperdomo
    Contributor

    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.

  10. changed the title [-]Storing and Accessing Binary Data Using PostgreSQL/Prisma[/-] [+]Support for binary type [/+] on Sep 4, 2020
  11. albertoperdomo commented on Sep 9, 2020

    @albertoperdomo
    Contributor

    Update: We actually consider #3447 the main issue to address native types. Will leave this issue around to track the request for binary especifically./

  12. simonwep commented on Nov 20, 2020

    @simonwep

    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?

  13. mavilein commented on Nov 20, 2020

    @mavilein
    Contributor

    @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!

  14. albertoperdomo commented on Feb 3, 2021

    @albertoperdomo
    Contributor

    Binary types are now also supported in Prisma Migrate since 2.15.0 (in Preview). Documentation can be found here.

  15. albertoperdomo commented on Feb 3, 2021

    @albertoperdomo
    Contributor

    Feedback for the native types feature can be shared here: #4045

  16. kentcdodds commented on Jul 14, 2021

    @kentcdodds
  17. lambrospetrou commented on Nov 24, 2021

    @lambrospetrou

    Why is SQLite's BLOB not supported? I can see that it's the only one missing...
    Screenshot 2021-11-24 at 12 46 36

  18. pantharshit00 commented on Nov 29, 2021

    @pantharshit00
    Contributor

    @lambrospetrou Please open a feature request for it. Then we can track that and add the mapping.

  19. lambrospetrou commented on Dec 2, 2021

    @lambrospetrou

    @lambrospetrou Please open a feature request for it. Then we can track that and add the mapping.

    I opened #10537 for tracking this. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featuretopic: client typestopic: native database typestopic: schema

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions