diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-15 10:26:53 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-15 10:26:53 -0700 |
commit | a92b9c4cc9a9cee920dc4a1591716a5bda550301 (patch) | |
tree | c1747819b8499d03e4a5348b1f42d1c22b73e3f2 /rwtransaction.go | |
parent | Merge pull request #30 from benbjohnson/examples (diff) | |
parent | Add bucket sequence. (diff) | |
download | dedo-a92b9c4cc9a9cee920dc4a1591716a5bda550301.tar.gz dedo-a92b9c4cc9a9cee920dc4a1591716a5bda550301.tar.xz |
Merge pull request #31 from benbjohnson/sequence
Sequence
Diffstat (limited to 'rwtransaction.go')
-rw-r--r-- | rwtransaction.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/rwtransaction.go b/rwtransaction.go index 92d05a8..568960a 100644 --- a/rwtransaction.go +++ b/rwtransaction.go @@ -66,6 +66,20 @@ func (t *RWTransaction) DeleteBucket(name string) error { return nil } +// NextSequence returns an autoincrementing integer for the bucket. +func (t *RWTransaction) NextSequence(name string) (int, error) { + // Check if bucket already exists. + b := t.Bucket(name) + if b == nil { + return 0, BucketNotFoundError + } + + // Increment and return the sequence. + b.bucket.sequence++ + + return int(b.bucket.sequence), nil +} + // Put sets the value for a key inside of the named bucket. // If the key exist then its previous value will be overwritten. // Returns an error if the bucket is not found, if the key is blank, if the key is too large, or if the value is too large. |