Azure Cosmos DB JavaScript SDK 2.0 now generally available

Version 2.0 of the Azure Cosmos DB JavaScript SDK is now generally available. Thank you to all who tried the preview and gave feedback!

In this release, we’ve added support for multi-region writes, a new “fluent” style object model – making it easier to reference Azure Cosmos DB resources without an explicit URL– and support for promises and other modern JavaScript features. It is also written in TypeScript and supports the latest TypeScript 3.0.

npmInstall

What is Azure Cosmos DB?

Azure Cosmos DB is a globally distributed, multi-model database service. It offers turnkey global distribution, guarantees single-digit millisecond latencies at the 99th percentile, elastic scaling of throughput and storage, and comprehensive SLA’s.

New object model

Based on your feedback, we’ve redesigned the object model to make it easier to interact with and perform operations against Cosmos DB.

We’ve created a new top level CosmosClient class to replace DocumentDBClient, and split up its methods into modular Database, Container, and Items classes. This new API surface enables a “builder” or “fluent” pattern. For example, to create an item, we first reference its database and container, and call items.create(). This removes the need to build an explicit URL to reference a resource.

As a result, you can create a new database, container, and add an item in only 10 lines of code!

helloCosmos

In addition, because Azure Cosmos DB supports multiple API models, we’ve introduced the concept of Container and Item into the SDK, to replace the previous Collection and Document concepts. What was previously known as a “Collection” is now called a “Container.”

Support for promises and modern JavaScript features

We’ve added full support for promises so you no longer have to write custom code to wrap the SDK yourself. Now, you can use async/await by awaiting the calls to Azure Cosmos DB directly from inside an async function.

We’ve also added a convenience method createIfNotExists() for databases and containers, which wraps the logic to read the database, check the status code, and create it if it doesn’t exist.

Finally, we’ve added support for async iterators, a modern JavaScript feature.

createAndAsyncIterator

Multi-region writes support

With Azure Cosmos DB multi-region writes, developers can build globally distributed apps that can read and write data to any Azure region in the world. To use the new SDK with multi-region writes, get started with samples.

Open Source model

The Azure Cosmos DB JavaScript SDK is open source, and our team is planning to do all development in the open. To that end, we will be logging issues, tracking feedback, and accepting PR’s in GitHub.

Getting started

To get started with the new SDK, go to the GitHub repo and follow the quick start. We’d love to hear your feedback! Email askcosmosdb@microsoft.com or log issues in our GitHub repo.

npmInstall

Stay up-to-date on the latest Azure #CosmosDB news and features by following us on Twitter @AzureCosmosDB. We are really excited to see what you will build with Azure Cosmos DB!

 

Source: Azure Blog Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.