Class: FluidDb2::Base
- Inherits:
-
Object
- Object
- FluidDb2::Base
- Defined in:
- lib/fluiddb2.rb
Overview
Base
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#verbose ⇒ Object
writeonly
Sets the attribute verbose.
Instance Method Summary collapse
-
#begin ⇒ Object
Transaction Semantics.
- #close ⇒ Object
-
#commit ⇒ Object
Transaction Semantics.
- #connect ⇒ Object
-
#execute(_sql, _params, _expected_affected_rows) ⇒ Object
Execute an insert, update or delete, then check the impact that statement has on the data.
-
#initialize(uri) ⇒ Base
constructor
Constructor.
-
#query_for_array(_sql, _params) ⇒ Object
Return a single row from the database, given the sql parameter.
- #query_for_resultset(_sql, _params) ⇒ Object
-
#query_for_value(_sql, _params) ⇒ Object
Return a single value is returned from a single row from the database, given the sql parameter.
- #reconnect ⇒ Object
-
#rollback ⇒ Object
Transaction Semantics.
- #verbose_log(string) ⇒ Object
Constructor Details
#initialize(uri) ⇒ Base
Constructor.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fluiddb2.rb', line 125 def initialize(uri) if uri.is_a? String @uri = URI.parse(uri) else @uri = uri end connect @verbose = !ENV['VERBOSE'].nil? end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
119 120 121 |
# File 'lib/fluiddb2.rb', line 119 def connection @connection end |
#verbose=(value) ⇒ Object (writeonly)
Sets the attribute verbose
118 119 120 |
# File 'lib/fluiddb2.rb', line 118 def verbose=(value) @verbose = value end |
Instance Method Details
#begin ⇒ Object
Transaction Semantics
194 195 196 |
# File 'lib/fluiddb2.rb', line 194 def begin @connection.execute('BEGIN') end |
#close ⇒ Object
145 146 147 |
# File 'lib/fluiddb2.rb', line 145 def close fail NotImplementedError, "You must implement 'close'." end |
#commit ⇒ Object
Transaction Semantics
199 200 201 |
# File 'lib/fluiddb2.rb', line 199 def commit @connection.execute('COMMIT', []) end |
#connect ⇒ Object
141 142 143 |
# File 'lib/fluiddb2.rb', line 141 def connect fail NotImplementedError, "You must implement 'connect'." end |
#execute(_sql, _params, _expected_affected_rows) ⇒ Object
Execute an insert, update or delete, then check the impact that statement
has on the data.
189 190 191 |
# File 'lib/fluiddb2.rb', line 189 def execute(_sql, _params, _expected_affected_rows) fail NotImplementedError, "You must implement 'execute'." end |
#query_for_array(_sql, _params) ⇒ Object
Return a single row from the database, given the sql parameter. Throws an error for no data. Throws an error for more than 1 row
161 162 163 |
# File 'lib/fluiddb2.rb', line 161 def query_for_array(_sql, _params) fail NotImplementedError, "You must implement 'queryForArray'." end |
#query_for_resultset(_sql, _params) ⇒ Object
177 178 179 |
# File 'lib/fluiddb2.rb', line 177 def query_for_resultset(_sql, _params) fail NotImplementedError, "You must implement 'queryForResultset'." end |
#query_for_value(_sql, _params) ⇒ Object
Return a single value is returned from a single row from the database,
given the sql parameter.
Throws an error for no data. Throws an error for more than 1 row
173 174 175 |
# File 'lib/fluiddb2.rb', line 173 def query_for_value(_sql, _params) fail NotImplementedError, "You must implement 'queryForValue'." end |
#reconnect ⇒ Object
149 150 151 152 |
# File 'lib/fluiddb2.rb', line 149 def reconnect close connect end |
#rollback ⇒ Object
Transaction Semantics
204 205 206 |
# File 'lib/fluiddb2.rb', line 204 def rollback @connection.execute('ROLLBACK', []) end |
#verbose_log(string) ⇒ Object
137 138 139 |
# File 'lib/fluiddb2.rb', line 137 def verbose_log(string) puts string if @verbose == true end |