db

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UniqueConstrain = 1555
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func NewSQLiteDB

func NewSQLiteDB(dbPath string) (*sql.DB, error)

NewSQLiteDB creates a new SQLite DB

func ReturnErrNotFound

func ReturnErrNotFound(err error) error

func RunMigrations

func RunMigrations(dbPath string, migrations []types.Migration) error

RunMigrations will execute pending migrations if needed to keep the database updated with the latest changes in either direction, up or down.

func SQLiteErr

func SQLiteErr(err error) (*sqlite.Error, bool)

func SlicePtrsToSlice

func SlicePtrsToSlice(slice interface{}) interface{}

SlicePtrsToSlice converts any []*Foo to []Foo

func SliceToSlicePtrs

func SliceToSlicePtrs(slice interface{}) interface{}

SliceToSlicePtrs converts any []Foo to []*Foo

Types

type AddressMeddler

type AddressMeddler struct{}

AddressMeddler encodes or decodes the field value to or from string

func (AddressMeddler) PostRead

func (b AddressMeddler) PostRead(fieldPtr, scanTarget interface{}) error

PostRead is called after a Scan operation for fields that have the AddressMeddler

func (AddressMeddler) PreRead

func (b AddressMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, err error)

PreRead is called before a Scan operation for fields that have the AddressMeddler

func (AddressMeddler) PreWrite

func (b AddressMeddler) PreWrite(fieldPtr interface{}) (saveValue interface{}, err error)

PreWrite is called before an Insert or Update operation for fields that have the AddressMeddler

type BigIntMeddler

type BigIntMeddler struct{}

BigIntMeddler encodes or decodes the field value to or from string

func (BigIntMeddler) PostRead

func (b BigIntMeddler) PostRead(fieldPtr, scanTarget interface{}) error

PostRead is called after a Scan operation for fields that have the BigIntMeddler

func (BigIntMeddler) PreRead

func (b BigIntMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, err error)

PreRead is called before a Scan operation for fields that have the BigIntMeddler

func (BigIntMeddler) PreWrite

func (b BigIntMeddler) PreWrite(fieldPtr interface{}) (saveValue interface{}, err error)

PreWrite is called before an Insert or Update operation for fields that have the BigIntMeddler

type DBer

type DBer interface {
	Querier
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

type HashMeddler

type HashMeddler struct{}

HashMeddler encodes or decodes the field value to or from string

func (HashMeddler) PostRead

func (b HashMeddler) PostRead(fieldPtr, scanTarget interface{}) error

PostRead is called after a Scan operation for fields that have the HashMeddler

func (HashMeddler) PreRead

func (b HashMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, err error)

PreRead is called before a Scan operation for fields that have the HashMeddler

func (HashMeddler) PreWrite

func (b HashMeddler) PreWrite(fieldPtr interface{}) (saveValue interface{}, err error)

PreWrite is called before an Insert or Update operation for fields that have the HashMeddler

type MerkleProofMeddler

type MerkleProofMeddler struct{}

MerkleProofMeddler encodes or decodes the field value to or from string

func (MerkleProofMeddler) PostRead

func (b MerkleProofMeddler) PostRead(fieldPtr, scanTarget interface{}) error

PostRead is called after a Scan operation for fields that have the MerkleProofMeddler

func (MerkleProofMeddler) PreRead

func (b MerkleProofMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, err error)

PreRead is called before a Scan operation for fields that have the MerkleProofMeddler

func (MerkleProofMeddler) PreWrite

func (b MerkleProofMeddler) PreWrite(fieldPtr interface{}) (saveValue interface{}, err error)

PreWrite is called before an Insert or Update operation for fields that have the MerkleProofMeddler

type Querier

type Querier interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

type SQLTxer

type SQLTxer interface {
	Querier
	Commit() error
	Rollback() error
}

type Tx

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

func (*Tx) AddCommitCallback

func (s *Tx) AddCommitCallback(cb func())

func (*Tx) AddRollbackCallback

func (s *Tx) AddRollbackCallback(cb func())

func (*Tx) Commit

func (s *Tx) Commit() error

func (*Tx) Rollback

func (s *Tx) Rollback() error

type Txer

type Txer interface {
	SQLTxer
	AddRollbackCallback(cb func())
	AddCommitCallback(cb func())
}

func NewTx

func NewTx(ctx context.Context, db DBer) (Txer, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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