@azure/cosmos has moved to a new repo https://github.com/Azure/azure-sdk-for-js
Перейти к файлу
Christopher Anderson 1173f1d224
TypeScript conversion (#3)
* 2.0.0-0

 * TypeScript Conversion

 * Promise support
2018-06-04 14:03:49 -07:00
.vscode TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
samples TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
src TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
.editorConfig Added an editorConfig 2017-01-18 12:56:28 +01:00
.gitattributes adding .git* 2014-08-26 08:25:08 -07:00
.gitignore TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
Contributing.md Node.js SDK Release 1.7.0 2016-04-26 13:21:42 -07:00
Gruntfile.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
LICENSE TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
README.md TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
SDK + Samples Workspace.code-workspace TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
browser-test.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
changelog.md TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
dev.md TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
karma.config.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
package-lock.json TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
package.json TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
tsconfig.json TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
tslint.json TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
webpack.config.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00

README.md

Microsoft Azure Cosmos JavaScript SDK

This project provides JavaScript & Node.js SDK library for SQL API of Azure Cosmos Database Service. This project also includes samples, tools, and utilities.

Useful links:

Installation

Prerequisites

Install Node.js and npm https://docs.npmjs.com/getting-started/installing-node

Node SDK can be consumed in two ways.

Install Core Module Published to NPM

The core module uses the callbacks model for responses, exposed through the DocumentClient

npm install @azure/cosmos

Install Core Module From Github

  1. Clone Azure/azure-documentdb-node repository Please clone the source and tests from https://github.com/Azure/azure-documentdb-node

  2. Install documentdb

     npm install azure-documentdb-node\source
    

Prerequisites

To use the SDK, first create an account and follow tutorial.

Note:

When connecting to the emulator from the SDK, SSL verification is disabled.

Follow these instructions to run the tests locally.

Tests

Prerequisites

  1. Clone Azure/azure-cosmos-js repository
git clone https://github.com/azure/azure-cosmos-js.git
  1. Install Node.js and npm https://docs.npmjs.com/getting-started/installing-node

  2. Cosmos DB emulator

    • Note: requires a windows machine or ability to run Windows container
  3. Install dependencies

    npm i     # alias for npm install
    
  4. Build the source

    npm run build   # compiles the typescript source, runs linting, creates webpack, creates docs
    

Running the tests

npm run test    # runs all tests

Examples

Hello World

import { CosmosClient } from "@azure/cosmos"

const host = "[hostendpoint]";                     // Add your endpoint
const masterKey = "[database account masterkey]";  // Add the masterkey of the endpoint
const client = new CosmosClient(host, { masterKey });

var databaseDefinition = { id: "sample database" };
var collectionDefinition = { id: "sample collection" };
var documentDefinition = { id: "hello world doc", content: "Hello World!" };

async function helloCosmos() {
    await client.createDatabase(databaseDefinition);
    console.log('created db');

    await client.createCollection(database._self, collectionDefinition);
    console.log('created collection');

    await client.createDocument(collection._self, documentDefinition);
    console.log('Created Document with content: ', document.content);

    await client.deleteDatabase(database._self);
    console.log("Deleted database");
});

helloCosmos().finally(()=>{});

Youtube Videos

Getting started with Node.js SDK:

Azure Demo: Getting started with Document Node.js SDK

Need Help?

Be sure to check out the Microsoft Azure Developer Forums on MSDN or the Developer Forums on Stack Overflow if you have trouble with the provided code.

Contribute Code or Provide Feedback

If you would like to become an active contributor to this project please follow the instructions provided in Azure Projects Contribution Guidelines.

If you encounter any bugs with the library please file an issue in the Issues section of the project.