This sophisticated API uses a method called chaining that enables a developer to call multiple methods on the same object, and allows for very flexible dynamic data lookup. It is suitable for complex use cases that require returning one of multiple matching rows, ordering etc.
To use this API,
1- First build the request query chains
Format:
xxxxxxxxxxassetDBReq(assetSourceName).keys(list of keys).max(number of rows returned).order(random or asc or desc).orderBy(name of column for sorting response).build();| Method(Parameters) | Required | Description | Example Usage |
|---|---|---|---|
| assetDBReq(assetSource) | Yes | Name of the asset source to query | assetDBReq("NumbersTest") |
| keys(list of keys) | Yes | Specify one or more key values to query for | keys("3,5,7") |
| max(number of rows returned) | Yes | Restrict number of returned rows, with multiple matching rows on lookup. Rows returned will be equal to or less than max rows specified | max(5) |
| order(random or asc or desc) | No | Specify ordering for multiple matches | order(random) |
| orderBy(name of column for sorting response) | No | Specify the column to use for sorting (ascending or descending) | orderBy(Display) |
| build() | Yes | Complete query |
Examples: To query asset source NumbersTest for key '3', and return the first 5 matching values sorted by the column named 'Display':
xxxxxxxxxxvar NumbersTestSortedLookup = jvxAd.assetDBReq("NumbersTest").keys('3').max(5).order("asce").orderBy('Display').build();To query the asset source NumbersTest for keys '3' and '5', and return the first matching value for each lookup:
xxxxxxxxxxvar NumbersTestTwoKeyLookup = jvxAd.assetDBReq("NumbersTest").keys('3,5').max(1).build();2- Next attach query to one or more callback functions.
Format:
| Method(Parameters) | Required | Description | Example Usage |
|---|---|---|---|
| dynamicDataCallback(CallbackFunction) | Yes | Name of callback function | dynamicDataCallback('callback') |
get() OR get(list of query chains) | Yes | Explicitly specify queries to execute, or leave blank to execute all defined queries | get() get(NumbersTestSortedLookup, NumbersTestTwoKeyLookup) |
Examples:
Return Data for a Single Row
This example implements the same functionality as:
xxxxxxxxxxjvxAd.getDynamicService( "NumbersTest:NumbersTest", "ap_NumbersTest=5", "callback");The sample code below fetches a single row with key '5' from the asset source "NumbersTest" and pretty prints it.