will / crystal-pg

a postgres driver for crystal
BSD 3-Clause "New" or "Revised" License
462 stars 77 forks source link

Error: can't cast to JSON::Any #263

Open ejstembler opened 1 year ago

ejstembler commented 1 year ago

I originally opened an issue on crystal-db, though Brian pointed out a change here. I've read though the change, however, I'm still not clear how to update my code to accomodate the new strategy.


I'm upgrading from Crystal 1.5.0, crystal-db 0.10.0, crystal-pg 0.23.1 and I'm seeing this error:

Error: can't cast (Array(PG::BoolArray) | Array(PG::CharArray) | Array(PG::Float32Array) | Array(PG::Float64Array) | Array(PG::Int16Array) | Array(PG::Int32Array) | Array(PG::Int64Array) | Array(PG::NumericArray) | Array(PG::StringArray) | Array(PG::TimeArray) | Array(PG::UUIDArray) | Bool | Char | Float32 | Float64 | Int16 | Int32 | Int64 | JSON::PullParser | PG::Geo::Box | PG::Geo::Circle | PG::Geo::Line | PG::Geo::LineSegment | PG::Geo::Path | PG::Geo::Point | PG::Geo::Polygon | PG::Interval | PG::Numeric | Slice(UInt8) | String | Time | UInt32 | UUID | Nil) to JSON::Any

from:

db.scalar(sql).as(JSON::Any)

In Postgres I have a function which RETURNS jsonb. JSON::Any worked fine for me before. I don't want to cast the JSON to a serializable class because the JSON is too verbose with nested data.

Any tips on what I need to change to keep the JSON::Any output? Or, is that a lost cause?