Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Transactional Blocks #32

Merged
merged 1 commit into from
Feb 15, 2014
Merged

Transactional Blocks #32

merged 1 commit into from
Feb 15, 2014

Conversation

benbjohnson
Copy link
Member

Overview

This pull request includes support for Transactional Blocks. This allows users to execute a transaction within a function without having to worry about deferring the commit/rollback. Any error returned from the function or that returns from the transaction's Commit() is returned from the block.

The transactional block is executed using the following method:

func (db *DB) Do(fn func(*RWTransaction) error) error

A read-only transactional block may be added in the future. Not sure what to call it yet.

Example

func myFunc() error {
    ...

    // Execute several commands within a write transaction.
    err := db.Do(func(t *RWTransaction) error {
        if err := t.CreateBucket("widgets"); err != nil {
            return err
        }
        if err := t.Put("widgets", []byte("foo"), []byte("bar")); err != nil {
            return err
        }
        return nil
    })

    if err != nil {
        return err
    }

    ...
}

/cc @snormore

benbjohnson added a commit that referenced this pull request Feb 15, 2014
@benbjohnson benbjohnson merged commit 2b5e440 into boltdb:master Feb 15, 2014
@benbjohnson benbjohnson deleted the blocks branch February 15, 2014 22:01
@benbjohnson benbjohnson mentioned this pull request Feb 15, 2014
tylertreat pushed a commit to tylertreat/bolt that referenced this pull request Aug 24, 2017
README: explain purpose of bbolt fork
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant