0.0.3 • Published 8 years ago

@hypertext.solutions/simple-documentdb v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
8 years ago

Azure Cosmos DB Helpers

This project provides a small promise based API for working with Cosmos DB Document Databases.

Installation

npm install @hypertext.solutions/simple-documentdb --save

Create the client

const key = "your-key";
const endpoint = "https://your-server.documents.azure.com:443";
const simpleDocumentDb = require("@hypertext.solutions/simple-documentdb");

let client = simpleDocumentDb.create(endpoint, key, "your-database", "your-collection");

Read

Used for querying documents

client.read("SELECT * FROM ROOT")
  .then(results => console.log("All the documents", results))
  .catch(console.err);

Upsert (create/update)

Used for creating or updating a document

let document = { message: "I'm a new document" };

client.upsert(document)
  .then(result => console.log("The new document", result))
  .catch(console.err);

Delete

Used for deleting documents

client.read("SELECT * FROM ROOT")
  .then(results => {
    console.log("Deleting all documents");
    results.forEach(doc => {
      client.delete(doc)
        .then(deleted => console.log(`Deleted ${deleted._self}`))
        .catch(console.err);
    });
  })
  .catch(console.err);
0.0.3

8 years ago

0.0.2

8 years ago