npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

documentdb-client

v4.2.1

Published

DocumentDB wrapper with automatic indexing

Downloads

6

Readme

documentdb-client Build Status

Convenience module for wrapping a DocumentDB collection with automatic indexing.

Usage

const DB = require('documentdb-client')
const db = DB({
  databaseId: 'my-documentdb',
  host: 'https://my-documentdb.documents.azure.com:443/',
  masterKey: 'q7dMeDOhIUASP2GtWRPnrbZ6K7IO91AgaYiOCsvImmoUJKRSTjI7CNf0mEehGh4czRo17yED5AmPN1wERf367=='
})

const coll = db.createCollection('my-collection')
const data = { some: 'value' }
coll.put('1234', data, function (err, result) {
  coll.get(data.id, function (err, result) {
    if (!err) console.log('.get() OK', JSON.stringify(result, null, 2))
  })
})

Api

const db = DB(options)

Creates a DocumentDB client where options take the following properties:

  • databaseId (string) database id
  • host (string) database host
  • masterKey (string) database master key
  • idProperty (string, optional) the id property of the data, defaults to 'id'
  • consistencyLevel (string, optional) consistency level, defaults to 'Strong'

The database will be created if it doesn't exist.

const coll = db.createCollection(id)

Returns a Collection object. Creates the collection if it doesn't exist.

coll.put(id, data, cb)

Stores data document with id. On success, calls back with the same JSON document with additional meta data properties set by DocumentDB.

Example of meta data properties:

{
  "key1": "value1",
  "key2": "value2",
  "id": "AGJMqmtbTVarTf",
  "_rid": "Mwl6APp1TAAXBBBBBB==",
  "_self": "dbs/Mwl6AA==/colls/Mwl6APp1TAA=/docs/Mwl6APp1TAAXBBBBBB==/",
  "_etag": "\"00000800-0000-0000-0000-5744210b0000\"",
  "_attachments": "attachments/",
  "_ts": 1464082697
}

If put is called with data and data._self exists then the document will be updated with the new data.

coll.upsert(id, data, cb)

Atomic create/update. This is to be preferred over .put() which is for backwards compatibility.

coll.get(id, cb)

Gets a document from a collection. Calls back with data stored at id.

coll.delete(id, cb)

Deletes a document from a collection.

coll.query(q, opts, cb)

A simplified query mechanism that builds a sql query based on properties of q. If you want more control use .sqlquery() which takes custom query objects.

  • q object with properties to query for
  • opts object
  • opts.orderby order based on this property
  • opts.sortby sort by ascending ('asc') or descending ('desc'), default is 'asc'
  • opts.limit limit the results
  • opts.offset offset of limited results

Get all documents with the property foo set to 'bar', limit the results to 10 and offset 10.

coll.query({ foo: 'bar' }, { LIMIT: 10, OFFSET: 10 }, cb)

The query object supports a simple way of quering for multiple values.

Get all documents with foo set to 'bar' or 'baz' with ts less than 1478008742351.

coll.query({ foo: [ 'bar', 'baz' ], ts: 'lt(1478008742351)' }, cb)

Supported operators:

  • '=' equality (default)
  • '<' less than, lt(314)
  • '<=' less than or equal, lte(314)
  • '>' greater than, gt(314)
  • '>=' greater than or equal, gte(314)

coll.sqlquery(query, cb)

Queries a collection using an SQL query.

Example of a query using the document id:

const query = {
  query: 'SELECT * FROM root r WHERE r.id = @id',
  parameters: [{ name: '@id', value: id }]
}

License

MIT