Get Column Metadata

Get the Metadata of a Specific Column

You can obtain the metadata of a single specific column of a Data Store table of the given instance by calling the getColumn() method. If the operation is successful, this method can return the metadata of the column, such as its data type, default value, or maximum length, or whether it is read only, unique, or mandatory.

The metadata of a specific column can be fetched in two different ways. The <TABLE_INSTANCE> used in both the methods is the instance defined in the Table Instance page.

i. Get a Column by its ID

You can retrieve a specific column’s metadata by passing the column ID as the argument to the getColumn() method in the String format, as shown in the code structure below:

    
copy
<TABLE_INSTANCE>.getColumn( String id, void Function(ZCatalystColumn) onSuccess, void Function(ZCatalystException) onFailed )

Parameters:

A sample code snippet is shown below:

    
copy
var table = dataStore.getTableInstance(identifier: 'Products'); table.getColumn( id: "'2823000000014176", onSuccess: (APIResponse response, ZCatalystRow row) { print('Get Row Success'); print('The row details are: ${row.getData()}'); //Actions to be executed upon successfully fetching a column }, onFailed: (ZCatalystException exception) { print('Get Row failed: $exception'); //Actions to be executed upon a failed state }, );

ii. Get a Column by its Name

You can retrieve a specific column’s metadata by passing the column’s name as the argument to the getColumn() method, as shown in the code syntax below:

    
copy
<TABLE_INSTANCE>.getColumn( String name, void Function(ZCatalystColumn) onSuccess, void Function(ZCatalystException) onFailed )

Parameters:

  • name: The name of the particular column that needs to be retrieved

A sample code snippet is shown below:

    
copy
var table = dataStore.getTableInstance(identifier: 'Products'); table.getColumn( identifier: "product_name", //Specifying the column by its name onSuccess: (APIResponse response, ZCatalystColumn column) { print('Get Column Success'); print('The name of the column is ${column.name}'); //Actions to be executed upon successfully fetching a column }, onFailed: (ZCatalystException exception) { print('Get Column failed: $exception'); //Actions to be executed upon a failed state }, );

Get the Metadata of all Columns

You can retrieve the metadata of all the columns of a table of the given instance, using the getColumns() method, as shown in the code syntax below. If the operation is successful, this method can return the metadata of all the columns of the specific table.

The <TABLE_INSTANCE> used in the code below is the instance defined in the Table Instance page.

    
copy
<TABLE_INSTANCE>.getColumns( void Function(List) onSuccess, void Function(ZCatalystException) onFailed )

A sample code snippet is shown below:

    
copy
var table = dataStore.getTableInstance(identifier: 'Products'); table.getColumns( onSuccess: (APIResponse response, List columns) { print('The columns of the table are :'); for (var column in columns) { print(column.name); //Actions to be executed upon successfully fetching column } }, onFailed: (ZCatalystException exception) { print('Get Columns failed: $exception'); //Actions to be executed upon a failed state }, );

Last Updated 2023-09-03 01:06:41 +0530 +0530