glsql

package
v15.10.8 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package glsql (Gitaly SQL) is a helper package to work with plain SQL queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN

func DSN(db config.DB, direct bool) string

DSN compiles configuration into data source name with lib/pq specifics.

func IsQueryCancelled

func IsQueryCancelled(err error) bool

IsQueryCancelled returns true if an error is a query cancellation.

func IsUniqueViolation

func IsUniqueViolation(err error, constraint string) bool

IsUniqueViolation returns true if an error is a unique violation.

func Migrate

func Migrate(db *sql.DB, ignoreUnknown bool) (int, error)

Migrate will apply all pending SQL migrations.

func MigrateSome

func MigrateSome(m *migrate.Migration, db *sql.DB, ignoreUnknown bool) (int, error)

MigrateSome will apply migration m and all unapplied migrations with earlier ids. To ensure a single migration is executed, run sql-migrate.PlanMigration and call MigrateSome for each migration returned.

func OpenDB

func OpenDB(ctx context.Context, conf config.DB) (*sql.DB, error)

OpenDB returns connection pool to the database.

func ScanAll

func ScanAll(rows *sql.Rows, in DestProvider) (err error)

ScanAll reads all data from 'rows' into holders provided by 'in'.

Types

type DestProvider

type DestProvider interface {
	// To returns list of pointers.
	// It is not an idempotent operation and each call will return a new list.
	To() []interface{}
}

DestProvider returns list of pointers that will be used to scan values into.

type ListenHandler

type ListenHandler interface {
	// Notification would be triggered once a new notification received.
	Notification(Notification)
	// Disconnect would be triggered once a connection to remote service is lost.
	// Passed in error will never be nil and will contain cause of the disconnection.
	Disconnect(error)
	// Connected would be triggered once a connection to remote service is established.
	Connected()
}

ListenHandler contains a set of methods that would be called on corresponding notifications received.

type Notification

type Notification struct {
	// Channel is a name of the receiving channel.
	Channel string
	// Payload is a payload of the notification.
	Payload string
}

Notification represent a notification from the database.

type Querier

type Querier interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

Querier is an abstraction on *sql.DB and *sql.Tx that allows to use their methods without awareness about actual type.

type StringArray

type StringArray struct {
	pgtype.TextArray
}

StringArray is a wrapper that provides a helper methods.

func (StringArray) Slice

func (sa StringArray) Slice() []string

Slice converts StringArray into a slice of strings. The array element considered to be a valid string if it is not a null.

type StringProvider

type StringProvider []*string

StringProvider allows ScanAll to read all rows and return the result as a slice.

func (*StringProvider) To

func (p *StringProvider) To() []interface{}

To returns a list of pointers that will be used as a destination for scan operation.

func (*StringProvider) Values

func (p *StringProvider) Values() []string

Values returns list of values read from *sql.Rows

type Uint64Provider

type Uint64Provider []*uint64

Uint64Provider allows to use it with ScanAll function to read all rows into it and return result as a slice.

func (*Uint64Provider) To

func (p *Uint64Provider) To() []interface{}

To returns a list of pointers that will be used as a destination for scan operation.

func (*Uint64Provider) Values

func (p *Uint64Provider) Values() []uint64

Values returns list of values read from *sql.Rows

Jump to

Keyboard shortcuts

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