(I'm new to Sequel: please harshly correct any silly mistakes or
assumptions you think I may be making.)
Summary:
When Sequel converts a Dataset into an Array, it does a poor job of
making the entries convenient to work with. I'll show you what I mean,
and what I'd ideally like.
Details:
I'm using Sequel 2.5 with SQLite 3.5.6 on a Ramaze project. Here's
what I get when using #group_and_count:
phrogz$ sqlite3 model/bugs.db
SQLite version 3.5.6
Enter ".help" for instructions
sqlite> .schema tags
CREATE TABLE tags (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bug_id INTEGER NOT NULL,
name TEXT NOT NULL
);
sqlite> .quit
phrogz$ ramaze -c
...
[2008-09-10 21:05:18] INFO PRAGMA table_info(`tags`)
...
[2008-09-10 21:05:18] INFO Ramaze already started, skipped start.
irb(main):001:0> Tag.db_schema
=>
{:name=>{:type=>nil, :numeric_precision=>nil, :allow_null=>false,
:max_chars=>nil, :primary_key=>false, :db_type=>"TEXT", :default=>nil},
:bug_id=>{:type=>nil, :numeric_precision=>nil, :allow_null=>false,
:max_chars=>nil, :primary_key=>false, :db_type=>"INTEGER", :default=>nil},
:id=>{:type=>nil, :numeric_precision=>nil, :allow_null=>true, :max_chars=>nil,
:primary_key=>true, :db_type=>"INTEGER", :default=>nil}}
irb(main):002:0> t1 = Tag.group_and_count(:name).first
[2008-09-10 21:05:43] INFO SELECT `name`, count(*) AS `count` FROM
`tags` GROUP BY `name` ORDER BY `count` LIMIT 1
=> #<Tag @values={:count=>"1", :"`name`"=>"amx"}>
irb(main):003:0> t1.name
=> nil
irb(main):004:0> t1.count
NoMethodError: undefined method `count' for #<Tag
@values={:count=>"1", :"`name`"=>"amx"}>
from (irb):4
irb(main):005:0> t1[:count].class
=> String
irb(main):006:0> t1[:name]
=> nil
irb(main):007:0> t1[:"`name`"]
=> "amx"
That the entries in the Array must be referenced using Hash notation
is unfortunate but not unacceptable.
That the value of count comes back as a string is really annoying,
almost on the verge of being a bug.
That the name of the existing column must be specified using symbol-
literal notation with backquotes is what pushed me over the edge to
getting online and reporting this.
Thanks to the authors for a great library. Is the above a known issue,
a consequence of working with SQLite specifically, or maybe (fingers
crossed) something surprising perhaps resulting from a particular
configuration on my machine?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
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
-~----------~----~----~----~------~----~------~--~---