buffalo-pop

command module
v1.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: MIT Imports: 1 Imported by: 0

README

GoDoc Go Report Card

github.com/gobuffalo/buffalo-pop

This is the home for all things that combine Buffalo and Pop.

Installation

$ go get -u -v github.com/gobuffalo/buffalo-pop

Or with SQLite 3 support:

$ go get -tags sqlite -u -v github.com/gobuffalo/buffalo-pop

Transaction Middleware

The popmw.Transaction will wrap each request inside of a new database transaction and automatically commit, or rollback, based on whether or not an error was returned from an upstream buffalo.Handler or buffalo.MiddlewareFunc.

Usage

First you need to add the middleware to your application giving it access to your *pop.Connection, typically found at models.DB.

import "github.com/gobuffalo/buffalo-pop/pop/popmw"

func App() *buffalo.App {
  // ...
  app.Use(popmw.Transaction(models.DB))
  // ...
}

Once added to the middleware stack for your application you can then use this transaction in upstream middleware or handlers.

func MyHandler(c buffalo.Context) error {
  // Get the DB connection from the context
  tx, ok := c.Value("tx").(*pop.Connection)
  if !ok {
    return errors.New("no transaction found")
  }
}

WARNING: DO NOT OPEN MULTIPLE TRANSACTIONS WITHIN EACH OTHER - doing so will cause many, many, many problems.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
genny
newapp
You can use the "packr clean" command to clean up this, and any other packr generated files.
You can use the "packr clean" command to clean up this, and any other packr generated files.
internal
You can use the "packr2 clean" command to clean up this, and any other packr generated files.
You can use the "packr2 clean" command to clean up this, and any other packr generated files.
pop

Jump to

Keyboard shortcuts

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