Skip to content

Retrieving Schema Definition

Backendless provides API for data table schema introspection. The API returns information about table's columns and their data types, whether a value for a column is required or if there is a default value.

Non-Blocking API

Backendless.Persistence.describe( String tableName, AsyncCallback<List<ObjectProperty>> callback )

where:

Argument                Description
tableName name of the table to get the schema definition for.
callback a responder with references to the methods called back upon successful invocation or an error.

Blocking API

public List<ObjectProperty> Backendless.Persistence.describe( String tableName )

where:

Argument                Description
tableName name of the table to get the schema definition for.

Return value

Method returns a collection of the ObjectProperty instances. The ObjectProperty class includes the following Java bean properties:

Argument                Description
boolean autoLoad applies only to relations. If true, the property is set to auto-load related data for the data retrieval queries.
String customRegex a regular expression assigned to the column as a validator. The validator applies when a new object is saved in the table or an existing one is updated.
Object defaultValue a default value assigned to any object saved/updated in the table where the column does not have a value.
boolean isPrimaryKey true if the column is or is a part of a primary key.
String name contains the name of a property Consider the
String relatedTable contains the name of the related table(s)
boolean required defines whether a property is optional or required for the requests which save the initial object or update an existing one.
String type defines the property type

Example

Suppose the Person table has the following schema - there are two data columns, age and name.

person-schema.zoom70

The following code retrieves the schema definition for the Person table:

Backendless.Persistence.describe( "Person", new AsyncCallback<List<ObjectProperty>>() 
   { 
     public void handleResponse( List<ObjectProperty> tableProperties ) 
     {     
       Iterator<ObjectProperty> iterator = tableProperties;

       while( iterator.hasMore() )
       {
         ObjectProperty propDef = iterator.next();
         Log.i( "MYAPP", "property name - " + propDef.getName() );
         Log.i( "MYAPP", "\tis property required - " + propDef.isRequired() );
         Log.i( "MYAPP", "\tproperty data type - " + propDef.getType() );
         Log.i( "MYAPP", "\tdefault value - " + propDef.getDefaultValue() );
         Log.i( "MYAPP", "\tis property identity - " + propDef.getPrimaryKey() );
       }
     } 

     public void handleFault( BackendlessFault backendlessFault ) 
     {              
     } 
} );
The code produces the following output:
property name - objectId  
   is property required - false   
   property data type - STRING_ID  
   default value - null  
   is property primary key - true  
property name - age   
   is property required - false   
   property data type - INT   
   default value - null   
   is property primary key - false   
property name - updated   
   is property required - false   
   property data type - DATETIME   
   default value - null   
   is property primary key - false   
property name - name   
   is property required - false   
   property data type - STRING   
   default value - null   
   is property primary key - false   
property name - created   
   is property required - false   
   property data type - DATETIME   
   default value - null   
   is property primary key - false   
property name - ownerId   
   is property required - false  
   property data type - STRING   
   default value - null   
   is property primary key - false