This file contains 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
$ ruby -I lib bin/sequel -E sqlite:/ | |
Your database is stored in DB... | |
irb(main):001:0> class AddFoosMigration < Sequel::Migration | |
irb(main):002:1> def up | |
irb(main):003:2> create_table :foos do | |
irb(main):004:3* primary_key :id | |
irb(main):005:3> string :name | |
irb(main):006:3> end | |
irb(main):007:2> end |
This file contains 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
class API::Comment < Sequel::Model(:group_audits) | |
# Comments, as we're interested in them, are review_videos and add_videos. | |
reviews = API::Comment.filter(:group_audits__action => 'review_video') | |
adds = API::Comment.filter( | |
{:group_audits__action => 'add_video'} & | |
(:length.sql_function(:group_audits__text) > 0) | |
) | |
set_dataset reviews.union(adds, :from_self=>false) |
This file contains 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
class Metrics | |
def self.by_day(uid) | |
DB.synchronize do | |
DB.run "SET search_path TO rpt, dx" | |
return "The UUID is not valid, please try again." unless cid = DB[:dx_campaign].where(:object_uid => uid).get(:campaign_id) | |
DB["SELECT r.created_dt as \"date\", sum(clicks) as \"clicks\", sum(impressions) as \"impressions\", sum(actions) as \"actions\", sum(spend)/1000000 as \"spend\", sum(spend)/1000000 / sum(actions) as CPA FROM rpt.rpt_exchange_daily r WHERE campaign_id = #{cid} GROUP BY r.created_dt order by r.created_dt"].all | |
end | |
end | |
end |
This file contains 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
def test_changes | |
@db.execute("create table foo ( a integer primary key, b integer )") | |
assert_equal 0, @db.changes | |
@db.execute("insert into foo (b) VALUES (1)") | |
assert_equal 1, @db.changes | |
@db.execute("update foo set b = b + ? where b = ?", [2, 1]) | |
assert_equal 1, @db.changes | |
assert_equal [[3]], @db.execute("select b from foo") | |
end |
This file contains 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
class User < Sequel::Model | |
one_to_many :posts | |
many_to_many :tags, :right_key=>:id, :right_primary_key=>:post_id, :join_table=>:posts | |
end |
This file contains 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
filter(:name => ["company_importer_created", "manual_txn_created"]). | |
filter("day_num >= ?", day_num). | |
filter("year_num >= ?", year_num). | |
filter(:engagement_type_str => "Initial"). |
This file contains 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
<% | |
BlogPost.select(:headline, 'substring(body from "^.*?</p>")'.as(:body_preview)). | |
order(:post_date.desc).all do |post| | |
%> | |
<div> | |
<h2><%=post.headline%></h2> | |
<%==post[:body_preview]%> | |
</div> | |
<% end %> |
This file contains 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
#! /usr/bin/env ruby | |
require 'rubygems' | |
require 'sequel' | |
# Setup schema correctly | |
TestDatabase.down | |
TestDatabase.up | |
TestSetup.down |
This file contains 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
module Sequel | |
module Plugins | |
module OracleSequence | |
def self.configure(model, seq=nil) | |
model.sequence = seq || model.dataset.opts[:sequence] | |
model.dataset = model.dataset.sequence(nil) if model.dataset.opts[:sequence] | |
end | |
module ClassMethods | |
attr_accessor :sequence | |
end |
This file contains 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
#! /usr/bin/env jruby | |
require 'rubygems' | |
require 'sequel' | |
DB = Sequel.sqlite | |
DB.create_table? :test do | |
primary_key :id | |
foreign_key :parent_id, :test, :on_delete => :set_null |
OlderNewer