Question

I'm using Datamapper+SqLite. I need to use a direct query like so:

adapter = DataMapper.repository(:default).adapter
adapter.execute("SELECT * FROM stuff")

How do I see the output of this thing? I see type DataObjects::Sqlite3::Result in irb? Also, any recommendations on how to see SQLite results, ala PHPMyAdmin for Mac?

Était-ce utile?

La solution

You want to use adapter.select. execute is meant for operations that do not return results.

Example:

> adapter.select('select * from posts')
=> [#<struct id=1, title="T1", body="B1">, 
    #<struct id=2, title="T2", body="B2">]

You can see the documentation on the different adapter methods here:
http://rdoc.info/github/datamapper/dm-do-adapter/DataMapper/Adapters/DataObjectsAdapter

But if all need is just a pure SQLite adapter then you should be looking at something like the sqlite3 gem instead: http://rubygems.org/gems/sqlite3

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top