pgutil

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package pgutil contains utilities for postgres

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckApplicationName

func CheckApplicationName(s string) (r string)

CheckApplicationName ensures that the Connection String contains an application name

func ConnstrWithSchema

func ConnstrWithSchema(connstr, schema string) string

ConnstrWithSchema adds schema to a connection string

func CreateRandomTestingSchemaName

func CreateRandomTestingSchemaName(n int) string

CreateRandomTestingSchemaName creates a random schema name string.

func CreateSchema

func CreateSchema(db Execer, schema string) (err error)

CreateSchema creates a schema if it doesn't exist.

func DropSchema

func DropSchema(db Execer, schema string) error

DropSchema drops the named schema

func IsConstraintError

func IsConstraintError(err error) bool

IsConstraintError checks if given error is about constraint violation

func LoadSchemaFromSQL

func LoadSchemaFromSQL(connstr, script string) (_ *dbschema.Schema, err error)

LoadSchemaFromSQL inserts script into connstr and loads schema.

func LoadSnapshotFromSQL

func LoadSnapshotFromSQL(connstr, script string) (_ *dbschema.Snapshot, err error)

LoadSnapshotFromSQL inserts script into connstr and loads schema.

func ParseSchemaFromConnstr

func ParseSchemaFromConnstr(connstr string) (string, error)

ParseSchemaFromConnstr returns the name of the schema parsed from the connection string if one is provided

func QueryData

func QueryData(db dbschema.Queryer, schema *dbschema.Schema) (*dbschema.Data, error)

QueryData loads all data from tables

func QuerySchema

func QuerySchema(db dbschema.Queryer) (*dbschema.Schema, error)

QuerySchema loads the schema from postgres database.

func QuerySnapshot

func QuerySnapshot(db dbschema.Queryer) (*dbschema.Snapshot, error)

QuerySnapshot loads snapshot from database

func QuoteSchema

func QuoteSchema(schema string) string

QuoteSchema quotes schema name for

Types

type DB

type DB struct {
	*sql.DB
	Schema string
}

DB is postgres database with schema

func Open

func Open(connstr string, schemaPrefix string) (*DB, error)

Open opens a postgres database with a schema

func (*DB) Close

func (db *DB) Close() error

Close closes the database and deletes the schema.

type Execer

type Execer interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Execer is for executing sql

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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