18 Apr '12, 2am

Sequel for Ruby cheat sheet - All you need!!

cheat_sheet.rdoc doc/cheat_sheet.rdoc Last Update: 2011-07-16 11:31:03 -0700 Cheat Sheet Open a database require 'rubygems' require 'sequel' DB = Sequel.sqlite('my_blog.db') DB = Sequel.connect('postgres://user:password@localhost/my_db') DB = Sequel.postgres('my_db', :user => 'user', :password => 'password', :host => 'localhost') DB = Sequel.ado('mydb') Open an SQLite memory database Without a filename argument, the sqlite adapter will setup a new sqlite database in memory. DB = Sequel.sqlite Logging SQL statements require 'logger' DB = Sequel.sqlite '', :loggers => [Logger.new($stdout)] # or DB.loggers << Logger.new(...) Using raw SQL DB.run "CREATE TABLE users (name VARCHAR(255) NOT NULL, age INT(3) NOT NULL)" dataset = DB["SELECT age FROM users WHERE name = ?", name] dataset.map(:age) DB.fetch("SELECT name FROM users") do |row| p row[:name] end Create a dataset dataset ...

Full article: http://sequel.rubyforge.org/rdoc/files/doc/cheat_sheet_rd...

Tweets