1

如何在https://github.com/infused/dbf/中使用 rake 。我尝试在database.yml中编写这样的文本:

development:  
  adapter: dbf
  database: db/file.dbf
  pool: 5
  timeout: 5000

但它说,没有找到适配器activerecord-dbf-adapter
我只需要阅读 dbf 文件。
PS。我不能使用 JDBC 适配器。

更新
我想在支持 ActiveRecord 的 Rails 中使用 dbf 数据库,例如另一个数据库(例如 mysql)

4

2 回答 2

2

https://github.com/infused/dbf/上有一章“基本用法”可以回答您的问题。

require 'dbf'
table= DBF::Table.new("your_table.dbf")

database.yml是连接数据库的配置文件。如果您不想在整个 Rails 应用程序中连接到 dbf-db,则不得指定adapter: dbf. 这就是您收到此错误的原因。

我强烈建议您阅读http://guides.rubyonrails.org/getting_started.html上的指南。还可以在https://github.com/infused/dbf/上阅读 gem 的自述文件和 wiki 。

于 2012-02-22T13:43:17.453 回答
2

我认为您想将 dbf 与 ActiveRecord 一起使用,但这不是这个 gem 的作用。它只是提供了从 Ruby 读取 dbf 文件的能力。

要在您的应用程序中使用它,您可以编写一个类来实现您想要的所有常用方法并从那里继承,例如:

require 'dbf'
class DbfModel

  def initialize
    @table= DBF::Table.new("#{self.class.name}.dbf")
  end

  def find your_params_here
    @table.find your_params_here
  end

end

如果您想将 dbf 与 ActiveRecord 一起使用,您应该为它找到一些适配器,但我没有幸运地找到它。

于 2012-02-29T13:31:55.950 回答