<object>.get
The <object>.get API returns all or selected records from the local database.
NOTE: The column names and values provided as key value pairs are case sensitive.
Quantum Visualizer (JavaScrpit)
Signature
<KNYObj>.get(options, successCallback, failureCallback)
Parameters
Parameter | Type | Description | Required |
options
|
JSON | If the options parameter is omitted, all records are returned. | Yes |
successCallback | Function | The function is invoked on success with records passed as an argument. | Yes |
failureCallback | Function | The function is invoked on an error with the cause of failure as an argument. | Yes |
Options Keys
Keys | Type | Description | Required |
primaryKeys | JSON/Table | Specify the primary keys to use for the select query. Use records primary key column names as key and respective values to populate primaryKeys JSON. | No |
whereConditionAsAString | String |
Specify the where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and the value is a string. NOTE: For Mobile Web and Desktop Web channels, every condition must have a comparison parameter only (=, !=, >, <, >=, <=). Multiple conditions can be clubbed using conjunctions (AND, OR). |
No |
orderByMap | JSON elements |
Specifies the way the data should be arranged in ascending/descending order of column name. Key Name: orderByMap and value is an array of the dictionary. NOTE: In Mobile Web and Desktop Web channels, OrderBy is applicable on one column. |
No |
whereCondition | JSON | Specify the where condition for the select query if primary keys are not provided. Key Name: whereCondition and values are column names and their respective values. . | No |
likeCondition | JSON/Table |
List of column names and their respective values according to which the records are to be fetched. NOTE: Not supported for Mobile Web and Desktop Web channels. |
No |
projectionColumns | Array List< string> | List of column names according to which the records are to be fetched. | No |
distinct | Boolean | Boolean value for getting the distinct value of the first projection column passed. | No |
Return Type
void
Example
//----- Example : Get all -------- function onGetAllSuccess(records) { //records is an array of records. each record is a dictionary. } function onGetAllFail(error) { kony.print("unable to retrieve records from db" + error.code) } var categories = new kony.sdk.KNYObj("CATEGORY"); //all records of object CATEGORY are returned as an argument to success callback. categories.get(null, onGetAllSuccess, onGetAllFail) //------- Example : getall with orderBy clause -------- function onGetAllSuccess(records) { //records is an array of records. each record is a dictionary. } function onGetAllFail(error) { kony.print("unable to retrieve records from db" + error.code) } var categories = new kony.sdk.KNYObj("CATEGORY"); var options = {}; var orderByMap = []; orderByMap.push({ "CategoryID": "DESC" }); orderByMap.push({ "CategoryName": "ASC" }); var options = {}; options["orderByMap"] = orderByMap; //all records of object CATEGORY are returned as an argument to success callback ordered by CategoryID and CategoryName. categories.get(options, onGetAllSuccess, onGetAllFail); //------ Example : get by PK -------- function onGetAllSuccess(records) { //records is an array of records. each record is a dictionary. } function onGetAllFail(error) { kony.print("unable to retrieve records from db" + error.code) } var categories = new kony.sdk.KNYObj("CATEGORY"); var options = {}; //Primary keys or a where clause can be used var primaryKeys["CategoryID"] = "2233"; options["primaryKeys"] = primaryKeys; // record with PK CategoryID with value "2233" of object CATEGORY are returned as an argument to success callback. categories.get(options, onGetAllSuccess, onGetAllFail) //---- Example : get by where clause -------- function onGetAllSuccess(records) { //records is an array of records. each record is a dictionary. } function onGetAllFail(error) { kony.print("unable to retrieve records from db" + error.code) } var categories = new kony.sdk.KNYObj("CATEGORY"); var whereClause = "Category_PN = '7'"; var options = {}; options["whereConditionAsAString"] = whereClause; //Invoking get returns record with Category_PN = 7 . categories.get(options, onGetAllSuccess, onGetAllFail); //------- Example : get for projection Columns -------- function onGetSuccess(records) { //records is an array of records. Each record is a dictionary. } Function onGetFailure(error) { Kony.print("unable to retrieve records from database" + error.code); } var categories = new kony.sdk.KNYObj("CATEGORY"); var options = {}; var projectionColumnsList = []; projectionColumnsList.push("Category_PN"); projectionColumnsList.push("Category_ID"); options["projectionColumns"] = projectionColumnsList; // Invoking get to get all projection columns passed for records. categories.get(options, onGetSuccess, onGetFailure); //------ Example : get for distinct -------- function onGetSuccess(records) { //records is an array of records. Each record is a dictionary. } Function onGetFailure(error) { Kony.print("unable to retrieve records from database" + error.code); } var categories = new kony.sdk.KNYObj("CATEGORY"); var options = {}; options["distinct"] = true; var projectionColumnsList = []; projectionColumnsList.push("Category_PN"); options[“projectionColumns”] = projectionColumnsList; // Invoking get to get all distinct Category_PN records. categories.get(options, onGetSuccess, onGetFailure);
Android (Java)
Signature
void <KNYObj>.get(HashMap<String, Object> options, final KNYCallback callback) throws Exception
Parameters
Parameter | Type | Description | Required |
options | HashMap<String, Object> | If the options parameter is omitted, all records are returned. | Yes |
callback | KNYCallback |
Application must implement onSuccess and onFailure methods of KNYCallback interface. Read records are passed as an argument through onSuccess handler. onFailure handler takes cause of failure as an argument. |
Yes |
Options Keys
Keys | Type | Description | Required |
primaryKeys | HashMap<String, Object> | Specify the primary keys to use for the select query. Use records primary key column names as key and respective values to populate primaryKeys map. | No |
whereConditionAsAString |
String |
Specify the where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and the value is a string. | No |
orderByMap | List of HashMap<String, Object> | Specifies the way the data should be arranged in ascending/descending order of column name. Key Name: orderByMap and value is an array of the dictionary. | No |
whereCondition | HashMap<String, Object> | Map of column names and their respective values according to which the records are to be fetched. | No |
likeCondition | HashMap<String, Object> | Map of column names and their respective values according to which the records are to be fetched. | No |
projectionColumns | Array List< string> | List of column names which are returned. | No |
distinct | Boolean | Boolean value for getting the distinct value of the first projection column passed. | No |
Return Type
void
Example
KNYObj category = new KNYObj("CATEGORY"); //----- Example : Get all -------- HashMap<String,Object> finalMap = new HashMap<String, Object>(); category.get(finalMap, new KNYCallback() { @Override public void onSuccess(Object object) { Log.d("Object Read", "Object Read successful for category"); ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object; for (HashMap<String, String> record : records) { Log.d("CATEGORY_DES", record.get("CATEGORY_DES"); } } @Override public void onFailure(Object error) { OfflineObjectsException e=(OfflineObjectsException)error; Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage()); } }); //------- Example : getall with orderBy clause -------- HashMap<String,Object> finalMap = new HashMap<String, Object>(); HashMap<String, Object> orderByCondition1 = new HashMap<String, Object>(); HashMap<String, Object> orderByCondition2 = new HashMap<String, Object>(); orderByCondition1.put("CATEGORY_DES","ASC"); orderByCondition2.put("CATEGORY_ID","DESC"); List<HashMap<String, Object>> orderByMap = new ArrayList<HashMap<String, Object>>(); orderByMap.add(orderByCondition1); orderByMap.add(orderByCondition2); finalMap.put("orderByMap",orderByMap); category.get(finalMap, new KNYCallback() { @Override public void onSuccess(Object object) { Log.d("Object Read", "Object Read successful for category"); ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object; for (HashMap<String, Object> record : records) { Log.d("CATEGORY_DES", record.get("CATEGORY_DES"); } } @Override public void onFailure(Object error) { OfflineObjectsException e=(OfflineObjectsException)error; Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage()); } }); //------ Example : get by PK -------- HashMap<String,Object> finalMap = new HashMap<String, Object>(); HashMap<String,Object> primaryKeys = new HashMap<String, Object>(); primaryKeys.put("CATEGORY_ID","2233"); finalMap.put("primaryKeys",primaryKeys); category.get(finalMap, new KNYCallback() { @Override public void onSuccess(Object object) { Log.d("Object Read", "Object Read successful for category"); ArrayList<HashMap<String, String>> records = (ArrayList<HashMap<String, Object>>) object; for (HashMap<String, String> record : records) { Log.d("CATEGORY_DES", record.get("CATEGORY_DES"); } } @Override public void onFailure(Object error) { OfflineObjectsException e=(OfflineObjectsException)error; Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage()); } }); //---- Example : get by where clause -------- HashMap<String,Object> finalMap = new HashMap<String, Object>(); String whereClause = "CATEGORY_ID = '2233'"; finalMap.put("whereConditionAsAString",whereClause); category.get(finalMap, new KNYCallback() { @Override public void onSuccess(Object object) { Log.d("Object Read", "Object Read successful for category"); ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object; for (HashMap<String, Object> record : records) { Log.d("CATEGORY_DES", record.get("CATEGORY_DES"); } } @Override public void onFailure(Object error) { OfflineObjectsException e=(OfflineObjectsException)error; Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage()); } });
//--- Example : get for distinct ---
HashMap<String,Object> finalMap = new HashMap<String, Object>();
ArrayList<String> projectionColumnsList = new ArrayList<String>();
projectionColumnsList.add("CATEGORY_DES");
finalMap.put("distinct", true);
finalMap.put("projectionColumns" , projectionColumnsList);
category.get(finalMap, new KNYCallback() {
@Override
public void onSuccess(Object object) {
Log.d("Object Read", "Object Read successful for category");
ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object;
for (HashMap<String, String> record : records) {
Log.d("CATEGORY_DES", record.get("CATEGORY_DES");
}
}
@Override
public void onFailure(Object error)
{
OfflineObjectsException e=(OfflineObjectsException)error;
Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage());
}
});
iOS (Objective C)
Signature
void <KNYObj> get:(NSDictionary <NSString *, id> *)options onSuccess:(KNYSuccessCompletionHandler)onSuccess onFailure:(KNYFailureCompletionHandler)onFailure
Parameters
Parameter | Type | Description | Required |
options | NSDictionary<NSString*, id> | If the options parameter is omitted, all records are returned. | Yes |
onSuccess | KNYSuccessCompletionHandler | The function is invoked on success with records passed as an argument. | Yes |
onFailure | KNYFailureCompletionHandler | The function is invoked on an error with the cause of failure as an argument. | Yes |
Options Keys
Keys | Type | Description | Required |
primaryKeys | NSDictionary<NSString*, id> | Specify the primary keys to use for the select query. Use records primary key column names as key and respective values to populate primaryKeys dictionary. | No |
whereConditionAsAString | NSString | Specify the where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and value is a string. | No |
orderByMap | NSArray< NSDictionary<NSString *, id> *> | Specifies the way the data should be arranged in ascending/descending order of column name. Key Name: orderByMap and value is an array of the dictionary. | No |
whereCondition | NSDictionary<NSString *, id> | Dictionary of column names and their respective values according to which the records are to be fetched. | No |
likeCondition | NSDictionary<NSString *, id> | Dictionary of column names and their respective values according to which the records are to be fetched. | No |
projectionColumns | NSDictionary<NSString *, id> | Dictionary of column names which need to returned. | No |
distinct | Boolean | Boolean value for getting the distinct value of the first projection column passed. | No |
Return Type
void
Example
//----- Example : Get all -------- NSError * error; KNYObj * _categoryObject = [ [KNYObj alloc] initWithName: @"CATEGORY" error: & error ]; //Success handler KNYSuccessCompletionHandler onSuccess = ^ (id records) { NSLog(@"Records read from db successfully"); }; //Failure Handler KNYFailureCompletionHandler onError = ^ (id error) { NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]); }; [_categories get: @{} onSuccess: onSuccess onFailure: onError ]; //------- Example : getall with orderBy clause -------- NSError * error; KNYObj * _categoryObject = [ [KNYObj alloc] initWithName: @"CATEGORY" error: & error ]; NSArray * orderByClause = @ [@{ "CATEGORY_ID": "DESC" }, @ { "CATEGORY_PK": "ASC" }]; NSDictionary * options = @ { "orderBy": orderByClause }; //Success handler KNYSuccessCompletionHandler onSuccess = ^ (id records) { NSLog(@"Records read from db successfully"); }; //Failure Handler KNYFailureCompletionHandler onError = ^ (id error) { NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]); }; [_categories get: options onSuccess: onSuccess onFailure: onError]; //------ Example : get by PK -------- NSError * error; KNYObj * _categoryObject = [ [KNYObj alloc] initWithName: @"CATEGORY" error: & error ]; NSDictionary * primaryKeys = @ {@ "CATEGORY_ID": "2233" }; NSDictionary * options = @ { "primaryKeys": primaryKeys }; //Success handler KNYSuccessCompletionHandler onSuccess = ^ (id records) { NSLog(@"Records read from db successfully"); }; //Failure Handler KNYFailureCompletionHandler onError = ^ (id error) { NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]); }; [_categories get: options onSuccess: onSuccess onFailure: onError]; //---- Example : get by where clause -------- NSError * error; KNYObj * _categoryObject = [ [KNYObj alloc] initWithName: @"CATEGORY" error: & error ]; NSString * whereClause = "CATEGORY_ID = '2233'"; NSDictionary * options = @ { "whereClause": whereClause }; //Success handler KNYSuccessCompletionHandler onSuccess = ^ (id records) { NSLog(@"Records read from db successfully"); }; //Failure Handler KNYFailureCompletionHandler onError = ^ (id error) { NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]); }; [_categories get: options onSuccess: onSuccess onFailure: onError]; //------ Example: get for distinct ------- NSError * error; KNYObj * _categoryObject = [ [KNYObj alloc] initWithName: @"CATEGORY" error: & error ]; NSMutableDictionary * options = [ [NSMutableDictionary alloc] init ]; NSMutableArray * projectionColumnList = [NSMutableArray new]; [projectionColumnsList addObject: @"Category_PN"] [options setValue: YES forKey: @"distinct "]; [options setValues: projectionColumnList forKey: @"projectionColumns"]; //Success handler KNYSuccessCompletionHandler onSuccess = ^ (id records) { NSLog(@"Records read from db successfully"); }; //Failure Handler KNYFailureCompletionHandler onError = ^ (id error) { NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]); }; [_categories get: options onSuccess: onSuccess onFailure: onError];
NOTE: If more than one key amongst primaryKeys, whereCondition and whereConditionAsAString are passed in options, the records are fetched in the following priority primaryKeys > whereCondition > whereConditionAsAString. Applicable for all platforms.
NOTE: If both whereCondition and likeCondition are passed in options, the records are fetched in the following priority: whereCondition> likeCondition. Applicable for all platforms.