Created
June 5, 2010 21:22
-
-
Save Whoops/427016 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sqlite3' | |
require 'active_record' | |
db = SQLite3::Database.new ('demo.db') | |
db.execute('DROP TABLE IF EXISTS demos') | |
db.execute('CREATE TABLE demos ( id TEXT PRIMARY KEY, data TEXT)') | |
ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a')) | |
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', | |
:database => 'demo.db') | |
db.close | |
class Demo < ActiveRecord::Base | |
end | |
foo=Demo.new(:data =>'bar') | |
fizz=Demo.new(:data => 'buzz') | |
#can't mass assign id | |
foo.id='foo' | |
fizz.id='fizz' | |
foo.save | |
fizz.save | |
puts Demo.find('foo').data | |
puts Demo.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment