class DbchainClient::Querier
Public Class Methods
new(base_url, private_key, app_code=nil)
click to toggle source
# File lib/dbchain_client/querier.rb, line 3 def initialize(base_url, private_key, app_code=nil) @base_url = base_url if private_key.instance_of? String @private_key = PrivateKey.new(private_key) else @private_key = private_key end set_app_code unless app_code.nil? @single_value = false end
Public Instance Methods
equal(field_name, value)
click to toggle source
# File lib/dbchain_client/querier.rb, line 72 def equal(field_name, value) where(field_name, value, '=') end
find(id)
click to toggle source
# File lib/dbchain_client/querier.rb, line 29 def find(id) @single_value = true h = { method: 'find', id: id } finish(h) end
find_first()
click to toggle source
# File lib/dbchain_client/querier.rb, line 38 def find_first @single_value = true h = { method: 'first', } finish(h) end
find_last()
click to toggle source
# File lib/dbchain_client/querier.rb, line 46 def find_last @single_value = true h = { method: 'last', } finish(h) end
own()
click to toggle source
# File lib/dbchain_client/querier.rb, line 76 def own() from_address = @private_key.public_key.address equal('created_by', from_address) end
run()
click to toggle source
# File lib/dbchain_client/querier.rb, line 81 def run reader = DbchainClient::Reader.new(@base_url, @private_key) result = reader.querier(@q[:app_code], @q[:commands]) if @single_value if result.size > 0 result[0] else nil end else result end end
select(*args)
click to toggle source
# File lib/dbchain_client/querier.rb, line 54 def select(*args) h = { method: 'select', fields: args.join(',') } finish(h) end
set_app_code(app_code)
click to toggle source
# File lib/dbchain_client/querier.rb, line 16 def set_app_code(app_code) initialize_internal_querier if @q.nil? @q[:app_code] = app_code end
table(table_name)
click to toggle source
# File lib/dbchain_client/querier.rb, line 21 def table(table_name) h = { method: 'table', table: table_name } finish(h) end
where(field_name, value, operator)
click to toggle source
# File lib/dbchain_client/querier.rb, line 62 def where(field_name, value, operator) h = { method: 'where', field: field_name, value: value, operator: operator } finish(h) end
Private Instance Methods
finish(h)
click to toggle source
# File lib/dbchain_client/querier.rb, line 101 def finish(h) @q[:commands].push(h) self end
initialize_internal_querier()
click to toggle source
# File lib/dbchain_client/querier.rb, line 97 def initialize_internal_querier @q = {commands: []} end