module Sequel::Plugins::PreparedStatements::InstanceMethods

Private Instance Methods

_insert_raw(ds) click to toggle source

Use a prepared statement to insert the values into the model's dataset.

Calls superclass method
    # File lib/sequel/plugins/prepared_statements.rb
129 def _insert_raw(ds)
130   if use_prepared_statements_for?(:insert)
131     _set_prepared_statement_server(model.send(:prepared_insert, @values.keys)).call(@values)
132   else
133     super
134   end
135 end
_insert_select_raw(ds) click to toggle source

Use a prepared statement to insert the values into the model's dataset and return the new column values.

Calls superclass method
    # File lib/sequel/plugins/prepared_statements.rb
139 def _insert_select_raw(ds)
140   if use_prepared_statements_for?(:insert_select)
141     if ps = model.send(:prepared_insert_select, @values.keys)
142       _set_prepared_statement_server(ps).call(@values)
143     end
144   else
145     super
146   end
147 end
_set_prepared_statement_server(ps) click to toggle source

If a server is set for the instance, return a prepared statement that will use that server.

    # File lib/sequel/plugins/prepared_statements.rb
159 def _set_prepared_statement_server(ps)
160   if @server
161     ps.server(@server)
162   else
163     ps
164   end
165 end
_update_without_checking(columns) click to toggle source

Use a prepared statement to update this model's columns in the database.

Calls superclass method
    # File lib/sequel/plugins/prepared_statements.rb
150 def _update_without_checking(columns)
151   if use_prepared_statements_for?(:update)
152     _set_prepared_statement_server(model.send(:prepared_update, columns.keys)).call(columns.merge(pk_hash))
153   else
154     super
155   end
156 end
use_prepared_statements_for?(type) click to toggle source

Whether prepared statements should be used for the given type of query (:insert, :insert_select, :update). True by default, can be overridden in other plugins to disallow prepared statements for specific types of queries.

Calls superclass method
    # File lib/sequel/plugins/prepared_statements.rb
171 def use_prepared_statements_for?(type)
172   if defined?(super)
173     result = super
174     return result unless result.nil?
175   end
176 
177   case type
178   when :insert, :insert_select, :update
179     true
180   # :nocov:
181   when :delete, :refresh
182     Sequel::Deprecation.deprecate("The :delete and :refresh prepared statement types", "There should be no need to check if these types are supported")
183     false
184   # :nocov:
185   else
186     raise Error, "unsupported type used: #{type.inspect}"
187   end
188 end