ZCQL

ZCQL is Catalyst’s own query language that enables you to perform data retrieval operations in the Data Store. It supports SELECT queries with built-in functions, SQL Join clauses, and other statements and conditions.

Execute a ZCQL Query

Before you execute a ZCQL query to fetch the required data set, you must construct the query to pass it to the execute() method. You can learn about the ZCQL syntax from the ZCQL help page.

You must pass an instance of ZCatalystSelectQuery to the execute() method, as shown in the code syntax of a ZCQL query execution below.

    
copy
<ZCatalystApp>.execute( query : ZCatalystSelectQuery, completion: @escaping (Result<[ [ String : Any ] ], ZCatalystError>) -> Void)

Parameters:

  • query: The instance of the type ZCatalystSelectQuery to be passed
  • completion: If the query execution call is successful, the completion block will return with the records that match the criteria of the query. Else, it will return an error.

You can create a query instance for the ZCatalystSelectQuery for the statements supported by ZCQL, in the following way:

    
copy
ZCatalystSelectQuery.Builder() .select(columns: Set<Column>) -> ZCatalystSelectQuery.Builder .selectAll() -> ZCatalystSelectQuery.Builder .where(column: String, comparator: Comparator, value: String) -> ZCatalystSelectQuery.Builder .from(tableName: String) -> ZCatalystSelectQuery.Builder .and(column: String, comparator: Comparator, value: String) -> ZCatalystSelectQuery.Builder .groupBy(columns: Set<Column>) -> ZCatalystSelectQuery.Builder .orderBy(columns: Set<Column>, sortOrder: SortOrder) -> ZCatalystSelectQuery.Builder .innerJoin(tableName: String) -> ZCatalystSelectQuery.Builder .leftJoin(tableName: String) -> ZCatalystSelectQuery.Builder .on(joinColumn1: String, comparator: Comparator, joinColumn2: String) -> ZCatalystSelectQuery.Builder .or(column: String, comparator: Comparator, value: String) -> ZCatalystSelectQuery.Builder .limit(offset: Int, value: Int? = nil) -> ZCatalystSelectQuery.Builder .build() -> ZCatalystSelectQuery

A sample code snippet of a ZCQL query execution is shown below:

    
copy
func testExecuteZCQL(){ var builder = ZCatalystSelectQuery.Builder() var query = builder.selectAll().from( tableName : "Bio-data" ).build() //replace your table name here ZCatalystApp.shared.getDataStoreInstance(tableIdentifier: "1096000000002071").execute( query : query) { ( result ) in switch result{ case .success( let response ) : print("Response : \( response )") case .error( let error ) : print( "Error occurred >>> \( error )" ) } } }

Last Updated 2023-09-14 18:05:46 +0530 +0530