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.

Method

Future<List<ObjectProperty>> Backendless.data.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 properties:

Argument                Description
Object defaultValue a default value assigned to any object saved/updated in the table where the column does not have a value.
String name contains the name of a property
String relatedTable contains the name of the related table(s)
bool required defines whether a property is optional or required for the requests which save the initial object or update an existing one.
DataTypeEnum 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.data.describe("Person").then((tableProperties) {     
  tableProperties.forEach((propDef) {
    print("property name - ${propDef.name}");
    print("\tis property required - ${propDef.required}");
    print("\tproperty data type - ${propDef.type}");
    print("\tdefault value - ${propDef.defaultValue}");
  });
});
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