Commit 724c1cbe05051e44f65ec67325a08926692561b1
1 parent
0f29247c
add to readme; fix queryobject
Showing
3 changed files
with
101 additions
and
4 deletions
Show diff stats
README.md
| @@ -72,6 +72,103 @@ logged_off = Syspro::Logoff.logoff(guid) | @@ -72,6 +72,103 @@ logged_off = Syspro::Logoff.logoff(guid) | ||
| 72 | ``` | 72 | ``` |
| 73 | `logged_off` will be `true` if the user has been successfully logged off, and will contain an error string if an error has occured. | 73 | `logged_off` will be `true` if the user has been successfully logged off, and will contain an error string if an error has occured. |
| 74 | 74 | ||
| 75 | +### Query | ||
| 76 | + | ||
| 77 | +#### Browse | ||
| 78 | +Browse returns a paginated view of a particular table. | ||
| 79 | + | ||
| 80 | +This is an example using the generic Browse Business Object, `COMBRW`. | ||
| 81 | +```rb | ||
| 82 | +combrw = Syspro::BusinessObject::ComBrw.new | ||
| 83 | +combrw.browse_name = "InvMaster" | ||
| 84 | +combrw.start_condition = "" | ||
| 85 | +combrw.return_rows = 5 | ||
| 86 | +combrw.filters = [] | ||
| 87 | +combrw.table_name = "InvMaster" | ||
| 88 | +combrw.title = "StockCodes" | ||
| 89 | +combrw.columns = [ | ||
| 90 | + {name: "StockCode"} | ||
| 91 | +] | ||
| 92 | + | ||
| 93 | +browse_result = combrw.call(user_id.guid) | ||
| 94 | +``` | ||
| 95 | + | ||
| 96 | +`browse_result` will be a BrowseObject, which has the following structure: | ||
| 97 | + | ||
| 98 | +```rb | ||
| 99 | +{ | ||
| 100 | + title: "Title", | ||
| 101 | + rows: [ { name: "", value: "", data_type: "" } ], | ||
| 102 | + next_prev_key: { name: "", text: "" }, | ||
| 103 | + header_details: { name: "", text: "" } | ||
| 104 | +} | ||
| 105 | +``` | ||
| 106 | + | ||
| 107 | +#### Query | ||
| 108 | + | ||
| 109 | +Query gives control over joins between multiple tables over a single Business Object. | ||
| 110 | + | ||
| 111 | +This is an example using the generic Query Business Object, `COMFND`. | ||
| 112 | + | ||
| 113 | +```rb | ||
| 114 | +comfnd = Syspro::BusinessObjects::ComFnd.new | ||
| 115 | +comfnd.table_name = "InvMaster" | ||
| 116 | +comfnd.return_rows = 5 | ||
| 117 | +comfnd.columns = [ | ||
| 118 | + { | ||
| 119 | + name: "StockCode" | ||
| 120 | + } | ||
| 121 | +] | ||
| 122 | +comfnd.expressions = [ | ||
| 123 | + { | ||
| 124 | + andor: "And", | ||
| 125 | + column: "StockCode", | ||
| 126 | + condition: "EQ", | ||
| 127 | + value: "02" | ||
| 128 | + } | ||
| 129 | +] | ||
| 130 | +comfnd.order_by = "StockCode" | ||
| 131 | + | ||
| 132 | +query_result = comfnd.call(user_id.guid) | ||
| 133 | +``` | ||
| 134 | + | ||
| 135 | +This will return a QueryObject, which looks like this: | ||
| 136 | + | ||
| 137 | +```rb | ||
| 138 | +{ | ||
| 139 | + header_details: { name: "", text: "" }, | ||
| 140 | + rows: [ { name: "", value: "" } ], | ||
| 141 | + row_count: 1 | ||
| 142 | +} | ||
| 143 | +``` | ||
| 144 | + | ||
| 145 | +#### Fetch | ||
| 146 | + | ||
| 147 | +Fetch selects the `TOP 1` of the query. | ||
| 148 | + | ||
| 149 | +This is an example using the generic Fetch Business Object, `COMFCH`. | ||
| 150 | + | ||
| 151 | +```rb | ||
| 152 | +comfch = Syspro::BusinessObjects::ComFch.new | ||
| 153 | +comfch.table_name = "InvMaster" | ||
| 154 | +comfch.key = "02" | ||
| 155 | +comfch.optional_keys = [] | ||
| 156 | +comfch.full_key_provided = false | ||
| 157 | +comfch.default_type = "" | ||
| 158 | +comfch.espresso_fetch = true | ||
| 159 | + | ||
| 160 | +fetch_result = comfch.call(user_id.guid) | ||
| 161 | +``` | ||
| 162 | + | ||
| 163 | +This will return a FetchObject, with the following structure: | ||
| 164 | + | ||
| 165 | +```rb | ||
| 166 | +{ | ||
| 167 | + table_name: "", | ||
| 168 | + columns: [ { name: "", value: "" } ] | ||
| 169 | +} | ||
| 170 | +``` | ||
| 171 | + | ||
| 75 | ## Development | 172 | ## Development |
| 76 | 173 | ||
| 77 | 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. | 174 | 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. |
lib/syspro/business_objects/parsers/comfnd_parser.rb
| @@ -30,14 +30,14 @@ module Syspro | @@ -30,14 +30,14 @@ module Syspro | ||
| 30 | } | 30 | } |
| 31 | }.flatten(1).compact | 31 | }.flatten(1).compact |
| 32 | 32 | ||
| 33 | - FindObject.new( | 33 | + QueryObject.new( |
| 34 | header_details_obj, | 34 | header_details_obj, |
| 35 | rows_obj, | 35 | rows_obj, |
| 36 | doc.first_element_child.xpath('//RowsReturned').text.to_i | 36 | doc.first_element_child.xpath('//RowsReturned').text.to_i |
| 37 | ) | 37 | ) |
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | - FindObject = Struct.new(:header_details, :rows, :row_count) | 40 | + QueryObject = Struct.new(:header_details, :rows, :row_count) |
| 41 | end | 41 | end |
| 42 | end | 42 | end |
| 43 | end | 43 | end |
test/query_test.rb
| @@ -41,9 +41,9 @@ class QueryTest < Minitest::Test | @@ -41,9 +41,9 @@ class QueryTest < Minitest::Test | ||
| 41 | ] | 41 | ] |
| 42 | comfnd.order_by = "StockCode" | 42 | comfnd.order_by = "StockCode" |
| 43 | 43 | ||
| 44 | - find_result = comfnd.call(user_id.guid) | 44 | + query_result = comfnd.call(user_id.guid) |
| 45 | 45 | ||
| 46 | - refute_nil find_result | 46 | + refute_nil query_result |
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | def test_query_fetch | 49 | def test_query_fetch |