> Well, Sequel::SQL::Blob is a String subclass, so it should still get
>> wrapped in a UUID. Can you post the code you are using?
>>
>
class Model < Sequel::Model(:model)
plugin :prepared_statements
plugin :prepared_statements_associations
plugin :typecast_on_load, :id
one_to_many :assocs
def id=(v)
super(UUIDTools::UUID.parse_raw(v))
end
end
class UUIDTools::UUID
def sql_literal(ds)
"uuid2binary(#{ds.literal(to_s)})"
end
end
m1 = Model.first => #<Model
@values={:id=>"\u00DB~\u00E4\u00C0\u00CA\u00C5\u0011\u00E1\u0085\u00E9\u00B8\u00F6\u00B1\u0013A'"}>
m1.id => "db7ee4c0-cac5-11e1-85e9-b8f6b1134127"
m1.id.class => Sequel::SQL::Blob
When I added this:
class Model
def id
UUIDTools::UUID.parse_raw(super)
end
end
Obviously, I get a UUID and the literalizer works as expected. Perhaps I am
misunderstanding what typecast_on_load is actually for.
Shouldn't m1.id.class be UUIDTools::UUID? Or does calling "super" then
force it to do to_s (that's what it seems like it's doing)?
If there is some way for me to simply subclass Sequel::SQL::Blob with some
other class and assign that to that column, I think we're gold with these
changes. prepared_statements, prepared_statements_associations and SQL
function literals. I'm ultimately going to want to mess with the way said
subclass's as_json method works too, since this would kill multiple birds
with one stone and, I believe, be the cleanest way of handling this.
(That's a pretty large assumption on my part though.)
If you want to do that in the query that retrieves the row:
>
> Model.dataset = Model.dataset.select(Sequel.function(:binary2uuid,
> :id).as(:id), ...)
>
> I don't think that's a good option, though, since then it should show up
> as a normal string.
>
Yeah, it's not. prepared_statements_associations fixes the problem this
"solution" was intended for.
> Are you also using the prepared_statements_associations plugin?
>
No, because apparently I'm a doofus. That solves a large part of the
association dilemma. If I want to do any sort of complex querying through
the dataset directly, I can pass in an sql_function which should do
basically everything want. This solves a bunch of things.
--
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/-/hXIvoXmRABYJ.
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.