Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

azure-storage-simple

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azure-storage-simple

Simplified Interfaces for Azure Storage Services (Tables, Queues, Blob)

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-22.22%
Maintainers
1
Weekly downloads
 
Created
Source

node-azure-storage-simple

Simplified interfaces for Azure Storage (Tables, Queues, Blob)

This is an opinionated interface using Promises. You can use the promises interface's .then and .catch methods, or you can use ES7-style await syntax via BabelJS stage 0 support, or something similar. A global Promise implementation is required, and must be set globally, no searches will be done.

Install

npm install --save azure-storage-simple

Module Interface - Storage

The module exposes a method that will return a Storage interface.

// Use Defaults
var storage = require('azure-storage-simple')(/*no arguments, uses defaults*/); //no await


// Pass Options - the example below actually uses the default values from the environment
var account = process.env.AZURE_STORAGE_ACCOUNT;
var key = process.env.AZURE_STORAGE_ACCESS_KEY;
var cs = process.env.AZURE_STORAGE_CONNECTION_STRING;

var storage = require('azure-storage-simple')(account || cs, key || null);

Underlying services

Because this module exposes only a simplified interface, the azure services interfaces are available.

NOTE: Will use underlying storage object's authentication credentials, no need to pass them in.

//you will be able to access the underlying azure-storage module
var azure = require('azure-storage-simple/azure-storage'); //returns underlying azure-storage module

//the methods below will return services using the credentials for the storage object
var tableService = storage.createTableService();
var queueService = storage.createQueueService();
var blobService = storage.createBlobService();

For details on how to use these services see:

Azure Queues

A dramatically simplified interface for using Azure Storage Queues.

var q = service.queue('myQueueName');

//child methods will call createQueueIfNotExist under the covers (once)

await queue.add(value);

var message = await q.one(); //gets a message

// message is wrapped with:
//    .value - parsed value  
//    other properties are buried in the prototype chain
var value2 = message.value; //unwrap the value

// got message/value - 30 seconds to resolve it

await q.done(message); //marke as complete / resolve / remove from queue

Azure Tables

A simplified interface will be used to access table storage. You won't need to wrap your objects, but you will need to specify the partitionKey and rowKey for read and write.

Note: write will do an insertOrMerge, so if you intend to remove field values, set them to null.

var tbl = storage.table('myTableName');

// child methods call createTableIfNotExist under the covers (once)

var value = {
  'someString': 'value',
  'someNumber': 1234,
  'someDate': new Date(),
  'someObject': {}, //will be JSON.stringified
  'someArray': [], //will be JSON.stringified
  'falseVal': false,
  'trueVal': true
};

await tbl.write('partitionKey','rowKey',value);

var record = await tbl.read('partitionKey','rowKey');

// record is wrapped with parsed values
//   original values are buried in the prototype chain
var value2 = result.value; // should deep equal value

var records = tbl.query() //records starts off as the query object/wrapper
    // .select('someString','someNumber') // fields to return (optional)
	.where('PartitionKey eq ?', 'partitionKey') // where clause (req)
    // .top(5) //limit results, must be under 1000
	; 

//there is a next method on query, and records that have more
while (records.next) {
  // get the next set of results 
  // if there are more results, will have a .next() function
  records = await records.next();

  records
    .forEach((record /*wrapped*/)=>{
      //do something with unwrapped value
      //can access original response with record.__proto__
    });
}
  

Blob Storage

TODO

For now use storage.createBlobService()

Keywords

FAQs

Package last updated on 06 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc