will / crystal-pg

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

Cannot read PG::{type}Array #149

Closed vladfaust closed 6 years ago

vladfaust commented 6 years ago

Hello,

require "db"
require "pg"

db = DB.open(ENV["DATABASE_URL"])
db.query("SELECT '{1,2}'") do |rs|
  values = rs.read(PG::Int16Array)
end
in lib/pg/src/pg/result_set.cr:98: undefined constant T

  def read(t : Array(T)?.class) : Array(T)? forall T
                     ^

I suppose the issue is in this recursive alias:

https://github.com/will/crystal-pg/blob/cafeb945be2003dd2d9b25620d693e4eab420e85/src/pg/decoders/array_decoder.cr#L108

/cc @will @asterite

vladfaust commented 6 years ago

Ah, so noone should read raw PG::{Type}Array. read(Array(Int16)) works as expected.