dynamicDataCallback

AI Tools

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:

assetDBReq(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':

var 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:

var 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:

jvxAd.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.

<script> function dataFromDb(result){ console.log(JSON.stringify(result)+"________________result"); } function initiate(){ var NumbersLookup = jvxAd.assetDBReq("NumbersTest").keys('5').build(); jvxAd.dynamicDataCallback('dataFromDb').get(); } <_script>

Return Multiple rows for a Single Key

Now assume that the NumbersTest asset source has multiple rows matching '5' (i.e. '5' is configured as an Asset Group during database upload). The sample code below fetches 2 rows in random order from the asset source "NumbersTest" and pretty prints.

<script> function dataFromDb(result){ console.log(JSON.stringify(result)+"________________result"); } function initiate(){ var NumbersLookup = jvxAd.assetDBReq("NumbersTest").keys('5').max(2).order("random").build(); jvxAd.dynamicDataCallback('dataFromDb').get(); } <_script>

Return data for Multiple Key, Multiple rows

This example shows how the multiple rows lookup of a single asset source using getDynamicService:

jvxAd.getDynamicService( "NumbersTest:NumbersTest", ["ap_NumbersTest=3,5,7"], "callback");

This can be more flexible using the dynamicDataCallback API. The code sample with notes is shown below:

<script> function dataFromDb(result){ console.log(JSON.stringify(result)+"________________result"); } function initiate(){ __ This will return at most 2 randomly selected rows for the keys 3,5,7 var NumbersLookupOddRan = jvxAd.assetDBReq("NumbersTest").keys('3,5,7').max(2).order("random").build(); __ This will return the first 3 rows found for the keys 2,4 var NumbersLookupEvenAsc = jvxAd.assetDBReq("NumbersTest").keys('2,4').max(3).order("asc").build(); __ Look up both NumbersLookupOddRan and NumbersLookupEvenAsc, 3 rows will be returned since NumbersLookupEvenAsc specifies max of 3 jvxAd.dynamicDataCallback('dataFromDb').get(NumbersLookupOddRan, NumbersLookupEvenAsc); __ Look up both NumbersLookupEvenAsc only jvxAd.dynamicDataCallback('dataFromDb').get(NumbersLookupEvenAsc); __ Look up both NumbersLookupOddRan and NumbersLookupEvenAsc jvxAd.dynamicDataCallback('dataFromDb').get(); } <_script>

Return Multiple rows from Multiple asset sources using Multiple Keys

This example shows how to lookup multiple rows of multiple asset sources using getDynamicService:

jvxAd.getDynamicService([ ["NumbersTest:NumbersTest", "DeepUploadTest: DeepUploadTest"], ["ap_NumbersTest=3,5,7", "ap_DeepUploadTest=s"], "callback");

This can be more flexible using the dynamicDataCallback API. The code sample with notes is shown below:

<script> function dataFromDb(result){ console.log(JSON.stringify(result)+"________________result"); } function initiate(){ __ This will return at most 2 randomly selected rows for the keys 3,5,7 var NumbersLookupOddRan = jvxAd.assetDBReq("NumbersTest").keys('3,5,7').max(2).order("random").build(); __ This will return first 3 rows for the keys 2,4 var NumbersLookupEvenAsc = jvxAd.assetDBReq("NumbersTest").keys('2,4').max(3).order("asc").build(); __ This will return first 2 rows for the keys 2,4 var AlphabetLookupVowelsDesc = jvxAd.assetDBReq("AlphabetsTest").keys('a,e,i,o,u').max(5).order("desc").build(); __ Look up both NumbersLookupOddRan and NumbersLookupEvenAsc, 3 rows will be returned since NumbersLookupEvenAsc specifies max of 3 jvxAd.dynamicDataCallback('dataFromDb').get(NumbersLookupOddRan, NumbersLookupEvenAsc); __ Look up all three dataabses jvxAd.dynamicDataCallback('dataFromDb').get(); } <_script>


On This Page
dynamicDataCallback