Method: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#set_role
- Defined in:
- lib/active_record/postgresql_extensions/adapter_extensions.rb
#set_role(role, options = {}) ⇒ Object
Sets the current database role/user. The :duration option can be set to :session or :local as described in the PostgreSQL docs.
426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/active_record/postgresql_extensions/adapter_extensions.rb', line 426 def set_role(role, = {}) duration = if [:duration] if [ :session, :local ].include?([:duration]) [:duration].to_s.upcase else raise ArgumentError.new("The :duration option must be one of :session or :local.") end end sql = 'SET ' sql << "#{duration} " if duration sql << "ROLE #{quote_role(role)};" execute(sql, "Setting current role") end |