pg

package
v0.0.0-...-5eee607 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUniqueSpecifier

func AddUniqueSpecifier(cols []*schema.Column, colname string) error

AddUniqueSpecifier adds unique to the type of a column referenced by a unique index.

Types

type Binder

type Binder int

Binder tracks a postgres query bind variable.

func NewBinder

func NewBinder() *Binder

NewBinder creates a bind variable generator initialized to 1.

func (*Binder) Next

func (p *Binder) Next() string

Next gets the bind variable string "$1", "$2" etc. for the current bind variable, and increments the binder.

func (*Binder) NotFirst

func (p *Binder) NotFirst() bool

NotFirst returns true if this is not the first bind variable.

type ConnSpec

type ConnSpec struct {
	User, Password string
	Database       string
	Host           string
	Port           int
	SSLMode        string
}

ConnSpec is a PostgreSQL connection spec.

func (ConnSpec) ConnectionString

func (c ConnSpec) ConnectionString() string

ConnectionString constructs a connection string suitable for use in sql.Open

func (ConnSpec) DBHost

func (c ConnSpec) DBHost() string

DBHost returns the database host, defaulting to localhost if unspecified.

func (ConnSpec) GetSSLMode

func (c ConnSpec) GetSSLMode() string

GetSSLMode returns the SSL mode setting, defaulting to "disable".

func (ConnSpec) Open

func (c ConnSpec) Open() (DB, error)

Open opens the PostgreSQL database and returns the DB object.

func (ConnSpec) SpecForDB

func (c ConnSpec) SpecForDB(db string) ConnSpec

SpecForDB clones this connection spec, replacing Database with the given db.

type DB

type DB struct {
	*sql.DB
}

DB is a wrapper around database/sql.DB.

func OpenDBUser

func OpenDBUser(db, user, password string) (DB, error)

OpenDBUser opens the named PostgreSQL database with the given username and password.

func (DB) ActiveConnections

func (p DB) ActiveConnections(db string) ([]PID, error)

ActiveConnections gets the list of client PIDs connected to the DB.

func (DB) CreateDatabase

func (p DB) CreateDatabase(db string) error

CreateDatabase creates a database named db

func (DB) CreateExtension

func (p DB) CreateExtension(ext string) error

CreateExtension creates a pg extension named ext

func (DB) CreateUser

func (p DB) CreateUser(user, pass string) error

CreateUser creates a user with the given password pass.

func (DB) DatabaseExists

func (p DB) DatabaseExists(db string) (bool, error)

DatabaseExists checks if the database named db exists.

func (DB) ExtensionExists

func (p DB) ExtensionExists(ext string) (bool, error)

ExtensionExists checks if the postgres extension ext exists.

func (DB) GrantDBOwner

func (p DB) GrantDBOwner(db, user string) error

GrantDBOwner alters the database owner to user.

func (DB) IntrospectSchema

func (p DB) IntrospectSchema() (*schema.Schema, error)

IntrospectSchema discovers the database schema.

func (DB) IntrospectTable

func (p DB) IntrospectTable(table string) (*schema.Table, error)

IntrospectTable discovers the structure of table.

func (DB) IntrospectTableColumns

func (p DB) IntrospectTableColumns(table string) ([]*schema.Column, error)

IntrospectTableColumns introspects the columns in table from the db.

func (DB) IntrospectTableConstraints

func (p DB) IntrospectTableConstraints(table string, cols []*schema.Column) ([]schema.Constraint, error)

IntrospectTableConstraints discovers the constraints on table with cols.

func (DB) IntrospectTableForeignKeys

func (p DB) IntrospectTableForeignKeys(table string) ([]schema.Constraint, error)

IntrospectTableForeignKeys discovers the foreign keys for table.

func (DB) IntrospectTableIndexes

func (p DB) IntrospectTableIndexes(table string, cols []*schema.Column) ([]*schema.Index, error)

IntrospectTableIndexes discovers the indexes for table with cols.

func (DB) IntrospectTableNames

func (p DB) IntrospectTableNames() ([]string, error)

IntrospectTableNames discovers the names of tables in the db.

func (DB) IntrospectTablePrimaryKey

func (p DB) IntrospectTablePrimaryKey(table string) (schema.Constraint, error)

IntrospectTablePrimaryKey discovers the primary key for a table.

func (DB) IntrospectTableSchemas

func (p DB) IntrospectTableSchemas(tables []string) (schemas []*schema.Table, err error)

IntrospectTableSchemas discovers the structure of the named tables in the db.

func (DB) IntrospectTableUniqueConstraints

func (p DB) IntrospectTableUniqueConstraints(table string, cols []*schema.Column) error

IntrospectTableUniqueConstraints discovers the unique constraints for table with cols.

func (DB) RowExists

func (p DB) RowExists(query string, binds ...interface{}) (bool, error)

RowExists checks if query returns any rows

func (DB) TerminateConnection

func (p DB) TerminateConnection(pid PID) error

TerminateConnection kills the connection specified by pid.

func (DB) UserExists

func (p DB) UserExists(user string) (bool, error)

UserExists checks if the user exists.

type Error

type Error struct {
	Context string
	Cause   error
}

Error describes a PostgreSQL error.

func (Error) Error

func (p Error) Error() string

Error returns a string representation of the error object.

type PID

type PID int

A PID is the PID of a postgres client connection; this is not the same as a Unix process ID.

Jump to

Keyboard shortcuts

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