<commit_before>dynamo
======

[![Build Status](https://secure.travis-ci.org/jed/dynamo.png)][travis]

This is a [node.js][node] binding for the [DynamoDB][dynamo] service provided by [Amazon Web Services][aws]. It currently supports the entire DynamoDB API in an unsugared (read: Amazon-flavored (read: ugly)) format. I'll be developing a more comfortable API over the coming week to make DynamoDB operations more node-ish, so stay tuned.

Goal
----

Abstract DynamoDB's implementation (request signing, session tokens, pagination), but not its tradeoffs/philosophy.

Example
-------

```javascript
var dynamo = require("dynamo")
  , db = dynamo.createClient()

// the current API is unsugared, mirrors the DynamoDB API...
db.listTables({}, function(err, data) {
  if (err) return console.warn(err)

  var name, names = data.TableNames

  while (name = names.shift()) {
  	console.log("table: " + name)
  }
})

// but an additional, more node-friendly API is in the works.
// this is a theoretical example of what i have in mind:
db.tables.forEach(function(err, name, next) {
  if (err) return console.warn(err)

  console.log("table: " + name)

  if (next) next() // use connect-style continuations for batching
})
```

Callbacks
---------

- All callbacks are optional, and if omitted will use `console.warn` for errors and `console.log` otherwise. This makes it easier to inspect your database in a REPL, for example.

- The signature for all callbacks is `(err, data, next)`. This is the same as the standard for most node.js programs, but with an additional `next` parameter: a continuation function such as those used in [Connect][connect] routes and other middleware. This function takes no arguments, and is passed only in the following cases:

  - The call was unsuccessful and can be retried. This is the case when DynamoDB returns a 5xx status code, indicating that the problem exists with the service, not the request. Calling `next()` will execute the same request again, so it's best used with `setTimeout`.
  - The call was successful and has subsequent results, such as for pagination or when a response hits the 1MB limit. Calling `next()` will fetch the next batch of results and call back again.

This allows you to write code like this, which logs a list of all tables:

```javascript<commit_msg>update example<commit_after>dynamo
======

[![Build Status](https://secure.travis-ci.org/jed/dynamo.png)][travis]

This is a [node.js][node] binding for the [DynamoDB][dynamo] service provided by [Amazon Web Services][aws]. It currently supports the entire DynamoDB API in an unsugared (read: Amazon-flavored (read: ugly)) format. I'll be developing a more comfortable API over the coming week to make DynamoDB operations more node-ish, so stay tuned.

Goal
----

Abstract DynamoDB's implementation (request signing, session tokens, pagination), but not its tradeoffs/philosophy.

Example
-------

```javascript
var dynamo = require("dynamo")
  , db = dynamo.createClient()
  , tables = []

db.tables.forEach(function(err, name, next) {
  if (err) return console.warn(err)

  console.log("found a table: " + table.name)

  if (next) next() // use connect-style continuations for batching
})
```

Callbacks
---------

- All callbacks are optional, and if omitted will use `console.warn` for errors and `console.log` otherwise. This makes it easier to inspect your database in a REPL, for example.

- The signature for all callbacks is `(err, data, next)`. This is the same as the standard for most node.js programs, but with an additional `next` parameter: a continuation function such as those used in [Connect][connect] routes and other middleware. This function takes no arguments, and is passed only in the following cases:

  - The call was unsuccessful and can be retried. This is the case when DynamoDB returns a 5xx status code, indicating that the problem exists with the service, not the request. Calling `next()` will execute the same request again, so it's best used with `setTimeout`.
  - The call was successful and has subsequent results, such as for pagination or when a response hits the 1MB limit. Calling `next()` will fetch the next batch of results and call back again.

This allows you to write code like this, which logs a list of all tables:

```javascript
{'fraction_non_alphanumeric': 0.0980209545983702, 'fraction_numerical': 0.0009313154831199069, 'mean_word_length': 4.175903614457831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1578632', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1172, 'n_words': 575}