Class: SqLite3Wrapper
- Inherits:
-
Object
- Object
- SqLite3Wrapper
- Defined in:
- lib/aspera/sync/database.rb
Overview
A wrapper class that provides common API for sqlite in both Ruby and JRuby
Constant Summary collapse
- READ_ONLY =
asyncmay have the database open while it synchronizes: the connection is set read-only (PRAGMA query_only, a core SQLite feature, so it works the same with the JDBC driver), so that a query (for example optionsql) cannot modify the live database (it blocksUPDATE,DELETE,INSERTandVACUUM INTO). The database is still opened read-write so that a database in WAL mode can be read (a read-only open needs to write the-shmindex). 'PRAGMA query_only = ON'
Instance Method Summary collapse
- #execute(sql) ⇒ Object
- #full_table(table_name, sql_suffix = nil) ⇒ Object
-
#initialize(db_path) ⇒ SqLite3Wrapper
constructor
A new instance of SqLite3Wrapper.
-
#single_table(table_name, sql_suffix = nil) ⇒ Object
The table contains a single row.
Constructor Details
#initialize(db_path) ⇒ SqLite3Wrapper
Returns a new instance of SqLite3Wrapper.
16 17 18 |
# File 'lib/aspera/sync/database.rb', line 16 def initialize(db_path) @db_path = db_path end |
Instance Method Details
#execute(sql) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/aspera/sync/database.rb', line 26 def execute(sql) db = Sequel.connect("jdbc:sqlite:#{@db_path}") begin db.run(READ_ONLY) normalize_rows(db.fetch(sql).all) ensure db.disconnect end end |
#full_table(table_name, sql_suffix = nil) ⇒ Object
52 53 54 |
# File 'lib/aspera/sync/database.rb', line 52 def full_table(table_name, sql_suffix = nil) execute(["SELECT * FROM #{table_name}", sql_suffix].compact.join(' ')) end |
#single_table(table_name, sql_suffix = nil) ⇒ Object
The table contains a single row
48 49 50 |
# File 'lib/aspera/sync/database.rb', line 48 def single_table(table_name, sql_suffix = nil) execute(["SELECT * FROM #{table_name}", sql_suffix, 'LIMIT 1'].compact.join(' ')).first end |