Skip to content

Instantly share code, notes, and snippets.

@Whoops
Created June 5, 2010 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Whoops/427016 to your computer and use it in GitHub Desktop.
Save Whoops/427016 to your computer and use it in GitHub Desktop.
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