Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'active_record'
- ddl = <<DDL
- create table if not exists rubyists (
- id integer not null primary key
- , name varchar(100) not null
- , city text not null
- );
- DDL
- ActiveRecord::Base.establish_connection(
- :adapter => "sqlite3" ,
- :host => "localhost",
- :database => ":memory:" ,
- :username => "fake"
- )
- connection = ActiveRecord::Base.connection
- puts 'Class: ' + connection.class.to_s
- puts 'Is connected? ' + ActiveRecord::Base.connected?.to_s
- connection.execute( ddl )
- class Rubyist < ActiveRecord::Base
- end
- Rubyist.create( :name => 'Mitali Talim', :city => "Nashville, Tennessee" )
- Rubyist.create( :name => 'Sunil Kelkar', :city => "Pune, India" )
- Rubyist.create( :name => 'Adam Smith' , :city => "SanFransisco, USA" )
- participant = Rubyist.find( :first )
- puts %{ #{ participant.name } stays in #{ participant.city } }
- Rubyist.find( :first ).destroy
- participant = Rubyist.find( :first )
- puts %{ #{ participant.name } stays in #{ participant.city } }
- connection.disconnect!()
- puts 'Is connected? ' + ActiveRecord::Base.connected?.to_s
- participant = Rubyist.find( :first )
- puts %{ #{ participant.name } stays in #{ participant.city } }
Add Comment
Please, Sign In to add comment