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

s3db

v0.0.3

Published

A node.js module allows you easily maintain simple data structure on Amazon S3 service

Downloads

5

Readme

About

A node.js module allows you easily maintain simple data structure on Amazon S3 service (Use aws2js for S3 access):

  1. KeyList

Maintains a list of string keys. You can:

  • Add a key / keys into the list
  • Fetch a list of keys on list
  • Delete a key / keys / all keys from list
  • Tell whether a key is / keys are on list
  1. ObjectDB

Maintains a key value store. You can:

  • Store a value / object under a string key
  • Get the value / object of a string key
  • Delete a key
  • Tell whether a key exists

Installation

Either manually clone this repository into your node_modules directory, or the recommended method:

npm install aws2js

Getting Started

Initailization

var s3db=require('s3db'); //--- load s3db module
var db=new s3db('your aws_access key id','your aws secrect access key');

KeyList

var kl=db.open('KeyList','s3://mybucket.com/path_to_my_key_list/my_key_list'); //--Open a keylist

//--- fetch keys on list
kl.get(function(keys){ //--- callback will be called when operation completed without error.
	console.log(keys); //-- first 100 keys
	if(kl.is_truncated==true){ //--- if not all keys return in one request (default fetch only first 1000 keys), then continue to fetch the rest keys on the list.
		kl.get(function(keys){
			console.log(keys); //-- next 1000 keys
		},function(error){
			console.log(error);
		});
	}
},function(error){ //--- callback will be called when error occurs
	console.log(error);
});

//--- delete all keys on list

kl.del_all(function(){  //--- callback will be called when operation completed without error.
	console.log('Operation completed'); //-- next 1000 keys
},function(error){
	console.log(error);
});

ObjectDB

var odb=db.open('ObjectDB','s3://mybucket.com/path_to_obejct_db/my_object_db'); //--Open a ObjectDB

//--- store an object / hash under key 'mykey'
var obj={a:1,b:2};

odb.put('mykey',obj,function(){  //--- callback will be called when operation completed without error. 
	console.log('Operation completed');
	
	//-- get value under key 'mykey'
	odb.get('mykey',function(obj){  //--- callback will be called when operation completed without error. 
		console.log(obj); //--- will print out: {a:1,b:2}
	},function(e){	//--- callback will be called when error occurs
		console.log(e);
	});
	
},function(e){	//--- callback will be called when error occurs
	console.log(e);
});

Promise Interface Support

Along with callback style API, Promise stlyle asynchronous programming pattern is also support (Based on JavaScript Library Q).

//---Load underscore library for function bind
var _=require('underscore');

//--- store an object / hash under key 'mykey'
var obj={a:1,b:2};

odb.put('mykey',obj).then(_.bind(odb.get,
								 odb, //---make sure get method is bound to odb object when is called
								 'mykey' //--- paramter for get method
)).then(function(obj){
	console.log(obj); //--- will print out: {a:1,b:2}
}).fail(function(error){
	console.log(error); //--- print out error during the whole process
});

API Reference

s3db

Method init(aws_access_key_id,aws_secrect_access_key,endpoint_prefix)

endpoint_prefix: default to ''. Example: 's3-us-west-1' The endpoint list is available here.

Method open(module,uri)

module: availble values: 'KeyList', 'ObjectDB'

KeyList

Method get(ok_func,error_func,limit,marker)

ok_func: callback. Will be called if operation completed withour error. Optional if use Promise API. ok_func: callback. Will be called if error occurs. Optional if use Promise API. limit: Max. number of keys to fetch. Optional, default to 1000. A value larger than 1000 will be ignored. marker: Fetch the keys from the marker. For pagination purpose. Optional.

Method reset()

Reset internal marker so that get method will return result form the first key rather then where the result is truncated during last method get call.

Method put(key,ok_func,error_func)

key: Can be a string key or an array of keys that should be put on list

Method del(key,ok_func,error_func)

key: Can be a string key or an array of keys that should be deleted from list

Method del_all(ok_func,error_func)
Method on_list(key,yes_func,no_func,error_func)

key: Can be a string key or an array of keys yes_func: callback will be called if all keys are on list

ObjectDB

Method get(key,ok_func,error_func)

key: String. key of the value / object

Method put(key,obj,ok_func,error_func)

key: String. key of the value / object obj: Object. The object should be store under the key.

Method del(key,ok_func,error_func)

key: String. key of the value / object

Method is_set(key,yes_func,no_func,error_func)

key: String. key of the value / object yes_func: callback will be called if the key exists