db

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBService

type DBService struct {

	// Set to true to enable additional debugging
	Debug bool
	// contains filtered or unexported fields
}

DBService database/sql bound with github.com/lib/pq as a Kernel Service

func (*DBService) Begin

func (s *DBService) Begin() (*sql.Tx, error)

func (*DBService) Exec

func (s *DBService) Exec(query string, args ...interface{}) (sql.Result, error)

func (*DBService) GetDB

func (s *DBService) GetDB() *sql.DB

GetDB returns the underlying sql.DB

func (*DBService) Init

func (s *DBService) Init(_ *kernel.Kernel) error

func (*DBService) MaxIdle

func (s *DBService) MaxIdle(maxIdle int) *DBService

func (*DBService) MaxLifetime

func (s *DBService) MaxLifetime(maxLifetime time.Duration) *DBService

func (*DBService) MaxOpen

func (s *DBService) MaxOpen(maxOpen int) *DBService

func (*DBService) Prepare

func (s *DBService) Prepare(sql string) (*sql.Stmt, error)

func (*DBService) Query

func (s *DBService) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*DBService) QueryRow

func (s *DBService) QueryRow(query string, args ...interface{}) *sql.Row

func (*DBService) SetDB

func (s *DBService) SetDB(postgresURI string) *DBService

func (*DBService) Start

func (s *DBService) Start() error

func (*DBService) Stop

func (s *DBService) Stop()

func (*DBService) Update

func (s *DBService) Update(f TxHandler) error

Update calls a TxHandler within a transaction. If the handler returns an error then the transaction is rolled back. If the handler returns nil then the transaction is committed

type OnCommit

type OnCommit func() error

type Tx

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

Tx wrapper around sql.Tx with additional functionality

func (*Tx) BeforeCommit

func (tx *Tx) BeforeCommit(f TxHandler)

BeforeCommit will call the supplied function when the transaction is about to commit but before the actual commit.

func (*Tx) DeleteFrom

func (tx *Tx) DeleteFrom(table string) (sql.Result, error)

DeleteFrom is a wrapper around deleting from a table

func (*Tx) Exec

func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)

Execute a query within this transaction

func (*Tx) ExecBeforeCommit

func (tx *Tx) ExecBeforeCommit(query string, args ...interface{})

ExecBeforeCommit will execute a query once this transaction commits BUT BEFORE the actual transaction commits.

Unlike ExecOnCommit this runs within this transaction, it's just queued so that it will be run before the transaction is finally Committed. Note this will not be within a transaction, see UpdateOnCommit for that

func (*Tx) ExecOnCommit

func (tx *Tx) ExecOnCommit(query string, args ...interface{})

ExecOnCommit will execute a query once this transaction commits. Note this will not be within a transaction, see UpdateOnCommit for that

func (*Tx) OnCommit

func (tx *Tx) OnCommit(f OnCommit)

OnCommit will call the supplied function once this transaction commits

func (*Tx) OnCommitCluster

func (tx *Tx) OnCommitCluster(table, column string)

func (*Tx) OnCommitVacuum

func (tx *Tx) OnCommitVacuum(table string)

func (*Tx) OnCommitVacuumFull

func (tx *Tx) OnCommitVacuumFull(table string)

func (*Tx) Prepare

func (tx *Tx) Prepare(query string) (*sql.Stmt, error)

Prepare a statement that will run within this transaction

func (*Tx) Query

func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)

Perform a Query within this transaction

func (*Tx) QueryRow

func (tx *Tx) QueryRow(query string, args ...interface{}) *sql.Row

func (*Tx) SetEncoding

func (tx *Tx) SetEncoding(enc string) error

func (*Tx) SetEncodingUTF8

func (tx *Tx) SetEncodingUTF8() error

Set's the connection encoding to "UTF8" - the default in the database. Use if SetEncodingWIN1252 or SetEncoding has been used.

func (*Tx) SetEncodingWIN1252

func (tx *Tx) SetEncodingWIN1252() error

Set's the connection encoding to "WIN1252" - use with csv style imports which have latin characters rather than UTF8

func (*Tx) UpdateOnCommit

func (tx *Tx) UpdateOnCommit(f TxHandler)

UpdateOnCommit will start a new update/transaction once this transaction commits

type TxHandler

type TxHandler func(*Tx) error

Jump to

Keyboard shortcuts

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