Type Function Return value none Revision Release 2022.3683 Keywords iCloud, sync, storage, CloudKit, recordQuery See also iCloud.recordFetch() iCloudRecordEvent iCloud.*
Retrieves existing records based on a defined query and passes the results to the onComplete
listener function as iCloudRecordEvent.recordArray.
You must pass a predicate to filter records. Predicates are formed according to Apple's documentation.
iCloud.recordQuery( params )
Table. Table containing
Valid keys for the params
table include:
type
— Required string value indicating the type of records to be queried.
query
— Required string value indicating the query. Use "TRUEPREDICATE"
to retrieve all records, or consult Apple's documentation for more sophisticated query options.
onComplete
— Required listener function to be invoked with an iCloudRecordEvent.
queryParams
— Optional table value used to search for certain values and escape them with Apple's predicate mechanism. See Apple's documentation for more information.
database
— Optional string value indicating the database to query.
containerId
— Optional string value indicating a specific iCloud Container to query. Do not pass this parameter if you have only one iCloud Container associated with your app.
local json = require( "json" ) function queryResults( event ) if event.recordArray then print( "Total records retrieved: ", #event.recordArray ) if #event.recordArray > 0 then for r = 1,#event.recordArray do print( "----------" ) print( json.prettify( event.recordArray[r]:table() ) ) print( "----------" ) end end else print( "No records found!" ) end end iCloud.recordQuery( { type = "people", query = "TRUEPREDICATE", onComplete = queryResults } )