문제

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