db

package
v0.0.0-...-0490640 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transaction

func Transaction(b *gorp.DbMap, f TransactionFunc) error

Transaction wraps your calls in a gorp.Transaction. If the call should fail with an error it will perform a rollback. Otherwise the transaction will be committed.

Usage: ``` import (

dblib "github.com/chef/automate/lib/db"
"github.com/go-gorp/gorp"
_ "github.com/lib/pq"

)

type postgres struct {
  *gorp.DbMap
}
func (db *postgres) InsertData(data) error {
  return dblib.Transaction(db.DbMap, func(tx *gorp.Transaction) error {

    // Add here all your transactions (check all errors)
    tx.Insert(deploy)
    tx.Update(deploy)
    tx.Insert(deploy)
    tx.Delete(deploy)

    return nil
  })
}

```

Types

type TransactionFunc

type TransactionFunc func(*gorp.Transaction) error

TransactionFunc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL