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
# in sequel/plugins/foo.rb | |
module Sequel::Plugin::Foo | |
def self.apply(model) | |
model.plugin :timestamps, :create => :created_on, :update => :updated_on | |
model.plugin :validation_helpers | |
model.many_to_one :user | |
end | |
module InstanceMethods | |
# Note that it's probably a bad idea to override initialize unless you |
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
Calculating ------------------------------------- | |
AR new 1110 i/100ms | |
AR new args 479 i/100ms | |
AR create 57 i/100ms | |
AR find 131 i/100ms | |
------------------------------------------------- | |
AR new 13570.5 (±5.4%) i/s - 67710 in 5.003359s | |
AR new args 5271.7 (±6.5%) i/s - 26345 in 5.018283s | |
AR create 576.4 (±6.2%) i/s - 2907 in 5.062781s | |
AR find 1357.2 (±4.2%) i/s - 6812 in 5.027665s |
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
one: {:name=>"Acme Enterprises, Inc.", :commplanname=>"All Transactions", :policynum=>"21IL909GL341234", :class=>"WORK", :billingtype=>"D", :term=>"A", :territory=>nil, :location=>1, :effective=>2008-10-05 00:00:00 -0500, :expires=>2009-10-04 00:00:00 -0500, :cancelled=>false, :decverified=>nil, :totprem=>#<BigDecimal:1d2da07,'0.1492E4',4(12)>, :policyfee=>#<BigDecimal:1e80cc2,'0.0',1(4)>, :adminfee=>#<BigDecimal:19db869,'0.0',1(4)>, :tax=>#<BigDecimal:1b5f860,'0.0',1(4)>, :otherfee=>#<BigDecimal:1c5822c,'0.0',1(4)>} | |
two: Acme Enterprises, Inc. |
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
# In-memory test database | |
# The schema has been simplified for the discussion (yes, it should have some domain_id somewhere !) | |
# | |
# Values in the content field for a SOA, are, in order : | |
# ns email serial refresh retry expiry minimum | |
DB = Sequel.sqlite | |
DB.run "CREATE TABLE records (name VARCHAR(255) PRIMARY KEY NOT NULL, type VARCHAR(5), content VARCHAR(255))" | |
DB.run "INSERT INTO records VALUES ('example.com', 'SOA', 'ns.example.com root.example.com 2012333335 28800 86400 3600000 86400')" | |
# Just an assert function for basic testing |
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
#! /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 |
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
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 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
#! /usr/bin/env ruby | |
require 'rubygems' | |
require 'sequel' | |
# Setup schema correctly | |
TestDatabase.down | |
TestDatabase.up | |
TestSetup.down |
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
<% | |
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 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
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 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
class User < Sequel::Model | |
one_to_many :posts | |
many_to_many :tags, :right_key=>:id, :right_primary_key=>:post_id, :join_table=>:posts | |
end |
NewerOlder