Tuesday, August 21, 2018

Azure CosmosDB JavaScript SDK 2.0: Public Preview

Version 2.0 RC of the Azure Cosmos DB JavaScript SDK is available for public previews. You can use the node pckage manager to install in your project using the following command.

npm install @azure/cosmos


Azure Cosmos DB is a multi-model database service that is highly scalable. It also features turn key global distribution as well as transparent multi-master replication. The best part about this API is it is based on TypeScript. TypeScript has many implementations and improvements happened over the years. Also the version 2.0 has major changes to the prior version including support for on-premises implementations. 

Old SDK is based on the DocumentDBClient object and it was not that easy to find what you are looking for on IntelliSense as shown in the image below. That makes it look like a mess and need to type many more characters to find exactly what you are looking for.    

Also you needed to specify the resource url each time a method is referenced. 

Source: Azure Blog

The redesigned V2.0 object model is based on CosmosClient class. 
Unlike the previous versions, methods of this base class is split into Database, Container and Item classes thereafter. A fine example of creating a DB, container and adding an item can be seen below. 
Source: Azure Blog
This follows the builder pattern, which follows the hierarchy. Simply it shows how a person would think about hierarchy. Just like Tree --> Branch --> Leave. 

This will even help a new comer to understand the code in less than a few minutes. As it is said, best documentation for your code is the code itself. 

So, why wait? Read the full article on Azure Blog and start writing code from now.

No comments:

Post a Comment