Class | Sequel::Postgres::Database |
In: |
lib/sequel/adapters/postgres.rb
|
Parent: | Sequel::Database |
Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.
# File lib/sequel/adapters/postgres.rb, line 182 182: def initialize(*args) 183: super 184: @primary_keys = {} 185: @primary_key_sequences = {} 186: end
Connects to the database. In addition to the standard database options, using the :encoding or :charset option changes the client encoding for the connection.
# File lib/sequel/adapters/postgres.rb, line 191 191: def connect(server) 192: opts = server_opts(server) 193: conn = Adapter.connect( 194: (opts[:host] unless blank_object?(opts[:host])), 195: opts[:port] || 5432, 196: nil, '', 197: opts[:database], 198: opts[:user], 199: opts[:password] 200: ) 201: if encoding = opts[:encoding] || opts[:charset] 202: if conn.respond_to?(:set_client_encoding) 203: conn.set_client_encoding(encoding) 204: else 205: conn.async_exec("set client_encoding to '#{encoding}'") 206: end 207: end 208: conn.db = self 209: conn.apply_connection_settings 210: conn 211: end
Return instance of Sequel::Postgres::Dataset with the given options.
# File lib/sequel/adapters/postgres.rb, line 214 214: def dataset(opts = nil) 215: Postgres::Dataset.new(self, opts) 216: end
Execute the given SQL with the given args on an available connection.
# File lib/sequel/adapters/postgres.rb, line 219 219: def execute(sql, opts={}, &block) 220: return execute_prepared_statement(sql, opts, &block) if Symbol === sql 221: begin 222: log_info(sql, opts[:arguments]) 223: synchronize(opts[:server]){|conn| conn.execute(sql, opts[:arguments], &block)} 224: rescue => e 225: log_info(e.message) 226: raise_error(e, :classes=>CONVERTED_EXCEPTIONS) 227: end 228: end
Insert the values into the table and return the primary key (if automatically generated).
# File lib/sequel/adapters/postgres.rb, line 232 232: def execute_insert(sql, opts={}) 233: return execute(sql, opts) if Symbol === sql 234: begin 235: log_info(sql, opts[:arguments]) 236: synchronize(opts[:server]) do |conn| 237: conn.execute(sql, opts[:arguments]) 238: insert_result(conn, opts[:table], opts[:values]) 239: end 240: rescue => e 241: log_info(e.message) 242: raise_error(e, :classes=>CONVERTED_EXCEPTIONS) 243: end 244: end