database

package
v0.0.0-...-f06e5ea Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package database wraps the database implmementation used for Pricewarp

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = pgx.ErrNoRows

Functions

This section is empty.

Types

type Batch

type Batch = pgx.Batch

type BatchResults

type BatchResults = pgx.BatchResults

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func Connect

func Connect() (*Conn, error)

Connect connects to the Postgres database with the project environment variables

func (*Conn) Begin

func (conn *Conn) Begin() (*Tx, error)

Begin starts a new transaction

func (*Conn) Close

func (conn *Conn) Close()

Close closes a database connection

func (*Conn) CopyFrom

func (conn *Conn) CopyFrom(tableName string, columNames []string, rows [][]any) (int64, error)

CopyFrom copies rows into a database.

func (*Conn) Exec

func (conn *Conn) Exec(sql string, arguments ...any) error

Exec executes a database query

func (*Conn) Query

func (conn *Conn) Query(sql string, arguments ...any) (Rows, error)

Query executes a database query

func (*Conn) QueryRow

func (conn *Conn) QueryRow(sql string, arguments ...any) Row

QueryRow executes a database query returning Row data

func (*Conn) SendBatch

func (conn *Conn) SendBatch(batch *Batch) BatchResults

SendBatch send a series of queries in a batch.

type Queryable

type Queryable interface {
	// Exec executes a database query
	Exec(sql string, arguments ...any) error
	// QueryRow executes a database query
	Query(sql string, arguments ...any) (Rows, error)
	// QueryRow executes a database query returning Row data
	QueryRow(sql string, arguments ...any) Row
	// SendBatch send a series of queries in a batch.
	SendBatch(batch *Batch) BatchResults
	// CopyFrom copies rows into a database.
	CopyFrom(tableName string, columNames []string, rows [][]interface{}) (int64, error)
}

Queryable defines an interface for either a connection or a transaction

type Row

type Row = pgx.Row

type Rows

type Rows = pgx.Rows

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit commits a transaction to the database

func (*Tx) CopyFrom

func (tx *Tx) CopyFrom(tableName string, columNames []string, rows [][]interface{}) (int64, error)

CopyFrom copies rows into a database.

func (*Tx) Exec

func (tx *Tx) Exec(sql string, arguments ...any) error

Exec executes a database query

func (*Tx) Query

func (tx *Tx) Query(sql string, arguments ...any) (Rows, error)

Query executes a database query

func (*Tx) QueryRow

func (tx *Tx) QueryRow(sql string, arguments ...any) Row

QueryRow executes a database query returning Row data

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback cancels a transaction in the database

func (*Tx) SendBatch

func (tx *Tx) SendBatch(batch *Batch) BatchResults

SendBatch send a series of queries in a batch.

Jump to

Keyboard shortcuts

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