Class: XRBP::NodeStore::SQLDB::Ledgers

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/xrbp/nodestore/sqldb.rb

Instance Method Summary collapse

Constructor Details

#initialize(sql_db) ⇒ Ledgers

Returns a new instance of Ledgers.



34
35
36
# File 'lib/xrbp/nodestore/sqldb.rb', line 34

def initialize(sql_db)
  @sql_db = sql_db
end

Instance Method Details

#allObject

TODO: remove memoization, define first(n), last(n) methods



70
71
72
73
# File 'lib/xrbp/nodestore/sqldb.rb', line 70

def all
  @all ||= @sql_db.ledger_db.execute("select * from Ledgers order by LedgerSeq asc")
                            .collect { |row| from_db(row) }
end

#between(before, after) ⇒ Object



38
39
40
41
42
43
# File 'lib/xrbp/nodestore/sqldb.rb', line 38

def between(before, after)
  @sql_db.ledger_db.execute("select * from Ledgers where ClosingTime >= ? and ClosingTime <= ?",
                                                                             before.to_xrp_time,
                                                                              after.to_xrp_time)
                   .collect { |row| from_db(row) }
end

#eachObject



63
64
65
66
67
# File 'lib/xrbp/nodestore/sqldb.rb', line 63

def each
  all.each do |row|
    yield row
  end
end

#firstObject



53
54
55
# File 'lib/xrbp/nodestore/sqldb.rb', line 53

def first
  @sql_db.ledger_db.execute("select LedgerSeq from Ledgers order by LedgerSeq asc limit 1").first.first
end

#hash_for_seq(seq) ⇒ Object



45
46
47
# File 'lib/xrbp/nodestore/sqldb.rb', line 45

def hash_for_seq(seq)
  @sql_db.ledger_db.execute("select LedgerHash from Ledgers where LedgerSeq = ?", seq).first.first
end

#lastObject



57
58
59
# File 'lib/xrbp/nodestore/sqldb.rb', line 57

def last
  @sql_db.ledger_db.execute("select LedgerSeq from Ledgers order by LedgerSeq desc limit 1").first.first
end

#sizeObject Also known as: count



49
50
51
# File 'lib/xrbp/nodestore/sqldb.rb', line 49

def size
  @sql_db.ledger_db.execute("select count(ROWID) from Ledgers").first.first
end