Skip to content

Instantly share code, notes, and snippets.

@jeremyevans
Forked from willgorman/gist:1293900
Created October 17, 2011 22:34
Show Gist options
  • Save jeremyevans/1294055 to your computer and use it in GitHub Desktop.
Save jeremyevans/1294055 to your computer and use it in GitHub Desktop.
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
module InstanceMethods
def before_create
seq_name = model.sequence
unless self.class.simple_pk.nil? or seq_name.nil?
self.send("#{self.primary_key.to_s}=", db.fetch("SELECT #{seq_name}.NEXTVAL FROM DUAL").all.first.values.first.to_i)
end
super
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment