ruby 没有Rails的ActiveRecord w / o Migrations

Posted

tags:

篇首语:本文由小常识网(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
# db/config.yml

production:
      adapter: sqlite3
      database: db-prod
      encoding: utf8
      host: localhost
      port: 5432

development:
      adapter: sqlite3
      database: db-test
      encoding: utf8
      host: localhost
      port: 5432
require 'active_record_migrations'
ActiveRecordMigrations.load_tasks

# rake db:new_migration name=CreateUser options="name birth:date"
# rake db:migrate db=production
source 'https://rubygems.org'

gem 'active_record_migrations'
gem 'activerecord'
gem 'sqlite3'

以上是关于ruby 没有Rails的ActiveRecord w / o Migrations的主要内容,如果未能解决你的问题,请参考以下文章

ruby 没有Rails的ActiveRecord w / o Migrations

如何在没有rails的ruby中实现Application Record

Ruby On Rails 中的编组与 ActiveRecord 序列化

如何存储和比较:ActiveRecord 中的符号(Ruby on Rails)

如何在 Ruby on Rails 中查看给定 ActiveRecord 查询将生成的 SQL

Ruby on Rails 购物车错误“ActiveRecord_Associations_CollectionProxy”