postgres

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DBMigrationsConcurrentInitErrPrefix = "ERROR #23505" // safe to ignore, error when gopg_migrations already exists
	DBStatementCancelledErrPrefix       = "ERROR #57014"
)

Variables

This section is empty.

Functions

func DBMigrationsAlreadyInit

func DBMigrationsAlreadyInit(err error) bool

func DBStatementCancelledByUser

func DBStatementCancelledByUser(err error) bool

func WithContextTimeout

func WithContextTimeout(ctx context.Context, f func(ctx context.Context))

WithContextTimeout executes statements with a default timeout

func WithContextTimeoutValue

func WithContextTimeoutValue(ctx context.Context, timeout time.Duration, f func(ctx context.Context))

WithContextTimeoutValue executes an inner routine while passing a ctx that supports custom timeout and query cancellation to the postgres server.

Types

type TGPGDB

type TGPGDB struct {
	*pg.DB
}

func CreateTGPGDB

func CreateTGPGDB(url string) *TGPGDB

func CreateTGPGDBWithOptions

func CreateTGPGDBWithOptions(dbOpts *TGPGDBOptions) *TGPGDB

func NewTGPGDB

func NewTGPGDB(db *pg.DB) *TGPGDB

func (*TGPGDB) ExecContext

func (db *TGPGDB) ExecContext(ctx context.Context, query interface{}, params ...interface{}) (pg.Result, error)

func (*TGPGDB) Migrate

func (db *TGPGDB) Migrate() error

Migrate check and migrate to lastest db version.

func (*TGPGDB) ModelContext

func (db *TGPGDB) ModelContext(ctx context.Context, models ...interface{}) *orm.Query

func (*TGPGDB) Ping

func (db *TGPGDB) Ping() error

Ping simulates a "blank query" behavior similar to lib/pq's to check if the db connection is alive.

func (*TGPGDB) RunInTransactionContext

func (db *TGPGDB) RunInTransactionContext(ctx context.Context, txFunc func(context.Context, *TGPGDB) error) error

RunInTransactionContext wraps around underlying go-pg's rollback-supported transaction execution with our custom context so it can be easily passed down.

func (*TGPGDB) WithTimeout

func (db *TGPGDB) WithTimeout(timeout time.Duration) *TGPGDB

WithTimeout needs to create a new db instance in order to pass into the next chain of commands.

type TGPGDBOptions

type TGPGDBOptions struct {
	Url string

	DisableBeforeQueryLog bool
	DisableAfterQueryLog  bool
}

Jump to

Keyboard shortcuts

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