txdbg

package
v0.0.0-...-b425644 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

txdbg

Debug SQL transactions inside tests

Usage

See https://godoc.org/github.com/dynport/dgtk/txdbg

Documentation

Overview

Debug SQL transactions inside tests

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadQuery

func LoadQuery(tx *sql.Tx, q string, args ...interface{}) (values []value, names []string, err error)

func Open

func Open(tx *sql.Tx) error
Example
// dummy database setup
db, err := sql.Open("postgres", "postgres://127.0.0.1/template1")
if err != nil {
	log.Fatal(err)
}
tx, err := db.Begin()
if err != nil {
	log.Fatal(err)
}
defer tx.Rollback()

Open(tx)
Output:

func OpenWithQuery

func OpenWithQuery(tx *sql.Tx, query string) error
Example
// dummy database setup
db, err := sql.Open("postgres", "postgres://127.0.0.1/template1")
if err != nil {
	log.Fatal(err)
}
tx, err := db.Begin()
if err != nil {
	log.Fatal(err)
}
defer tx.Rollback()

OpenWithQuery(tx, "SELECT count(1) FROM users") // starts with this query as "default"
Output:

func StartServer

func StartServer(tx *sql.Tx, query string) (waitForClose chan struct{}, address string)

StartServer starts a new http server for the given transaction

The server shuts down when a) the user presses the "quit" button or b) on the first db error (as we can not recover from that error inside the transaction)

Example
// dummy database setup
db, err := sql.Open("postgres", "postgres://127.0.0.1/template1")
if err != nil {
	log.Fatal(err)
}
tx, err := db.Begin()
if err != nil {
	log.Fatal(err)
}
defer tx.Rollback()

waitForClose, addr := StartServer(tx, "")
openURL(addr)
<-waitForClose // blocks until the QUIT button is pressed or first error occurs on tx
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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