篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 没有Rails的ActiveRecord w / o Migrations相关的知识,希望对你有一定的参考价值。
require 'rubygems'
require 'active_record'
require 'yaml'
require 'logger'
# If you need migrations, you will want to modify the dbconfig to 'config.yml'
# establish connection for appropriate environment
dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)
# Log to file or stdout
# ActiveRecord::Base.logger = Logger.new(File.open('database.log')
ActiveRecord::Base.logger = Logger.new(STDERR)
class User < ActiveRecord::Base
end
puts User.count
# SQL (0.000277) SELECT count(*) AS count_all FROM users
# 6
adapter: mysql
database: database
username: user
password: password
host: localhost