Module: Sequel::SetOverrides
- Defined in:
- lib/sequel/extensions/set_overrides.rb
Instance Method Summary collapse
-
#insert_sql(*values) ⇒ Object
Set overrides/defaults for insert hashes.
-
#set_defaults(hash) ⇒ Object
Set the default values for insert and update statements.
-
#set_overrides(hash) ⇒ Object
Set values that override hash arguments given to insert and update statements.
-
#update_sql(values = {}) ⇒ Object
Set overrides/defaults for update hashes.
Instance Method Details
#insert_sql(*values) ⇒ Object
Set overrides/defaults for insert hashes
28 29 30 31 32 33 34 |
# File 'lib/sequel/extensions/set_overrides.rb', line 28 def insert_sql(*values) if values.size == 1 && (vals = values.first).is_a?(Hash) super(merge_defaults_overrides(vals)) else super end end |
#set_defaults(hash) ⇒ Object
Set the default values for insert and update statements. The values hash passed to insert or update are merged into this hash, so any values in the hash passed to insert or update will override values passed to this method.
DB[:items].set_defaults(:a=>'a', :c=>'c').insert(:a=>'d', :b=>'b')
# INSERT INTO items (a, c, b) VALUES ('d', 'c', 'b')
42 43 44 |
# File 'lib/sequel/extensions/set_overrides.rb', line 42 def set_defaults(hash) clone(:defaults=>(@opts[:defaults]||{}).merge(hash)) end |
#set_overrides(hash) ⇒ Object
Set values that override hash arguments given to insert and update statements. This hash is merged into the hash provided to insert or update, so values will override any values given in the insert/update hashes.
DB[:items].set_overrides(:a=>'a', :c=>'c').insert(:a=>'d', :b=>'b')
# INSERT INTO items (a, c, b) VALUES ('a', 'c', 'b')
52 53 54 |
# File 'lib/sequel/extensions/set_overrides.rb', line 52 def set_overrides(hash) clone(:overrides=>hash.merge(@opts[:overrides]||{})) end |