Sunday, October 16, 2011

Reinstalling Sequel

My installed Sequel was acting strange. It crashed hard to corrupt my file systems, resulting my Ubuntu not being able to start up. So I decided to reinstall it.


0. Resources
Sequel home page: http://sequel.rubyforge.org/


1. Uninstall Sequel
$ sudo gem uninstall sequel
Select gem to uninstall:
 1. sequel-3.26.0
 2. sequel-3.27.0
 3. All versions
> 3
Successfully uninstalled sequel-3.26.0
Successfully uninstalled sequel-3.27.0

2. Install Sequel
$ sudo gem install sequel
Successfully installed sequel-3.28.0
1 gem installed
Installing ri documentation for sequel-3.28.0...
Installing RDoc documentation for sequel-3.28.0...

3. Test Sequel
$ irb
irb(main):001:0> require 'sequel'
=> true
irb(main):002:0> DB = Sequel.sqlite
=> #
irb(main):003:0> DB.create_table :items do
irb(main):004:1* primary_key :id
irb(main):005:1> String :name
irb(main):006:1> Float :price
irb(main):007:1> end
=> nil
irb(main):008:0> items = DB[:items]
=> #
irb(main):009:0> items.insert(:name => 'iphone', :price => 450)
=> 1
irb(main):010:0> items.insert(:name => 'xphone', :price => 550)
=> 2
irb(main):011:0> items.insert(:name => 'zphone', :price => 650)
=> 3
irb(main):012:0> puts "Items count: #{items.count}"
Items count: 3
=> nil
irb(main):013:0> puts "Average price is: #{items.avg(:price)}"
Average price is: 550.0
=> nil

4. Test Sequel (continues)
irb(main):014:0> PGDB = Sequel.connect('postgres://localhost/mydb?user=socrateos&password=secret')
=> #
irb(main):015:0> PGDB.create_table :items do
irb(main):016:1* primary_key :id
irb(main):017:1> String :name
irb(main):018:1> Float :price
irb(main):019:1> end
=> nil
irb(main):020:0> pgitems = PGDB[:items]
=> #
irb(main):021:0> pgitems.insert(:name => 'Camera A', :price => 1000)
=> 1
irb(main):022:0> pgitems.insert(:name => 'Camera B', :price => 2000)
=> 2
irb(main):023:0> pgitems.insert(:name => 'Camera C', :price => 3000)
=> 3
irb(main):024:0> puts "Item count: #{pgitems.count}"
Item count: 3
=> nil
irb(main):025:0> puts "Average price: #{pgitems.avg(:price)}"
Average price: 2000.0
=> nil

5. Finish Testing Sequel
irb(main):026:0> DB.disconnect
=> []
irb(main):027:0> PGDB.disconnect
=> []
irb(main):028:0> quit

No comments:

Post a Comment