database

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database represents a database replicas pool.

func New

func New(ctx context.Context, replica ...*Replica) (*Database, error)

New creates a new database replicas pool.

func NewFromDSN

func NewFromDSN(ctx context.Context, dsn ...string) (*Database, error)

func (*Database) Begin

func (d *Database) Begin(ctx context.Context, t ReplicaType) (pgx.Tx, error)

func (*Database) BeginFunc

func (d *Database) BeginFunc(ctx context.Context, t ReplicaType, f func(pgx.Tx) error) error

func (*Database) BeginTx

func (d *Database) BeginTx(ctx context.Context, t ReplicaType, txOptions pgx.TxOptions) (pgx.Tx, error)

func (*Database) BeginTxFunc

func (d *Database) BeginTxFunc(ctx context.Context, t ReplicaType, txOptions pgx.TxOptions, f func(pgx.Tx) error) error

func (*Database) Exec

func (d *Database) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)

Exec executes a non-SELECT query using an RW replica.

func (*Database) GetReplica

func (d *Database) GetReplica(t ReplicaType) *Replica

GetReplica returns a next replica of type t from a pool.

func (*Database) Migrate

func (d *Database) Migrate(source migration.Source, direction migration.Direction, max int) (int, error)

func (*Database) Query

func (d *Database) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query executes a SELECT query using an RO replica.

func (*Database) QueryFunc

func (d *Database) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)

func (*Database) QueryRow

func (d *Database) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

func (*Database) SelectAll

func (d *Database) SelectAll(ctx context.Context, dest interface{}, sql string, args ...interface{}) error

SelectAll performs a SELECT query and scans all rows into a slice of structs or maps.

func (*Database) SelectOne

func (d *Database) SelectOne(ctx context.Context, dest interface{}, sql string, args ...interface{}) error

SelectOne performs a SELECT query and scans a single row into a struct or map.

func (*Database) SendBatch

func (d *Database) SendBatch(ctx context.Context, t ReplicaType, b *pgx.Batch) pgx.BatchResults

type Entity

type Entity struct {
	ID        uint
	UUID      pgtype.UUID
	CreatedAt pgtype.Timestamp
	UpdatedAt pgtype.Timestamp
	DeletedAt pgtype.Timestamp
}

func (*Entity) GetCreatedAt

func (e *Entity) GetCreatedAt() time.Time

func (*Entity) GetDeletedAt

func (e *Entity) GetDeletedAt() time.Time

func (*Entity) GetID

func (e *Entity) GetID() uint

GetID returns entity ID.

func (*Entity) GetUUID

func (e *Entity) GetUUID() string

GetUUID returns entity UUID.

func (*Entity) GetUpdatedAt

func (e *Entity) GetUpdatedAt() time.Time

type Replica

type Replica struct {
	DSN  string
	Type ReplicaType
	// contains filtered or unexported fields
}

func ROReplica

func ROReplica(dsn string) *Replica

ROReplica makes a new RO replica.

func RWReplica

func RWReplica(dsn string) *Replica

RWReplica makes a new RW replica.

func (*Replica) Ping

func (r *Replica) Ping(ctx context.Context) error

Ping verifies a connection to the database is still alive, establishing a connection if necessary.

type ReplicaType

type ReplicaType uint8
const (
	ReplicaTypeRW ReplicaType = iota
	ReplicaTypeRO
)

Jump to

Keyboard shortcuts

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