简体   繁体   English

使用活动记录独立访问数据库

[英]Acessing a database stand alone using active record

Is it possible to obtain details about a schema and get the table objects using a stand alone active record connection. 是否有可能使用独立的活动记录连接获取有关架构的详细信息并获取表对象。 I am trying to do something like this 我正在尝试做这样的事情

require'rubygems'
gem 'activerecord'
require 'activerecord'
ActiveRecord::Base.establish_connection(
  :adapter  => "mysql",
  :host     => "localhost",
  :username => "root",
  :database => "test_database"
)

Is it possible to access the tables of the db using this connection object. 是否可以使用此连接对象访问数据库的表。

Yes, it is perfectly possible to use ActiveRecord without Rails. 是的,完全可以使用没有Rails的ActiveRecord。

You can also use standalone_migrations gem to manage ActiveRecord environment outside of Rails: https://github.com/thuss/standalone-migrations . 您还可以使用standalone_migrations gem在Rails之外管理ActiveRecord环境: https : //github.com/thuss/standalone-migrations

Have you try to load all Active Support? 您是否尝试加载所有活动支持?

In order to have a near-zero default footprint, Active Support does not load anything by default. 为了使默认足迹几乎为零,默认情况下,Active Support不加载任何内容。 It is broken in small pieces so that you can load just what you need 它被粉碎成小块,以便您可以加载所需的东西

require 'active_support/all' 

Active Support Core Extensions 主动支持核心扩展

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM