質問

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?

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top