Class: Sequel::Postgres::Adapter
- Includes:
- AdapterMethods
- Defined in:
- lib/sequel_core/adapters/postgres.rb
Overview
PGconn subclass for connection specific methods used with the pg, postgres, or postgres-pr driver.
Instance Method Summary collapse
-
#apply_connection_settings ⇒ Object
Apply connection settings for this connection.
-
#execute(sql, args = nil) ⇒ Object
Execute the given SQL with this connection.
-
#prepared_statements ⇒ Object
Hash of prepared statements for this connection.
-
#reset(*args, &block) ⇒ Object
Reapply the connection settings if the connection is reset.
Instance Method Details
#apply_connection_settings ⇒ Object
Apply connection settings for this connection. Current sets the date style to ISO in order make Date object creation in ruby faster, if Postgres.use_iso_date_format is true.
121 122 123 124 125 126 127 128 |
# File 'lib/sequel_core/adapters/postgres.rb', line 121 def apply_connection_settings super if Postgres.use_iso_date_format sql = "SET DateStyle = 'ISO'" @db.log_info(sql) execute(sql) end end |
#execute(sql, args = nil) ⇒ Object
Execute the given SQL with this connection. If a block is given, yield the results, otherwise, return the number of changed rows.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/sequel_core/adapters/postgres.rb', line 132 def execute(sql, args=nil) q = nil begin q = args ? async_exec(sql, args) : async_exec(sql) rescue PGError begin s = status rescue PGError raise(Sequel::DatabaseDisconnectError) end status_ok = (s == Adapter::CONNECTION_OK) status_ok ? raise : raise(Sequel::DatabaseDisconnectError) ensure block if status_ok end begin block_given? ? yield(q) : q.cmd_tuples ensure q.clear end end |
#prepared_statements ⇒ Object
Hash of prepared statements for this connection. Keys are string names of the server side prepared statement, and values are SQL strings.
164 165 166 |
# File 'lib/sequel_core/adapters/postgres.rb', line 164 def prepared_statements @prepared_statements ||= {} end |
#reset(*args, &block) ⇒ Object
Reapply the connection settings if the connection is reset.
155 156 157 158 |
# File 'lib/sequel_core/adapters/postgres.rb', line 155 def reset(*args, &block) super(*args, &block) apply_connection_settings end |