如何使用ActiveRecord Rails的外? [英] How to use ActiveRecord outside Rails?

查看:144
本文介绍了如何使用ActiveRecord Rails的外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个Rails应用程序的基础上六角形结构。

I'm building a Rails application based on hexagonal architecture.

我的一个适配器的存储适配器(保持为宝石),管理访问数据库,并提供简单的界面的Rails应用程序存储和查询数据的数据库。

One of my adapters is storage adapter (maintained as a gem) that manages access to database and provides simple interface for rails application to store and query data in database.

我想使用的ActiveRecord 在这个创业板上市的所有任务(创建,迁移,滴,回滚),用于管理数据库。

I'd like to use ActiveRecord in this gem with all rake tasks (create, migrate, drop, rollback) for managing database.

我如何使用AR外轨,但所有rake任务?

How can I use AR outside rails, but with all rake tasks?

推荐答案

就像任何其他创业板​​安装它

Install it like any other gem

gem install activerecord

然后配置它的地方像这样

Then you configure it somewhere like this

ActiveRecord::Base.establish_connection(
  :adapter  => 'mysql',
  :database => 'database',
  :username => 'user',
  :password => 'password',
  :host     => 'localhost')

然后模型可以继承是正常的的ActiveRecord :: Base的

Models can then inherit as normal from ActiveRecord::Base

您得到所有​​的耙任务,但你必须做一些额外的配置,因为你不会有Rails的。下面是如何配置这些东西的ActiveRecord里面的链接。

You get all of the rake tasks but you do have to do some extra configuration since you will not have the Rails. Here is the link inside of activerecord for how to configure that stuff.

<一个href="https://github.com/rails/rails/blob/master/activerecord/lib/active_record/tasks/database_tasks.rb">Database任务

这篇关于如何使用ActiveRecord Rails的外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆