datastore

package
v0.0.0-...-f003305 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 19 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// CurrentMigrationVersion holds the default migration version
	CurrentMigrationVersion = uint(66)
	// MigrationTracks holds the migration version for a given track (eyeshade, promotion, wallet)
	MigrationTracks = map[string]uint{
		"eyeshade": 20,
	}
)

Functions

func CreateTx

func CreateTx(ctx context.Context, ta TxAble) (tx *sqlx.Tx, err error)

CreateTx - helper to create a tx

func GetTx

func GetTx(ctx context.Context, ta TxAble) (context.Context, *sqlx.Tx, func(), func() error, error)

GetTx will get or create a tx on the context, if created hands back rollback and commit functions

Types

type Datastore

type Datastore interface {
	RawDB() *sqlx.DB
	NewMigrate() (*migrate.Migrate, error)
	Migrate(...uint) error
	RollbackTxAndHandle(tx *sqlx.Tx) error
	RollbackTx(tx *sqlx.Tx)
	BeginTx() (*sqlx.Tx, error)
}

Datastore holds generic methods

type Metadata

type Metadata map[string]interface{}

Metadata - type which represents key/value pair metadata

func (*Metadata) Scan

func (m *Metadata) Scan(value interface{}) error

Scan - implement driver.Scanner interface for conversion to and from sql

func (Metadata) Value

func (m Metadata) Value() (driver.Value, error)

Value - implement driver.Valuer interface for conversion to and from sql

type NullString

type NullString struct {
	sql.NullString
}

NullString is a type that lets ya get a null field from the database

func (*NullString) MarshalJSON

func (ns *NullString) MarshalJSON() ([]byte, error)

MarshalJSON for NullString

func (*NullString) UnmarshalJSON

func (ns *NullString) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls NullString

type Postgres

type Postgres struct {
	*sqlx.DB
}

Postgres is a Datastore wrapper around a postgres database

func NewPostgres

func NewPostgres(
	databaseURL string,
	performMigration bool,
	migrationTrack string,
	dbStatsPrefix ...string,
) (*Postgres, error)

NewPostgres creates a new Postgres Datastore

func (*Postgres) BeginTx

func (pg *Postgres) BeginTx() (*sqlx.Tx, error)

BeginTx starts a transaction

func (*Postgres) Migrate

func (pg *Postgres) Migrate(currentMigrationVersions ...uint) error

Migrate the Postgres instance

func (*Postgres) NewMigrate

func (pg *Postgres) NewMigrate() (*migrate.Migrate, error)

NewMigrate creates a Migrate instance given a Postgres instance with an active database connection

func (*Postgres) RawDB

func (pg *Postgres) RawDB() *sqlx.DB

RawDB - get the raw db

func (*Postgres) RollbackTx

func (pg *Postgres) RollbackTx(tx *sqlx.Tx)

RollbackTx rolls back a transaction (useful with defer)

func (*Postgres) RollbackTxAndHandle

func (pg *Postgres) RollbackTxAndHandle(tx *sqlx.Tx) error

RollbackTxAndHandle rolls back a transaction

type TxAble

type TxAble interface {
	RollbackTx(*sqlx.Tx)
	BeginTx() (*sqlx.Tx, error)
}

TxAble - something that is capable of beginning and rolling back a sqlx.Tx

Jump to

Keyboard shortcuts

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