sqlcon

package
v0.0.626 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 15 Imported by: 78

Documentation

Overview

Package sqlcon provides helpers for dealing with SQL connectivity.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUniqueViolation is returned when^a SQL INSERT / UPDATE command returns a conflict.
	ErrUniqueViolation = &herodot.DefaultError{
		CodeField:     http.StatusConflict,
		GRPCCodeField: codes.AlreadyExists,
		StatusField:   http.StatusText(http.StatusConflict),
		ErrorField:    "Unable to insert or update resource because a resource with that value exists already",
	}
	// ErrNoRows is returned when a SQL SELECT statement returns no rows.
	ErrNoRows = &herodot.DefaultError{
		CodeField:     http.StatusNotFound,
		GRPCCodeField: codes.NotFound,
		StatusField:   http.StatusText(http.StatusNotFound),
		ErrorField:    "Unable to locate the resource",
	}
	// ErrConcurrentUpdate is returned when the database is unable to serialize access due to a concurrent update.
	ErrConcurrentUpdate = &herodot.DefaultError{
		CodeField:     http.StatusBadRequest,
		GRPCCodeField: codes.Aborted,
		StatusField:   http.StatusText(http.StatusBadRequest),
		ErrorField:    "Unable to serialize access due to a concurrent update in another session",
	}
	ErrNoSuchTable = &herodot.DefaultError{
		CodeField:     http.StatusInternalServerError,
		GRPCCodeField: codes.Internal,
		StatusField:   http.StatusText(http.StatusInternalServerError),
		ErrorField:    "Unable to locate the table",
	}
)

Functions

func FinalizeDSN added in v0.0.116

func FinalizeDSN(l *logrusx.Logger, dsn string) string

FinalizeDSN will return a finalized DSN URI.

func GetDriverName added in v0.0.73

func GetDriverName(dsn string) string

GetDriverName returns the driver name of a given DSN.

func HandleError

func HandleError(err error) error

HandleError returns the right sqlcon.Err* depending on the input error.

func HelpMessage

func HelpMessage() string

HelpMessage returns a string explaining how to set up SQL using environment variables.

func ParseConnectionOptions added in v0.0.84

func ParseConnectionOptions(l *logrusx.Logger, dsn string) (maxConns int, maxIdleConns int, maxConnLifetime, maxIdleConnTime time.Duration, cleanedDSN string)

ParseConnectionOptions parses values for max_conns, max_idle_conns, max_conn_lifetime from DSNs. It also returns the URI without those query parameters.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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