Guest User

Untitled

a guest
May 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. require 'rubygems'
  2. require 'active_record'
  3.  
  4. ddl = <<DDL
  5. create table if not exists rubyists (
  6. id integer not null primary key
  7. , name varchar(100) not null
  8. , city text not null
  9. );
  10. DDL
  11.  
  12. ActiveRecord::Base.establish_connection(
  13. :adapter => "sqlite3" ,
  14. :host => "localhost",
  15. :database => ":memory:" ,
  16. :username => "fake"
  17. )
  18. connection = ActiveRecord::Base.connection
  19. puts 'Class: ' + connection.class.to_s
  20. puts 'Is connected? ' + ActiveRecord::Base.connected?.to_s
  21. connection.execute( ddl )
  22.  
  23. class Rubyist < ActiveRecord::Base
  24. end
  25.  
  26. Rubyist.create( :name => 'Mitali Talim', :city => "Nashville, Tennessee" )
  27. Rubyist.create( :name => 'Sunil Kelkar', :city => "Pune, India" )
  28. Rubyist.create( :name => 'Adam Smith' , :city => "SanFransisco, USA" )
  29.  
  30. participant = Rubyist.find( :first )
  31. puts %{ #{ participant.name } stays in #{ participant.city } }
  32.  
  33. Rubyist.find( :first ).destroy
  34.  
  35. participant = Rubyist.find( :first )
  36. puts %{ #{ participant.name } stays in #{ participant.city } }
  37.  
  38. connection.disconnect!()
  39. puts 'Is connected? ' + ActiveRecord::Base.connected?.to_s
  40.  
  41. participant = Rubyist.find( :first )
  42. puts %{ #{ participant.name } stays in #{ participant.city } }
Add Comment
Please, Sign In to add comment