Class: KStor::SQLConnection
- Inherits:
-
Object
- Object
- KStor::SQLConnection
- Defined in:
- lib/kstor/sql_connection.rb
Overview
Execute SQL commands in a per-thread SQLite connection.
Instance Method Summary collapse
-
#execute(sql, *params) ⇒ Any
Execute SQL statement.
-
#initialize(file_path) ⇒ KStor::SQLConnection
constructor
Create a new SQL connection.
-
#last_insert_row_id ⇒ Integer
Last generated ID (from an INSERT statement).
-
#transaction(&block) ⇒ Any
Execute given block of code in a database transaction.
Constructor Details
#initialize(file_path) ⇒ KStor::SQLConnection
Create a new SQL connection.
21 22 23 |
# File 'lib/kstor/sql_connection.rb', line 21 def initialize(file_path) @file_path = file_path end |
Instance Method Details
#execute(sql, *params) ⇒ Any
Execute SQL statement.
30 31 32 |
# File 'lib/kstor/sql_connection.rb', line 30 def execute(sql, *params, &) database.execute(sql, *params, &) end |
#last_insert_row_id ⇒ Integer
Last generated ID (from an INSERT statement).
37 38 39 |
# File 'lib/kstor/sql_connection.rb', line 37 def last_insert_row_id database.last_insert_row_id end |
#transaction(&block) ⇒ Any
Execute given block of code in a database transaction.
44 45 46 47 48 49 50 51 |
# File 'lib/kstor/sql_connection.rb', line 44 def transaction(&block) result = nil database.transaction do |db| result = block.call(db) end result end |