Skip to content

Instantly share code, notes, and snippets.

View jeremyevans's full-sized avatar

Jeremy Evans jeremyevans

View GitHub Profile
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
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
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)
$ 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