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-initializer

v1.0.4

Published

A tool to initialise documentDb base on config

Downloads

7

Readme

DocumentDb initializer

This is a npm package to initialise and update a collection in document db. You can create and update store procedure, trigger and seed data in a collection using npm commandline.

Please refer to github for more detail.

Installation

npm install documentdb-initializer -g

Usage

docdb <config-file-path>

should be the realted path to the path you run the command (current wokrking directory).

Configuration

Example of config file:

{
    "url": "<url>",
    "key": "<key>",
    "database": "<databaseId>",
    "collection": "<collectionId>",
    "storedProcPath": "<path-to-storeProcs>",
    "triggerPath": "<path-to-triggers>",
    "documentPath": "<path-to-documents>",
    "userDefinedFunctionPath": "<path-to-userDefinedFunction>"
}
  • url: The url to connect to your documentdb
  • key: The key to use to connect to your documentdb
  • database: the database name/id
  • collection: the collection name/id
  • storedProcPath: The related path of current working directory to the folder that you keep your stored procedure files. The format of the files please refer to the File Format section.
  • triggerPath: The related path of current working directory to the folder that you keep your trigger files. The format of the files please refer to the File Format section.
  • documentPath: The related path of current working directory to the folder that you keep your document files. The format of the files please refer to the File Format section.
  • userDefinedFunctionPath: The related path of current working directory to the folder that you keep your stored procedure files. The format of the files please refer to the File Format section.

###File Format

Stored proc, trigger, document and user defined function should be in one or multiple js files kept in your configured path. The js script should assign the script configuration object to a variable named objs.

Please refer to Microsoft Azure DocumentDB Node.js SDK Documentation for detail documentation of the configuration object.

Example of Stored Proc File:

var objs = [{
    id: "helloWorld",
    serverScript: function () {
        var context = getContext();
        var response = context.getResponse();

        response.setBody("Hello, World");
    }
},
{
    id: "helloWorld2",
    serverScript: function () {
        var context = getContext();
        var response = context.getResponse();

        response.setBody("Hello, World2");
    }
}]

Example of Trigger file:

var objs = [{
        id: "validateName",
        triggerType: "Pre",
        triggerOperation: "All",
        serverScript: function () {
              var collection = getContext().getCollection();
              var request = getContext().getRequest();
              var docToCreate = request.getBody();
            
              // Reject documents that do not have a name property by throwing an exception.
              if (!docToCreate.name) {
                throw new Error('Document must include a "name" property.');
              }
        }
}]

Example of Document file:

var objs = [
    {
        id: "testDocument1",
        name: "testName1"
    },
    {
        id: "testDocument2",
        name: "testName2"
    },
    {
        id: "testDocument3",
        name: "testName3"
    }
]

Example of UserDefinedFunction file:

var objs = [{
    id: "tax",
    serverScript: function tax(income) {
        if(income == undefined) 
            throw 'no input';

        if (income < 1000) 
            return income * 0.1;
        else if (income < 10000) 
            return income * 0.2;
        else
            return income * 0.4;
    }
}]

Ongoing....