Module: Sequel::Settable

Defined in:
lib/sequel/extensions/settable.rb

Overview

The Settable module provides database configuration functionality through SET statements. When loaded as an extension, it adds the set method to database connections.

Instance Method Summary collapse

Instance Method Details

#set(opts = {}) ⇒ void

This method returns an undefined value.

Execute SET statements for the given options hash.

Each key-value pair in the options hash is converted to a SET statement and executed against the database. Multiple options result in multiple SET statements being executed in sequence.

Examples:

Set a single parameter

DB.set(timezone: 'UTC')
# Executes: SET timezone=UTC

Set multiple parameters

DB.set(search_path: 'public', work_mem: '256MB')
# Executes: SET search_path=public
#           SET work_mem=256MB

Different value types

DB.set(port: 5432, autocommit: true, custom_setting: nil)
# Executes: SET port=5432
#           SET autocommit=true
#           SET custom_setting=

Parameters:

  • opts (Hash) (defaults to: {})

    Hash of configuration options to set

Options Hash (opts):

  • key (Object)

    The configuration parameter name

  • value (Object)

    The value to set for the parameter



54
55
56
57
58
# File 'lib/sequel/extensions/settable.rb', line 54

def set(opts = {})
  set_sql(opts).each do |sql|
    run(sql)
  end
end