dbutil

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 9 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseName

func DatabaseName(u *url.URL) string

DatabaseName returns the database name from a URL

func MustClose

func MustClose(c io.Closer)

MustClose ensures a stream is closed

func MustParseURL

func MustParseURL(s string) *url.URL

MustParseURL parses a URL from string, and panics if it fails. It is used during testing and in cases where we are parsing a generated URL.

func MustUnescapePath added in v1.14.0

func MustUnescapePath(s string) string

MustUnescapePath unescapes a URL path, and panics if it fails. It is used during in cases where we are parsing a generated path.

func QueryColumn

func QueryColumn(db Transaction, query string, args ...interface{}) ([]string, error)

QueryColumn runs a SQL statement and returns a slice of strings it is assumed that the statement returns only one column e.g. schema_migrations table

func QueryValue

func QueryValue(db Transaction, query string, args ...interface{}) (string, error)

QueryValue runs a SQL statement and returns a single string it is assumed that the statement returns only one row and one column sql NULL is returned as empty string

func RunCommand

func RunCommand(name string, args ...string) ([]byte, error)

RunCommand runs a command and returns the stdout if successful

func TrimLeadingSQLComments

func TrimLeadingSQLComments(data []byte) ([]byte, error)

TrimLeadingSQLComments removes sql comments and blank lines from the beginning of text generally when performing sql dumps these contain host-specific information such as client/server version numbers

Types

type Transaction

type Transaction interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Transaction can represent a database or open transaction

Jump to

Keyboard shortcuts

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