Class: Bricolage::PostgresConnection
- Inherits:
-
Object
- Object
- Bricolage::PostgresConnection
- Defined in:
- lib/bricolage/postgresconnection.rb
Instance Method Summary collapse
- #analyze(table) ⇒ Object
- #drop_table(name) ⇒ Object
- #drop_table_force(name) ⇒ Object
- #execute(query) ⇒ Object (also: #update)
- #execute_query(query, &block) ⇒ Object
-
#initialize(connection, ds, logger) ⇒ PostgresConnection
constructor
A new instance of PostgresConnection.
- #select(table, &block) ⇒ Object
- #source ⇒ Object
- #vacuum(table) ⇒ Object
- #vacuum_sort_only(table) ⇒ Object
Constructor Details
#initialize(connection, ds, logger) ⇒ PostgresConnection
Returns a new instance of PostgresConnection.
9 10 11 12 13 |
# File 'lib/bricolage/postgresconnection.rb', line 9 def initialize(connection, ds, logger) @connection = connection @ds = ds @logger = logger end |
Instance Method Details
#analyze(table) ⇒ Object
62 63 64 |
# File 'lib/bricolage/postgresconnection.rb', line 62 def analyze(table) execute "analyze #{table};" end |
#drop_table(name) ⇒ Object
38 39 40 |
# File 'lib/bricolage/postgresconnection.rb', line 38 def drop_table(name) execute "drop table #{name} cascade;" end |
#drop_table_force(name) ⇒ Object
42 43 44 45 46 |
# File 'lib/bricolage/postgresconnection.rb', line 42 def drop_table_force(name) drop_table name rescue PostgreSQLException => err @logger.error err. end |
#execute(query) ⇒ Object Also known as: update
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bricolage/postgresconnection.rb', line 19 def execute(query) @logger.info "[#{@ds.name}] #{query}" log_elapsed_time { rs = @connection.exec(query) result = rs.to_a rs.clear result } rescue PG::Error => ex raise PostgreSQLException.wrap(ex) end |
#execute_query(query, &block) ⇒ Object
31 32 33 34 |
# File 'lib/bricolage/postgresconnection.rb', line 31 def execute_query(query, &block) @logger.info "[#{@ds.name}] #{query}" exec(query, &block) end |
#select(table, &block) ⇒ Object
48 49 50 51 52 |
# File 'lib/bricolage/postgresconnection.rb', line 48 def select(table, &block) query = "select * from #{table}" @logger.info "[#{@ds.name}] #{query}" exec(query, &block) end |
#source ⇒ Object
15 16 17 |
# File 'lib/bricolage/postgresconnection.rb', line 15 def source @connection end |
#vacuum(table) ⇒ Object
54 55 56 |
# File 'lib/bricolage/postgresconnection.rb', line 54 def vacuum(table) execute "vacuum #{table};" end |
#vacuum_sort_only(table) ⇒ Object
58 59 60 |
# File 'lib/bricolage/postgresconnection.rb', line 58 def vacuum_sort_only(table) execute "vacuum sort only #{table};" end |