postgres

package
v0.1.0-alpha9 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package postgres provides functions for interacting with postgres-compatible databases and includes migration scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, url string) (*sql.DB, error)

Open a connection to the database instance described in the URL, performing migrations on success.

func WithinReadOnlyTransaction

func WithinReadOnlyTransaction(ctx context.Context, db *sql.DB, fn TransactionFunc) error

WithinReadOnlyTransaction invokes the TransactionFunc, providing it an sql.Tx transaction to perform SQL operations against. If the TransactionFunc returns a non-nil error, the transaction is rolled back. Otherwise, it is committed. If the transaction is intended to include write operations, use WithinTransaction.

func WithinTransaction

func WithinTransaction(ctx context.Context, db *sql.DB, fn TransactionFunc) error

WithinTransaction invokes the TransactionFunc, providing it an sql.Tx transaction to perform SQL operations against. If the TransactionFunc returns a non-nil error, the transaction is rolled back. Otherwise, it is committed. If the transaction is intended to be read-only, use WithinReadOnlyTransaction.

Types

type TransactionFunc

type TransactionFunc func(ctx context.Context, tx *sql.Tx) error

The TransactionFunc is a function invoked when calling WithinTransaction.

Jump to

Keyboard shortcuts

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