@hypertext.solutions/cosmos-db

0.0.1 • Public • Published

Azure Cosmos DB Helpers

This project provides a set of helper functions to make working with Cosmos DB simpler and promise based.

Read

Used for querying documents

const key = "<key>";
const endpoint = "<endpoint>";
const cosmos = require("cosmos-db");

let client = cosmos.create(endpoint, key, <db>, <collection>);

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

const key = "<key>";
const endpoint = "<endpoint>";
const cosmos = require("cosmos-db");

let client = cosmos.create(endpoint, key, <db>, <collection>);

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

const key = "<key>";
const endpoint = "<endpoint>";
const cosmos = require("cosmos-db");

let client = cosmos.create(endpoint, key, <db>, <collection>);

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);

Readme

Keywords

none

Package Sidebar

Install

npm i @hypertext.solutions/cosmos-db

Weekly Downloads

1

Version

0.0.1

License

ISC

Last publish

Collaborators

  • anson.goldade