On Friday, June 1, 2012 10:47:20 AM UTC-7, Jeremy Evans wrote:
>
> On Friday, June 1, 2012 10:07:03 AM UTC-7, Joe Van Dyk wrote:
>>
>> Hi,
>>
>> There's been lots of activity in the postgresql world in the past couple 
>> years. Arrays, hstores, ranges, json, etc. AR's postgresql adapter in 4.0 
>> will have support for mapping ruby types to custom postgresql types (
>> https://github.com/rails/rails/pull/4775). 
>>
>> I've noticed that sequel, AR's postgresql adapter, and 
>> jdbc-activerecord-postgres all contain similar, but different parsers for 
>> handling those postgresql datatypes. Each of the ORMs have their own 
>> plugins for arrays, hstores, etc.
>>
>>
>> https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/postgresql/adapter.rb
>>
>> https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L119
>>
>> https://github.com/jeremyevans/sequel/blob/master/lib/sequel/adapters/postgres.rb#L86
>>
>> It seems like having a single gem for handling the postgresql parser code 
>> would be helpful.  Maybe this could be done before ActiveRecord 4.0?
>>
>> Thoughts?
>>
>
> I'm not opposed to extracting the parsers that Sequel uses for complex 
> types for use by other libraries.  In the array case, I'm using ruby's json 
> parser for integer/float arrays, and a custom pure-ruby parser for 
> string/numeric arrays.  In the hstore case, I'm using a strscan-based 
> parser.  The json type just uses ruby's json parser.  The range parser I 
> haven't written yet, but I'm assuming it'll be pure-ruby as well.
>
> I don't see value in extracting the handling/parsing for primitive types 
> such as integer/float/date, though.
>
> As long as the interested developers can agree on an API, I don't foresee 
> problems with your suggestion.
>
> Thanks,
> Jeremy
>

I'm not sure if this is what you mean by a "primitive type", but I have a 
postgresql domain like:

CREATE DOMAIN tanga_money AS numeric(19,2)                                 
                         
  CONSTRAINT not_negative CHECK ((VALUE >= (0)::numeric));

I use it for prices of things.

ActiveRecord 3.x (not sure if changed in 4.x?), both jdbc and regular:
1.9.3p0 :002 > Product.first.normal_price
 => "8.99" 
Note that it's a string.

Sequel:
1.9.3-p0-perf :011 > DB[:products].order(:id.desc).first[:normal_price]
 => #<BigDecimal:7fae1bbac748,'0.899E1',18(18)>                             
                                                                   
                                                                            
                        
1.9.3-p0-perf :012 > p Product.order(:id.desc).first.normal_price
 => #<BigDecimal:7fe85243c190,'0.899E1',18(18)>

It's a BigDecimal in Sequel, what I'd expect.

If Sequel and AR shared the same code that detected the types here, it 
would make it a lot easier to write code that accessed the same database.

-- 
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/-/GPUz6xf463gJ.
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.

Reply via email to