Class: SimpleCache::SqliteDatabase
- Inherits:
-
Object
- Object
- SimpleCache::SqliteDatabase
- Defined in:
- lib/simple_cache/sqlite_store.rb
Overview
A simplistic Sqlite database interface
Direct Known Subclasses
Instance Method Summary collapse
- #ask(sql, *args) ⇒ Object
- #exec(sql, *args) ⇒ Object
-
#initialize(url) ⇒ SqliteDatabase
constructor
A new instance of SqliteDatabase.
Constructor Details
#initialize(url) ⇒ SqliteDatabase
Returns a new instance of SqliteDatabase.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/simple_cache/sqlite_store.rb', line 3 def initialize(url) require "sqlite3" path = URI.parse(url).path FileUtils.mkdir_p File.dirname(path) @impl = SQLite3::Database.new(path) @prepared_queries = {} ask "PRAGMA synchronous = OFF" end |
Instance Method Details
#ask(sql, *args) ⇒ Object
19 20 21 |
# File 'lib/simple_cache/sqlite_store.rb', line 19 def ask(sql, *args) exec(sql, *args).first end |
#exec(sql, *args) ⇒ Object
14 15 16 17 |
# File 'lib/simple_cache/sqlite_store.rb', line 14 def exec(sql, *args) query = @prepared_queries[sql] ||= @impl.prepare(sql) query.execute!(*args) end |