とくに解説とかはしない。めも。
db.yml
development:
adapter: 'sqlite3'
database: './list.db'
db.rb
require 'active_record'
require 'yaml'
class List < ActiveRecord::Base
end
config = YAML.load_file('./config/db.yml')
p config
ActiveRecord::Base.establish_connection config['development']
ActiveRecord::Schema.define do
unless ActiveRecord::Base.connection.tables.include? 'lists'
create_table :lists do |table|
table.column :user_name, :string
table.column :date_string, :string
end
end
end
main.rb
require_relative './db'
List.create(user_name: 'name', date_string: '2014-01-01')
List.find_by_user_name('name')