On Friday, June 27, 2014 1:18:43 PM UTC-7, Andreas Yankopolus wrote:
>
> I'm building a class that will iterate across a range of databases and
> perform the same query on each one. The queries return an array of numbers
> that will get passed on for statistical analysis. I want to pass in the
> names of the databases, the table, and the query to perform in the class
> constructor.
>
> The meat of the class would look like
>
> database_names.each.with_index do |database_name, idx|
> db = Sequel.connect(database_name)
> result[idx] = db[<:table>].<query>
> db.close
> end
>
> Passing in the database names and symbol for the table is easy enough.
> Passing in the query is tricky.
>
> I've been working with .send() and making good progress. For example:
>
> table = :my_table
> query = [:select, :NodeId]
>
> db[table].send(*query)
>
> => #<Sequel::SQLite::Dataset: "SELECT `NodeId` FROM `my_table`
>
> But I not getting anywhere with where clauses.
>
> query = [[:select, :NodeId], [:where, :Timestamp, :"=>", :"60"]]
>
That's because where(:Timestamp, :=>, :"60") is not valid Sequel code. Is
there a reason you expected that to work?
> db[table].send(*query[0]).send(*query[1]) # Obviously automate the
> unrolling of a variable-length query
>
> => #<Sequel::SQLite::Dataset: "SELECT `NodeId` FROM `my_table` WHERE
> (`Timestamp` AND `=>` AND `60`)">
>
> How can I get that where clause to evaluate to "WHERE ('Timestamp' = 60)"?
>
You should probably use a hash:
[:where, {:Timestamp => 60}]
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.