0.1.0 • Published 4 years ago

@hypertext.solutions/simple-documentdb-client v0.1.0

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

Simple Document DB client

This project provides a small promise based wrapper around the documentdb package. The goal is to provide an simpler and promise based API for working with Azure Cosmos DB Document Databases.

Installation

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

Create the client

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

let client = clientFactory(endpoint, key, db, collection);

Query

Used for querying documents

client.query("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.query("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.1.0

4 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.1

6 years ago