You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-3Lines changed: 32 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -22,26 +22,43 @@ To configure the internal instance of [AWS.DynamoDB](http://docs.aws.amazon.com/
22
22
you can follow one of the many methods described [here](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html) or
23
23
manually using this `config` instance.
24
24
25
-
`increment`
26
-
-----------
25
+
`increment( counterId, options )`
26
+
---------------------------------
27
27
28
28
This method increments the counter for the specified `counterId`.
29
29
It returns an AWS-SDK [request](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Request.html)
30
30
instance with a jQuery style promise interface applied to it.
31
31
See the [jQuery documentation](http://api.jquery.com/category/deferred-object/) for details on how the promises work.
32
32
[underscore.deferred](https://github.com/wookiehangover/underscore.deferred) is used to add the Promise interface to the returned request object.
33
33
Additionally, success, error, and complete callback can be provided in the second argument.
34
-
The increment method takes the following arguments:
34
+
The `increment` method takes the following arguments:
35
35
36
36
*`counterId`: The unique name/identifier of the counter.
37
37
*`options` (optional): An options object to overwrite some of the default behaviour of the increment operation. All attributes in this object are optional.
38
+
* `options.tableName`: The name of the DynamoDB table that stores the counters. If not specified, it uses "AtomicCounters" by default.
38
39
* `options.keyAttribute`: The name of the attribute that stores the counter name/identifier. If not specified, it uses "id" by default.
39
40
* `options.countAttribute`: The name of the attribute that stores the last value generated for the specified `counterId`. If not specified, it uses "lastValue" by default.
41
+
* `options.increment`: Specifies by how much the counter should be incremented. If not specified, it uses 1 by default.
40
42
* `options.success`: Success callback function. It receives a single argument: the value (integer) generated by this increment operation for the specified `counterId`.
41
43
* `options.error`: Error callback function. If the DynamoDB UpdateItem request fails, the error callback is executed. It receives a single argument: the error object returned from AWS-SDK.
42
44
* `options.complete`: Complete callback function. This callback is executed when the increment operation is completed, whether or not it was successful. It receives a single argument: an integer, if the operation was successful, or an error object if it failed.
43
45
* `options.context`: The context object to use in all callbacks. If specified, the value of `this` within all callbacks will be `options.context`.
44
46
47
+
`getLastValue( counterId, options )`
48
+
------------------------------------
49
+
50
+
This method retrieves, from DynamoDB, the last generated value for the specified `counterId`. If the counter doesn't exist,
51
+
the success callback would receive 0 as the first argument.
52
+
It returns an AWS-SDK [request](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Request.html)
53
+
instance with a jQuery style promise interface applied to it.
54
+
See the [jQuery documentation](http://api.jquery.com/category/deferred-object/) for details on how the promises work.
55
+
[underscore.deferred](https://github.com/wookiehangover/underscore.deferred) is used to add the Promise interface to the returned request object.
56
+
Additionally, success, error, and complete callback can be provided in the second argument.
57
+
The `getLastValue` method takes the following arguments:
58
+
59
+
*`counterId`: The unique name/identifier of the counter.
60
+
*`options` (optional): The same options supported by the `increment` method are also supported by this method.
61
+
45
62
46
63
Basic Usage
47
64
-----------
@@ -64,4 +81,16 @@ The following few lines of code demonstrate basic usage of this library. Additio
64
81
// An error occurred
65
82
}).always(function (valueOrError) {
66
83
// Executed whether or not the increment operation was successful
84
+
});
85
+
86
+
/**
87
+
* Retrieve the last value generated for the "Clients" counter.
0 commit comments