If you think that March was an exciting month for the Telerik Platform with the introduction of Windows Phone 8 support, CLI and Sublime integration for AppBuilder, you should prepare yourself for what’s coming in April.

We are starting the month with a set of improvements coming to our Backend Services that include support for expanding relational data and Data Connectors to MS SQL, Oracle and MySQL as part of our private beta.

Support for expanding relations

Even though the Backend Services use NoSQL datastore behind the scenes, there is a way to define relations between content types that are handy when you want to use some of the benefits of a relational datastore. With this release, we are introducing the ability to expand data from related content types with a single request.This is important when you want to minimize the round trips to the server from the client, and retrieve the necessary data with minimum number of requests. The support is now available for all Backend Services SDKs.

In order to see the power of expand, let’s dive into a quick example where we have two content types Teams and Players with many-to-many relations between the them, so that each player can participate in more than one team.

The Players type will have two fields PlayerName and Age, while the Teams type will define TeamName and PlayerIDs which is a defined as many-to-many relation to Players as shown below.


After some manual data entry, here is how our Teams content type looks like:

Support in all Backend Services SDKs and REST layer


Now, if we execute a regular GET request to the Teams type, we will get each Team in the following format where we need to either make additional requests to get the Players, or use PowerFields expression to retrieve the related items.

{
   "Id":"4cd5b080-bfb7-11e3-9614-f50276fccf56",
   "TeamName":"Team A",
   "PlayerIDs":[
      "5e5ab490-bfb7-11e3-9614-f50276fccf56",
      "621572a0-bfb7-11e3-9614-f50276fccf56",
      "6697ed80-bfb7-11e3-9614-f50276fccf56"
   ]
}

With the included support for expand, we can simply pass a header X-Everlive-Expand in the GET request with value {“PlayerIDs” : true} and we will receive the following result:

{
   "Id":"4cd5b080-bfb7-11e3-9614-f50276fccf56",
   "TeamName":"Team A",
   "PlayerIDs":[
      {
         "Age":20,
         "PlayerName":"Player 1",
         "Id":"5e5ab490-bfb7-11e3-9614-f50276fccf56"
      },
      {
         "Age":25,
         "PlayerName":"Player 2",
         "Id":"621572a0-bfb7-11e3-9614-f50276fccf56"
      },
      {
         "Age":16,
         "PlayerName":"Player 3",
         "Id":"6697ed80-bfb7-11e3-9614-f50276fccf56"
      }
   ]
}

Note: I have omitted the default fields returned by the Backend Services such as CreatedBy,ModifiedBy, CreatedAt and ModifiedAt for clarity. The actual response for the server will include them, but there is a way to define which fields you want to get from the relation.

You don't have to worry about setting this header when working with our SDKs, since this features comes with full support in the Backend Services JavaScript, iOS, Android, and .NET SDKs. 

Support for Kendo UI HierarchicalDataSource


With this release we are also improving our support for Kendo UI HierarchicalDataSource that can be used to bind widgets like ListView or TreeView. The Backend Services provide a helper constructor for initializing the Kendo UI HierarchicalDataSource component with all supported configurations which rely on the new expand feature.

Let’s bind our Teams and Players content types to a Kendo UI TreeView to see that in practice. We have to simply initialize our Everlive JavaScript SDK with an ApiKey, and configure the datasource to look for content type Teams and expand the PlayerIDs field.

var el = new Everlive('your-api-key');
 
var ds = Everlive.createHierarchicalDataSource({
    "typeName": "Teams",
    "expand" : ["PlayerIDs"]
    });
 
$("#itemList").kendoTreeView({
    dataSource: ds,
    dataTextField: ["TeamName", "PlayerName"]
    });

And booom…. 

Just like that, we have a Kendo UI TreeView binded to your content types with “lazy” loading which means that the first time a user clicks on a TreeView item it will make an additional request to the Backend Services to retrieve the related items. We also support loading all data with a single request called “eager” loading that you can learn more about in our docs.

The Expand also supports complex expressions where you can order the expanded data and apply filters, so you really get what you need with minimum code! Let’s order all players in alphabetical order and get only players that are above 20 years old based on our Age field in the Players table that we defined earlier:

var el = new Everlive('your-api-key');
 
var playersExpandExpression = {
    relation: "PlayerIDs",
        filter: {
            Age: {
                $gt: 20
                }
            },
        sort: {
            "PlayerName": 1
            }
    };
            
var ds = Everlive.createHierarchicalDataSource({
    "typeName": "Teams",
    "expand" :[ playersExpandExpression ]
    });
 
$("#itemList").kendoTreeView({
    dataSource: ds,
    dataTextField: ["TeamName", "PlayerName"]
    });

Which results in a list of sorted children for the TreeView and filtered players:
We also support the ability to expand just some of the fields, or even expand items on multiple levels, so you can get related data to the Players table above as well. You can read more about Expand and all the goodies it provides in the Backend Services Expand docs.

Data Connectors for Microsoft SQL Server, Oracle and MySQL as private beta

 

With this release we are introducing Data Connectors for Microsoft SQL Server, Oracle and MySQL as part of our Backend Services private beta. You can request to join our private beta here.

Data Connectors are powerful way to mobilize enterprise data residing in databases part of your corporate infrastructure. Using the new Create Type from Data Connector option you can create Types that talk directly to a table or view in your database. These Content Types also provide support for Create, Read, Update, Delete (CRUD) operations, as well as filtering and sorting mechanism. In order to use Data Connectors, you also need to setup a tiny Data Link Server that is hosted in IIS and has network access to your database.

Screenshot 2014-04-06 11.38.57.png
There is a small wizard that guides you through all steps you need to execute to create content types based on tables or views of your database. You can map just a selection of fields coming from the legacy databases giving you flexibility to create powerful light-weight services with full filtering and sorting mechanism.

Screenshot 2014-04-06 11.44.08.png

Once created, the Backend Services will treat your content type from Data Connectors as a regular type. This means that you can use all Backend Services SDKs without any additional logic, and also benefit from the easy to use Backend portal to manage your data. 

It’s important to note that any additional logic you have on the database layer such as triggers or cascade deleting will work as expected, since the Data Link Server is executing standard T-SQL statements against your database. Also any constraints and required fields that are not met during the CRUD operation are bubbled up to the Backend Services REST layer giving you exact information why your operations are failing.

Here is an example where we have 2 Data Connectors to MS SQL server stored in Windows Azure and Rackspace that are simply treated as standard Backend Services content types, but don’t store any of its data in our Backend Services.


If you are new to the Telerik Platform, you can sign-up for free and enjoy a 30 day free trial.


About the Author

Hristo Borisov

Hristo Borisov (@hristoborisov) is currently a product line manager in Telerik leading all cloud technologies part of the Telerik Platform after spending more than 6 years with the company. A passionate advocate of applying lean startup practices to existing organizations, Hristo is on the quest for discovering scalable and sustainable business models through product and customer development using tools like MVPs, Pivots, and Lean Business Model Canvases.

Related Posts

Comments

Comments are disabled in preview mode.