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.Data.Describe( string tableName, AsyncCallback<List<ObjectProperty>> callback )
Blocking API¶
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
objects. The ObjectProperty
class includes the following properties:
Argument | Description |
---|---|
autoLoad:boolean |
applies only to relations. If true, the property is set to auto-load related data for the data retrieval queries. |
CustomRegex:String |
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. |
DefaultValue:Object |
a default value assigned to any object saved/updated in the table where the column does not have a value. |
PrimaryKey:bool |
true if the column is or is a part of a primary key. |
Name:String |
contains the name of a property. |
RelatedTable:String |
contains the name of the related table(s). |
IsRequired:boolean |
defines whether a property is optional or required for the requests which save the initial object or update an existing one. |
Type:DateTypeEnum |
defines the column type. |
Example¶
Suppose the Person
table has the following schema - there are two data columns, age
and name
.
The following code retrieves the schema definition for the Person
table:
List<ObjectProperty> properties = Backendless.Persistence.Describe( "Person" );
foreach( ObjectProperty property in properties )
{
System.Console.WriteLine( "property name - " + propDef.Name );
System.Console.WriteLine( "\tis property required - " + propDef.IsRequired );
System.Console.WriteLine( "\tproperty data type - " + propDef.Type );
System.Console.WriteLine( "\tdefault value - " + propDef.DefaultValue );
System.Console.WriteLine( "\tis property identity - " + propDef.PrimaryKey );
System.Console.WriteLine( "=====================================" );
}
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