Class: XRBP::NodeStore::SQLDB::Ledgers
- Inherits:
-
Object
- Object
- XRBP::NodeStore::SQLDB::Ledgers
- Includes:
- Enumerable
- Defined in:
- lib/xrbp/nodestore/sqldb.rb
Instance Method Summary collapse
-
#all ⇒ Object
TODO: remove memoization, define first(n), last(n) methods.
- #between(before, after) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
- #hash_for_seq(seq) ⇒ Object
-
#initialize(sql_db) ⇒ Ledgers
constructor
A new instance of Ledgers.
- #last ⇒ Object
- #size ⇒ Object (also: #count)
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
#all ⇒ Object
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 |
#each ⇒ Object
63 64 65 66 67 |
# File 'lib/xrbp/nodestore/sqldb.rb', line 63 def each all.each do |row| yield row end end |
#first ⇒ Object
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 |
#last ⇒ Object
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 |
#size ⇒ Object 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 |