About
A node.js module allows you easily maintain simple data structure on Amazon S3 service (Use aws2js for S3 access):
- 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
- 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=; //--- load s3db modulevar db='your aws_access key id''your aws secrect access key';
KeyList
var kl=db; //--Open a keylist //--- fetch keys on listkl; //--- delete all keys on list kl;
ObjectDB
var odb=db; //--Open a ObjectDB //--- store an object / hash under key 'mykey'var obj=a:1b:2; odb;
Promise
Interface Support
Along with callback style API, Promise
stlyle asynchronous programming pattern is also support (Based on JavaScript Library Q).
kl //---get full key list //-- del all key returned by kl.get() //-- fetch key list again;
//---Load underscore library for function bindvar _=; //--- store an object / hash under key 'mykey'var obj=a:1b:2; odb;
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