Documentation
¶
Index ¶
- Constants
- Variables
- func GetMigrationsIDsApplied(db *sql.DB) ([]string, error)
- func NewSQLiteDB(dbPath string) (*sql.DB, error)
- func NewTx(ctx context.Context, db types.DBer) (types.Txer, error)
- func RegisterMeddler(name string, meddlerType meddler.Meddler)
- func ReturnErrNotFound(err error) error
- func RunMigrations(dbPath string, migrations []types.Migration) error
- func RunMigrationsDB(logger aggkitcommon.Logger, db *sql.DB, migrationsParam []types.Migration) error
- func RunMigrationsDBExtended(logger aggkitcommon.Logger, db *sql.DB, migrationsParam []types.Migration, ...) error
- func RunMigrationsDown(dbPath string, migrations []types.Migration, ...) error
- func RunMigrationsExtended(dbPath string, migrations []types.Migration, ...) error
- func SQLiteErr(err error) (*sqlite.Error, bool)
- func SlicePtrsToSlice(slice interface{}) interface{}
- func SliceToSlicePtrs(slice interface{}) interface{}
- type AddressMeddler
- type BigIntMeddler
- type HashMeddler
- type KeyValueStorage
- type MerkleProofMeddler
- type Tx
Constants ¶
const ( UpDownSeparator = "-- +migrate Up" NoLimitMigrations = 0 // indicate that there is no limit on the number of migrations to run )
const (
UniqueConstraintErrCode = 1555
)
Variables ¶
var (
ErrNotFound = errors.New("not found")
)
Functions ¶
func GetMigrationsIDsApplied ¶
GetMigrationsIDsApplied returns the list of migration IDs that have been applied to the database, ordered by application time. It is useful to know which migrations have been applied, e.g. before executing migrations or after a down migration.
func NewSQLiteDB ¶
NewSQLiteDB creates a new SQLite DB
func RegisterMeddler ¶ added in v0.3.0
RegisterMeddlerType registers a new meddler type with the given name
func ReturnErrNotFound ¶
func RunMigrations ¶
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 RunMigrationsDBExtended ¶ added in v0.5.0
func RunMigrationsDBExtended(logger aggkitcommon.Logger, db *sql.DB, migrationsParam []types.Migration, idempotentFunc func(*sql.DB) error, 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 RunMigrationsDown ¶ added in v0.8.1
func RunMigrationsExtended ¶
func RunMigrationsExtended(dbPath string, migrations []types.Migration, idempotentFunc func(*sql.DB) error) error
RunMigrationsExtended is an extended version of RunMigrations that allows to execute an idempotent function after running the migrations, which can be useful to execute some extra SQL statements that are not included in the migrations or to do some checks.
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
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
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 ¶
func (*Tx) AddCommitCallback ¶
func (s *Tx) AddCommitCallback(cb func())
func (*Tx) AddRollbackCallback ¶
func (s *Tx) AddRollbackCallback(cb func())