lib/pg_conn.rb in pg_conn-0.9.0 vs lib/pg_conn.rb in pg_conn-0.10.0
- old
+ new
@@ -3,10 +3,11 @@
require "pg_conn/version"
require "pg_conn/role_methods"
require "pg_conn/schema_methods"
require "pg_conn/rdbms_methods"
+require "pg_conn/session_methods"
module PgConn
class Error < StandardError; end
# Can be raised in #transaction blocks to rollback changes
@@ -57,10 +58,13 @@
# Schema manipulation methods: #exist?, #create, #drop, #list, and
# #exist?/#list for relations/tables/views/columns
attr_reader :schema
+ # Session manipulation methods: #list, #terminate, #disable, #enable
+ attr_reader :session
+
# The transaction timestamp of the most recent SQL statement executed by
# #exec or #transaction block
attr_reader :timestamp
# PG::Error object if the last statement failed; otherwise nil
@@ -196,15 +200,16 @@
end
@schema = SchemaMethods.new(self)
@role = RoleMethods.new(self)
@rdbms = RdbmsMethods.new(self)
+ @session = SessionMethods.new(self)
@timestamp = nil
@savepoints = nil # Stack of savepoint names. Nil if no transaction in progress
end
- # Close the database connection
+ # Close the database connection. TODO: Rename 'close'
def terminate()
@pg_connection.close if @pg_connection && !@pg_connection.finished?
end
def self.new(*args, **opts, &block)
@@ -414,10 +419,13 @@
h[record[key_column]] = record.to_h
}
h
end
+ # TODO: An #array method that returns a map from id to tuple. Hmm... almost
+ # the same as #map
+
# Return a hash from the record id column to an OpenStruct representation
# of the record. If the :key_column option is defined it will be used
# instead of id as the key. It is an error if the id field value is not
# unique
def set(query, key_column: :id)
@@ -565,9 +573,10 @@
# Switch user to the given user and execute the statement before swithcing
# back to the original user
#
# FIXME: The out-commented transaction block makes postspec fail for some reason
+ # TODO: Rename 'sudo' because it acts just like it.
def su(username, &block)
raise Error, "Missing block in call to PgConn::Connection#su" if !block_given?
realuser = self.value "select current_user"
result = nil
# transaction(commit: false) {