db

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpDownSeparator = "-- +migrate Up"

	NoLimitMigrations = 0 // indicate that there is no limit on the number of migrations to run
)
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 NewTx

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

func RegisterMeddler added in v0.3.0

func RegisterMeddler(name string, meddlerType meddler.Meddler)

RegisterMeddlerType registers a new meddler type with the given name

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 RunMigrationsDB

func RunMigrationsDB(logger *log.Logger, db *sql.DB, migrationsParam []types.Migration) error

func RunMigrationsDBExtended added in v0.5.0

func RunMigrationsDBExtended(logger *log.Logger,
	db *sql.DB,
	migrationsParam []types.Migration,
	dir migrate.MigrationDirection,
	maxMigrations int) error

RunMigrationsDBExtended is an extended version of RunMigrationsDB that allows dir: can be migrate.Up or migrate.Down maxMigrations: Will apply at most `max` migrations. Pass 0 for no limit (or use Exec)

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 HashMeddler

type HashMeddler struct{}

HashMeddler encodes or decodes the field value to or from string

func (HashMeddler) PostRead

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

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

func (HashMeddler) PreRead

func (m 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 (m HashMeddler) PreWrite(fieldPtr interface{}) (saveValue interface{}, err error)

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

type KeyValueStorage added in v0.2.0

type KeyValueStorage struct {
	*sql.DB
}

KeyValueStorage wraps a sql.DB instance to provide key-value storage functionality. It can be used to interact with a relational database as a key-value store.

func NewKeyValueStorage added in v0.2.0

func NewKeyValueStorage(db *sql.DB) *KeyValueStorage

NewKeyValueStorage creates and returns a new instance of KeyValueStorage using the provided sql.DB connection.

func (*KeyValueStorage) GetValue added in v0.2.0

func (kv *KeyValueStorage) GetValue(tx types.Querier, owner, key string) (string, error)

GetValue retrieves the value associated with the specified owner and key from the key-value storage. It uses the provided transaction (tx) for the query; if tx is nil, it falls back to the storage's default DB connection. Returns the value as a string if found, or an error if the key does not exist or if there is a database issue.

func (*KeyValueStorage) InsertValue added in v0.2.0

func (kv *KeyValueStorage) InsertValue(tx types.Querier, owner, key, value string) error

InsertValue inserts a new key-value pair into the storage for the specified owner. If a transaction (tx) is provided, it uses that transaction; otherwise, it uses the default database connection. The function sets the current Unix timestamp as the update time for the entry. Returns an error if the insertion fails.

func (*KeyValueStorage) UpdateValue added in v0.4.0

func (kv *KeyValueStorage) UpdateValue(tx types.Querier, owner, key, value string) error

UpdateValue inserts or updates a key-value pair for a given owner in the key-value storage. If a record with the specified owner and key already exists, its value and updated_at timestamp are updated. If no transaction (tx) is provided, the method uses the default database connection. Returns an error if the operation fails, wrapped with ReturnErrNotFound.

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 Tx

type Tx struct {
	types.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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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