From 63e8e474d7d26f60eb6f97f92f051a925958819f Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Sun, 16 Feb 2014 12:36:37 -0700 Subject: Add CreateBucketIfNotExists(). --- db.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'db.go') diff --git a/db.go b/db.go index ec049dd..a519f73 100644 --- a/db.go +++ b/db.go @@ -389,6 +389,14 @@ func (db *DB) CreateBucket(name string) error { }) } +// CreateBucketIfNotExists creates a new bucket with the given name if it doesn't already exist. +// This function can return an error if the name is blank, or the bucket name is too long. +func (db *DB) CreateBucketIfNotExists(name string) error { + return db.Do(func(t *RWTransaction) error { + return t.CreateBucketIfNotExists(name) + }) +} + // DeleteBucket removes a bucket from the database. // Returns an error if the bucket does not exist. func (db *DB) DeleteBucket(name string) error { -- cgit v1.2.3