From 724c1cbe05051e44f65ec67325a08926692561b1 Mon Sep 17 00:00:00 2001 From: Isaac Lewis Date: Thu, 5 Apr 2018 17:56:41 -0700 Subject: [PATCH] add to readme; fix queryobject --- README.md | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/syspro/business_objects/parsers/comfnd_parser.rb | 4 ++-- test/query_test.rb | 4 ++-- 3 files changed, 101 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 340d5c0..010eec6 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,103 @@ logged_off = Syspro::Logoff.logoff(guid) ``` `logged_off` will be `true` if the user has been successfully logged off, and will contain an error string if an error has occured. +### Query + +#### Browse +Browse returns a paginated view of a particular table. + +This is an example using the generic Browse Business Object, `COMBRW`. +```rb +combrw = Syspro::BusinessObject::ComBrw.new +combrw.browse_name = "InvMaster" +combrw.start_condition = "" +combrw.return_rows = 5 +combrw.filters = [] +combrw.table_name = "InvMaster" +combrw.title = "StockCodes" +combrw.columns = [ + {name: "StockCode"} +] + +browse_result = combrw.call(user_id.guid) +``` + +`browse_result` will be a BrowseObject, which has the following structure: + +```rb +{ + title: "Title", + rows: [ { name: "", value: "", data_type: "" } ], + next_prev_key: { name: "", text: "" }, + header_details: { name: "", text: "" } +} +``` + +#### Query + +Query gives control over joins between multiple tables over a single Business Object. + +This is an example using the generic Query Business Object, `COMFND`. + +```rb +comfnd = Syspro::BusinessObjects::ComFnd.new +comfnd.table_name = "InvMaster" +comfnd.return_rows = 5 +comfnd.columns = [ + { + name: "StockCode" + } +] +comfnd.expressions = [ + { + andor: "And", + column: "StockCode", + condition: "EQ", + value: "02" + } +] +comfnd.order_by = "StockCode" + +query_result = comfnd.call(user_id.guid) +``` + +This will return a QueryObject, which looks like this: + +```rb +{ + header_details: { name: "", text: "" }, + rows: [ { name: "", value: "" } ], + row_count: 1 +} +``` + +#### Fetch + +Fetch selects the `TOP 1` of the query. + +This is an example using the generic Fetch Business Object, `COMFCH`. + +```rb +comfch = Syspro::BusinessObjects::ComFch.new +comfch.table_name = "InvMaster" +comfch.key = "02" +comfch.optional_keys = [] +comfch.full_key_provided = false +comfch.default_type = "" +comfch.espresso_fetch = true + +fetch_result = comfch.call(user_id.guid) +``` + +This will return a FetchObject, with the following structure: + +```rb +{ + table_name: "", + columns: [ { name: "", value: "" } ] +} +``` + ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/lib/syspro/business_objects/parsers/comfnd_parser.rb b/lib/syspro/business_objects/parsers/comfnd_parser.rb index 62715fb..78a5fde 100644 --- a/lib/syspro/business_objects/parsers/comfnd_parser.rb +++ b/lib/syspro/business_objects/parsers/comfnd_parser.rb @@ -30,14 +30,14 @@ module Syspro } }.flatten(1).compact - FindObject.new( + QueryObject.new( header_details_obj, rows_obj, doc.first_element_child.xpath('//RowsReturned').text.to_i ) end - FindObject = Struct.new(:header_details, :rows, :row_count) + QueryObject = Struct.new(:header_details, :rows, :row_count) end end end diff --git a/test/query_test.rb b/test/query_test.rb index 725d309..f892c7a 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -41,9 +41,9 @@ class QueryTest < Minitest::Test ] comfnd.order_by = "StockCode" - find_result = comfnd.call(user_id.guid) + query_result = comfnd.call(user_id.guid) - refute_nil find_result + refute_nil query_result end def test_query_fetch -- libgit2 0.21.4