0

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?

4

1 回答 1

2

你想用adapter.select. execute用于不返回结果的操作。

例子:

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

您可以在此处查看有关不同适配器方法的文档:
http ://rdoc.info/github/datamapper/dm-do-adapter/DataMapper/Adapters/DataObjectsAdapter

但是,如果所有需要的只是一个纯 SQLite 适配器,那么您应该查看类似sqlite3gem 的东西:http ://rubygems.org/gems/sqlite3

于 2013-09-03T05:06:48.130 回答