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

cosmos-db-writer-ssl-fixed

v1.1.10

Published

This module is for performing CRUD operations into azure cosmos DB.

Downloads

1

Readme

cosmos-db-writer

Description

This module is for performing CRUD operations into azure cosmos DB.

Install

npm install cosmos-db-writer --save

Usage Example


const  cosmosDB = require('cosmos-db-writer');

let  options = {
//Cosmos db endpoint
endpoint:"",
//cosmos db primary key for your subscription
primaryKey:"",
//name for your database
dbName:"",
//name for your container
containerName:"",
// container paths for multi country database for ex. ["/Country"]
containerPaths: [],
// throughput  for  your  transactions  ex. 400
throughput:400,
// environment  you  are  working  into, example local, others
environment:""
}

cosmosDB.init(options, function(error){

// check for error.

});

//Normal fields to write in cosmos db

let  dataFields = {"key1":"value1","key2":"value2"};

//fields to be read from request context which you have set
// here key will be the field name in cosmos db and value will be thekey for request context
// for example {"userId":"request:userId"}
let  requestFields = {"key1":"value1","key2":"value2"};

let  dataOptions={

"dataFields":dataFields,
// this field is optional, use it only if you are setting some request context fields like userId
"requestFields":requestFields 

}
// containerName and callback is optional for write operation default container is the one you initialized in init method.
cosmosDB.write(dataOptions,[containerName] ,[callback]);


// *****************query data from container********************* /
let options = {};
    options.clauses = [];    
    // set where clauses for your query, operator is for field and value, Logical Operator is for between different clauses
    let clause = new cosmosDB.Clause();
    clause.setField("field");
    clause.setValue("value");
    //{'EQ':'=', 'NEQ':'!=', 'GT':'>', 'LT':'<', 'GTE':'>=', 'LTE': '<=', 'NEQD':'<>'}
    clause.setOperator(clause.operatorEnum.EQ);
    //{'AND':'AND', 'OR':'OR'}
    clause.setLogicalOperator(clause.logicalOperatorEnum.OR);
    // groupid for same group like (field1=value1 OR field2=value2)
    clause.setGroup('grp2');
    // Operator for complete group with othere groups like (field1=value1 OR field2=value2) AND(field3=value3 OR field4=value4)
    clause.setGroupOperator('AND');
    options.clauses.push(clause);
    });
// pass fields which you want to retrieve
options.fields = ["id","userId","emailId","taskId"];

// set 
options.orderBy = {"field":"id", "order":"DESC"};

cosmosDB.query(options,[containerName],function(err, response){
    //handle error and response here
});



// ********read specific item, it will with partition key as of now *********** /

let options = {};
options.id = "1233"// id of item to read
options.partitionKey = "India" // value for the partition key for ex India, if your partion key is country
cosmosDB.read(options,[containerName],function(err, response){
     //handle error and response here
});

// *****************partial update an existing Item -- Partial update require partition key ******* /
let options = {};
options.id = "123";
options.partial= true;
options.updateFields =[{"name":"taskId","value":"12345"}],// give the list of properties you want to update withe the mentioned new value
options.partitionKey = "India" // value for the partition key for ex India, if your partion key is 

cosmosDB.partialUpdate(options,[containerName],function(err, response){
        //handle error and response here
}

// ********************* update an existing Item -- full update require complete itemBody ********* /
let options = {};
options.id = "123";
options.partial= false;
options.itemBody = {
"id":"123",
"name":"name of item"// pass complete object to relace the existing item
} 

cosmosDB.update(options,[containerName],function(err, response){
        //handle error and response here
}

// *************** delete an item ********** /

let options = {};
options.id = "123";
options.partitionKey = "India" // value for the partition key for ex India, if your partion key is 
cosmosDB.delete(options,[containerName],function(err, response){
        //handle error and response here
}

Versioning

1.1.3.

Authors

Ankit Choudhary

License

MIT

Acknowledgments

Hat tip to anyone whose code was used