Coder Social home page Coder Social logo

Image type support? about tds HOT 9 CLOSED

markquezada avatar markquezada commented on August 16, 2024
Image type support?

from tds.

Comments (9)

mjaric avatar mjaric commented on August 16, 2024 1

@markquezada, What if field in your model is :binary instead of :string? I'm referring to original issue at top. Somehow I didn't notice it earlier.

For geometry, I'll see if ecto custom type could help

from tds.

josevalim avatar josevalim commented on August 16, 2024 1

@mjaric I believe the issue happens before the Ecto type, because TDS does not know how to decode this. We either need to explicitly support them all OR we could return unknown types as TDS.Raw{binary: ...}. And now people should be able to create Ecto types that encode/decode to raw. :)

from tds.

markquezada avatar markquezada commented on August 16, 2024

@mjaric @mobileoverlord @moogle19 any thoughts on this one? If you can point me in the right direction I'd happily create a PR to fix this. Thank you!

from tds.

mjaric avatar mjaric commented on August 16, 2024

@markquezada I'm a bit rusty, haven't work on driver for some time. But you can try to work with binary (varbinary(max) to be precise).

What do you think your system would benefit from actual image type?

from tds.

markquezada avatar markquezada commented on August 16, 2024

@mjaric thanks for getting back to me. I'm working with a legacy system that is already using the mssql image type so I can't really change it.

All I need is a way to get the binary string out of the db so I can render it as an image from a controller endpoint. Is there a way to get the driver to just return the raw string from the db? Even if not using it from within an ecto schema?

from tds.

mjaric avatar mjaric commented on August 16, 2024

The simplest way is to cast(columName as varbinary) in select. Then it will be picked up as binary in elixir.

You can create ecto custom type using above to pack it nicely. For raw tds usage, I was planning 2-3 years ago to add pluggable serialization bit I think it is not there (probably never done)

from tds.

markquezada avatar markquezada commented on August 16, 2024

Unfortunately since using a custom ecto type seems to first require the raw data to be decoded via the TDS adapter, it still failed when I went down that route.

That said, I was able to access the data directly, using cast as you suggested:

    query =
       from s in Student,
         select: fragment("CAST(? AS varbinary(max))", s.picture_data),
         where: s.id == ^id,
         where: not is_nil(s.picture_data)

     case Repo.one(query) do
       nil -> {:error, :no_image}
       binary_data -> {:ok, binary_data}
     end

Thanks!

from tds.

fnicastri avatar fnicastri commented on August 16, 2024

@mjaric facing something similar with geometry/geography type,
it would be nice to have a away to get the raw data from the db

from tds.

mjaric avatar mjaric commented on August 16, 2024

@fnicastri, I created issue #147 for geometry support, it is not that simple and I don't want to block image support

from tds.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.