-
-
Save cyberfox/916442 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sqlite3' | |
require 'sequel' | |
# Adding this monkey-patch makes it work on MacRuby. | |
module Sequel | |
class Dataset | |
def single_record | |
record = nil | |
clone(:limit=>1).each{|r| record = r; return r} | |
record | |
end | |
end | |
end | |
DB = Sequel.sqlite() | |
DB.create_table :entries do | |
primary_key :id | |
String :words | |
end | |
DB[:entries].insert(:words => "Hello MacRuby!") | |
puts "Querying for all entries records: #{DB[:entries].all.to_s}" | |
puts "Query for just the first record: #{DB[:entries].first}" | |
puts "Query for record based on id: #{DB[:entries].where(:id => 1).first.to_s}" | |
#results | |
# $ macruby database.rb | |
# Querying for all entries records: [{:id=>1, :words=>"Hello MacRuby!"}] | |
# Query for just the first record: | |
# Query for record based on id: | |
# $ rvm use 1.9.2 | |
# $ ruby database.rb | |
# Querying for all entries records: [{:id=>1, :words=>"Hello MacRuby!"}] | |
# Query for just the first record: {:id=>1, :words=>"Hello MacRuby"} | |
# Query for record based on id: {:id=>1, :words=>"Hello MacRuby!"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment