module Sequel::Plugins::PreparedStatementsSafe::ClassMethods

Attributes

prepared_statements_column_defaults[R]

A hash with column symbol keys and default values. Instance's values are merged into this hash before creating to reduce the number of free columns (columns that may or may not be present in the INSERT statement), as the number of prepared statements that can be created is 2^N (where N is the number of free columns).

Public Instance Methods

freeze() click to toggle source

Freeze the prepared statements column defaults when freezing the model class.

Calls superclass method
# File lib/sequel/plugins/prepared_statements_safe.rb, line 42
def freeze
  @prepared_statements_column_defaults.freeze if @prepared_statements_column_defaults

  super
end

Private Instance Methods

set_prepared_statements_column_defaults() click to toggle source

Set the column defaults based on the database schema. All columns are set to a default value unless they are a primary key column or they don't have a parseable default.

# File lib/sequel/plugins/prepared_statements_safe.rb, line 53
def set_prepared_statements_column_defaults
  if db_schema
    h = {}
    db_schema.each do |k, v|
      default = v[:ruby_default]
      h[k] = default if (default || !v[:default]) && !v[:primary_key] && !default.is_a?(Sequel::SQL::Expression)
    end
    @prepared_statements_column_defaults = h
  end
end