You can do:
results = repository(:default).adapter.query("SELECT...")
You'll get back an array of open structs representing the returned data.
Well, you don't technically need to specify :default. You can just do
repository.adapter.query().
The reason the method is on the adapter, and not directly on
repository, is because it is a SQL specific action. It makes sense for
a SQL adapter to accept a string to query, but that is not necessarily
the case for other kinds of databases.
It would be easy enough, of course, for you to add that yourself (or
turn it into a plugin).
module DataMapper
def query(sql)
repository.adapter.query(sql)
end
end
Heh. I actually quite like that idea of making a certain call ugly to
discourage it's use!
> DM is an ORM designed to fetch and store objects in a data store
> through a simple CRUD layer. It won't handle reporting very well,
> since there's no way to simply construct a non-trivial query for
> aggregate reporting in a way that will work with more than a handful
> of storage backends. Even describing non-trivial aggregate report
> queries between RDBMS' is a bit painful, but it gets insane when you
> throw in CouchDB or web APIs.
<snip other relevant stuff>
This is, however, an intractable problem, since for anything more than
trivial problems there is no "perfect" solution, simply best tools,
and this means making sacrifices.
In my current project the vast majority of DB access is blindingly
simple, the sort of problem that scaffolding can actually solve (at
least for the moment). I do, however, have a few queries that need in
DB reporting - I need to iterate over a set of objects, joining on to
a table and retrieving a count for joined objects for each row in the
first set. (actually, this is a simplification)
For now I have actually implemented this in an n+1 query style, with a
ruby loop. Unpleasant and unscalable, but works for me right now.
I like the idea of DM interfacing to Sequel. Pure Sequel is overkill
for this project, but I might look into this further...
Thanks
Emma