On Wednesday, April 11, 2012 8:21:14 AM UTC-7, jan zimmek wrote:
>
> hello,
>
> i really appreciate the latest support for pg_array and pg_hstore in
> sequel, but is there any support for postgresql composite types
> (http://www.postgresql.org/docs/9.1/static/rowtypes.html) ?
>
> reading a composite type with sequel is possible, but it is only
> returned as a string and is nearly useless in this form. translating a
> custom type into some ruby equivalent structure (nested array/hash)
> should be possible for the simple cases. getting all the escaping/
> quoting (nested) right is where things get complicated.
>
> maybe someone is already working on this - i would really like to
> know.
>
I can't see of a way to handle this on a generalized basis, such that you
could just load an extension and row types would be handled correctly
automatically. At the very least, you'll need to tell Sequel what the type
and field names to use for the row. You can use the pg_array/pg_hstore
extensions as a guide for what to do. I imagine the API like this:
Sequel.extension :pg_composite_types
# Sequel::Postgres::CompositeType method returns a subclass for the
# specific row type. The block given to the method is handled similarly
# to a create table block, using instance eval, setting the names and
# types of the fields in order.
#
# This method would also populate Sequel::Postgres::NAMED_TYPES
# with a callable for the :type_name so that the Database object
# would transform the value into an instance of the class.
Sequel::Postgres::CompositeType(:type_name) do
Integer :field1
String :field2
Float :field3
end
I don't have plans to implement this myself in the near future, but if
someone else wants to write the extension, I'll certainly consider it for
inclusion in Sequel.
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/lhQmOjtoH50J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.