Class: RecordxSqlite

Inherits:
Object
  • Object
show all
Defined in:
lib/recordx_sqlite.rb

Instance Method Summary collapse

Constructor Details

#initialize(dbfile, table) ⇒ RecordxSqlite

Returns a new instance of RecordxSqlite.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/recordx_sqlite.rb', line 11

def initialize(dbfile, table)

  @db = SQLite3::Database.new dbfile
  @db.results_as_hash = true
  rs = @db.query 'select * from ' + table

  @a = rs.map do |h| 
    h2 = h.inject({}) {|r, x| k, v = x; r.merge(k.to_sym => v)}
    RecordX.new(h2, self, h2[:uid]) 
  end

end

Instance Method Details

#allObject



24
25
26
# File 'lib/recordx_sqlite.rb', line 24

def all()
  @a
end

#update(id, h = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/recordx_sqlite.rb', line 28

def update(id, h={})

  col, value = h.to_a.first
  return if col == :id

s = "
UPDATE headers
SET #{col}='#{value}'
WHERE id='#{id}';"

  @db.execute(s)

end