Module: Operations
- Included in:
- QAT::DB
- Defined in:
- lib/qat/db/operations.rb
Overview
Database operations helper methods
Defined Under Namespace
Classes: ConnectionError
Instance Method Summary collapse
-
#connect(*args, &block) ⇒ Sequel::Database
Establishes a connection.
-
#connection ⇒ Sequel::Database
Returns the current connection.
-
#execute(sql, opts = nil) ⇒ NilClass
Executes a SQL statement in the open connection.
-
#query(sql) ⇒ Array
Executes a SQL query in the open connection and returns an array of results.
Instance Method Details
#connect(*args, &block) ⇒ Sequel::Database
Establishes a connection
14 15 16 17 |
# File 'lib/qat/db/operations.rb', line 14 def connect(*args, &block) @connection = Sequel.connect(*args, &block) connection end |
#connection ⇒ Sequel::Database
Returns the current connection
8 9 10 |
# File 'lib/qat/db/operations.rb', line 8 def connection @connection end |
#execute(sql, opts = nil) ⇒ NilClass
Executes a SQL statement in the open connection
24 25 26 27 28 |
# File 'lib/qat/db/operations.rb', line 24 def execute(sql, opts=nil) args = [sql] args << opts if opts connection.run(*args) end |
#query(sql) ⇒ Array
Executes a SQL query in the open connection and returns an array of results
33 34 35 36 37 38 |
# File 'lib/qat/db/operations.rb', line 33 def query(sql) connection = Sequel.connect(self.args) connection[sql].map { |row| row } connection connection.close end |