Backendless Support
 

Retrieving database/table schema using API

Backendless provides an easy way to use API for introspecting data tables. Given a table name, the API provides information about table columns, their names, data types, default values, etc. 

If a column represents a relationship, it is properly denoted as such in the provided information.

Consider the following data table - the table name is Person as it is indicated in the upper right corner: 

The following code retrieves the schema information for the table.

Asynchronous API sample (Android and Plain Java):

Backendless.Data.describe( "Person", new AsyncCallback<List<ObjectProperty>>()
{
 @Override
 public void handleResponse( List<ObjectProperty> schema )
 {
 Iterator<ObjectProperty> iterator = schema.iterator();
 while( iterator.hasNext() )
 {
 ObjectProperty property = iterator.next();
 System.out.println( "Column name - " + property.getName() );
 System.out.println( "Data type - " + property.getType() );
 System.out.println( "Default value - " + property.getDefaultValue() );
 System.out.println( "----------------------------" );
 }
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
 }
} );
Synchronous API sample (Plain Java only):
List<ObjectProperty> schema = Backendless.Data.describe( "Person" );
Iterator<ObjectProperty> iterator = schema.iterator();
while( iterator.hasNext() )
{
 ObjectProperty property = iterator.next();
 System.out.println( "Column name - " + property.getName() );
 System.out.println( "Data type - " + property.getType() );
 System.out.println( "Default value - " + property.getDefaultValue() );
 System.out.println( "----------------------------" );
}
The code produces the following output:
Column name - created
Data type - DATETIME
Default value - null
----------------------------
Column name - updated
Data type - DATETIME
Default value - null
----------------------------
Column name - birthday
Data type - DATETIME
Default value - null
----------------------------
Column name - name
Data type - STRING
Default value - null
----------------------------
Column name - age
Data type - INT
Default value - null
----------------------------
Column name - ownerId
Data type - STRING
Default value - null
----------------------------
Column name - objectId
Data type - STRING_ID
Default value - null
----------------------------
Is article helpful?