Class: NetSystem::SqliteClient

Inherits:
Client show all
Defined in:
lib/net_system/sub/database/clients/sqlite_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Constructor Details

#initialize(*args) ⇒ SqliteClient



5
6
7
8
9
10
11
12
# File 'lib/net_system/sub/database/clients/sqlite_client.rb', line 5

def initialize *args
  require "sqlite3"
  t = Time.now
  args = [NetBox[:client].get(:sqlite_path)] if args.empty?
  @conn = SQLite3::Database.new(*args)
ensure
  log "#{t.diff}s | Connecting to #{args}"
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



14
15
16
# File 'lib/net_system/sub/database/clients/sqlite_client.rb', line 14

def conn
  @conn
end

Instance Method Details

#call(sql, *args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/net_system/sub/database/clients/sqlite_client.rb', line 16

def call sql, *args
  t = Time.now
  result = @conn.execute2 sql, *args

  result
ensure
  log "#{t.diff}s | #{sql} | #{args}"
end

#nowObject



25
26
27
# File 'lib/net_system/sub/database/clients/sqlite_client.rb', line 25

def now
  call "SELECT strftime('%Y-%m-%dT%H:%M:%S.%f', 'now', 'localtime');"
end