Class: SQLiteServer
- Inherits:
-
Object
- Object
- SQLiteServer
- Includes:
- SQLite3
- Defined in:
- lib/sqlite_server2018.rb
Instance Method Summary collapse
- #execute(dbfile, *args, &blk) ⇒ Object
- #exists?(raw_dbfile) ⇒ Boolean
-
#initialize(cache: 5, debug: false, filepath: '.') ⇒ SQLiteServer
constructor
A new instance of SQLiteServer.
- #load(dbfile) ⇒ Object
- #query(*args, &blk) ⇒ Object
Constructor Details
#initialize(cache: 5, debug: false, filepath: '.') ⇒ SQLiteServer
Returns a new instance of SQLiteServer.
14 15 16 17 18 19 20 21 |
# File 'lib/sqlite_server2018.rb', line 14 def initialize(cache: 5, debug: false, filepath: '.') @dbcache = HashCache.new(cache: cache) @h = {} @debug = debug Dir.chdir filepath end |
Instance Method Details
#execute(dbfile, *args, &blk) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sqlite_server2018.rb', line 23 def execute(dbfile, *args, &blk) p 'dbfile: ' + dbfile if @debug db = Database.new dbfile if @debug then p 'db: ' + db.inspect p 'args: ' + args.inspect end begin read(dbfile).execute(*args, &blk) rescue 'SQLiteServerError: ' + ($!).inspect end end |
#exists?(raw_dbfile) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sqlite_server2018.rb', line 41 def exists?(raw_dbfile) dbfile = if raw_dbfile =~ /^sqlite:\/\// then raw_dbfile[/^sqlite:\/\/[^\/]+\/(.*)/,1] else raw_dbfile end File.exists? dbfile end |
#load(dbfile) ⇒ Object
52 53 54 55 |
# File 'lib/sqlite_server2018.rb', line 52 def load(dbfile) read dbfile 'loaded ' + dbfile end |
#query(*args, &blk) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/sqlite_server2018.rb', line 57 def query(*args, &blk) begin read(dbfile).query(*args, &blk) rescue 'SQLiteServerError: ' + ($!).inspect end end |