database

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 20 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionIsNotInitialized = errors.New("connection is not initialized")
	ErrUnsupportedDatabaseType    = errors.New("unsupported database type")
)

errors

Functions

func CreateTables added in v0.3.0

func CreateTables(ctx context.Context, conn Database, models ...any) error

CreateTables - creates tables by passed models. If partition tag is present table will be partitioned

func MakeComments added in v0.2.36

func MakeComments(ctx context.Context, sc SchemeCommenter, models ...interface{}) error

MakeComments -

func Wait

func Wait(ctx context.Context, db driver.Pinger, checkPeriod time.Duration)

Wait -

Types

type Bun added in v0.3.0

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

Bun -

func NewBun added in v0.3.0

func NewBun() *Bun

NewBun -

func (*Bun) Close added in v0.3.0

func (db *Bun) Close() error

Close -

func (*Bun) Connect added in v0.3.0

func (db *Bun) Connect(ctx context.Context, cfg config.Database) error

Connect -

func (*Bun) CreateState added in v0.3.0

func (db *Bun) CreateState(ctx context.Context, s *State) error

CreateState -

func (*Bun) CreateTable added in v0.3.0

func (db *Bun) CreateTable(ctx context.Context, model any, opts ...CreateTableOption) error

CreateTable -

func (*Bun) DB added in v0.3.0

func (db *Bun) DB() *bun.DB

DB -

func (*Bun) DeleteState added in v0.3.0

func (db *Bun) DeleteState(ctx context.Context, s *State) error

DeleteState -

func (*Bun) Exec added in v0.3.0

func (db *Bun) Exec(ctx context.Context, query string, args ...any) (int64, error)

Exec -

func (*Bun) MakeColumnComment added in v0.3.0

func (db *Bun) MakeColumnComment(ctx context.Context, tableName string, columnName string, comment string) error

MakeColumnComment -

func (*Bun) MakeTableComment added in v0.3.0

func (db *Bun) MakeTableComment(ctx context.Context, name string, comment string) error

MakeTableComment -

func (*Bun) Ping added in v0.3.0

func (db *Bun) Ping(ctx context.Context) error

Ping -

func (*Bun) State added in v0.3.0

func (db *Bun) State(ctx context.Context, indexName string) (*State, error)

State -

func (*Bun) UpdateState added in v0.3.0

func (db *Bun) UpdateState(ctx context.Context, s *State) error

UpdateState -

type CreateTableOption added in v0.3.0

type CreateTableOption func(opts *CreateTableOptions)

CreateTableOption -

func WithIfNotExists added in v0.3.0

func WithIfNotExists() CreateTableOption

WithIfNotExists -

func WithPartitioning added in v0.3.0

func WithPartitioning(by string) CreateTableOption

WithPartitioning -

func WithTemporary added in v0.3.0

func WithTemporary() CreateTableOption

WithTemporary -

type CreateTableOptions added in v0.3.0

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

CreateTableOptions -

type Database

type Database interface {
	Connect(ctx context.Context, cfg config.Database) error
	Exec(ctx context.Context, query string, args ...any) (int64, error)
	CreateTable(ctx context.Context, model any, opts ...CreateTableOption) error

	StateRepository
	SchemeCommenter

	driver.Pinger
	io.Closer
}

Database -

type PartitionBy added in v0.3.0

type PartitionBy int

PartitionBy -

const (
	PartitionByMonth PartitionBy = iota + 1
	PartitionByYear
)

type PostgreSQLContainer added in v0.3.0

type PostgreSQLContainer struct {
	testcontainers.Container
	Config PostgreSQLContainerConfig
	// contains filtered or unexported fields
}

func NewPostgreSQLContainer added in v0.3.0

func NewPostgreSQLContainer(ctx context.Context, cfg PostgreSQLContainerConfig) (*PostgreSQLContainer, error)

NewPostgreSQLContainer -

func (PostgreSQLContainer) GetDSN added in v0.3.0

func (c PostgreSQLContainer) GetDSN() string

GetDSN -

func (PostgreSQLContainer) MappedPort added in v0.3.0

func (c PostgreSQLContainer) MappedPort() nat.Port

MappedPort -

type PostgreSQLContainerConfig added in v0.3.0

type PostgreSQLContainerConfig struct {
	User     string
	Password string
	Database string
	Host     string
	Port     int
	Image    string
}

type RangePartitionManager added in v0.3.0

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

RangePartitionManager -

func NewPartitionManager added in v0.3.0

func NewPartitionManager(conn Database, by PartitionBy) RangePartitionManager

NewPartitionManager -

func (*RangePartitionManager) CreatePartition added in v0.3.0

func (pm *RangePartitionManager) CreatePartition(ctx context.Context, currentTime time.Time, tableName string) error

CreatePartition -

func (*RangePartitionManager) CreatePartitions added in v0.3.0

func (pm *RangePartitionManager) CreatePartitions(ctx context.Context, currentTime time.Time, tableNames ...string) error

CreatePartitions -

type SchemeCommenter added in v0.2.35

type SchemeCommenter interface {
	MakeTableComment(ctx context.Context, name string, comment string) error
	MakeColumnComment(ctx context.Context, tableName string, columnName string, comment string) error
}

SchemeCommenter -

type State

type State struct {
	bun.BaseModel `gorm:"-" pg:"-" bun:"dipdup_state" json:"-" comment:"Indexer state table"`

	IndexName string    `gorm:"primaryKey" pg:",pk" bun:",pk" json:"index_name" comment:"Index name"`
	IndexType string    `json:"index_type" comment:"Index type"`
	Hash      string    `json:"hash" comment:"Current hash"`
	Timestamp time.Time `json:"timestamp" comment:"Current timestamp"`
	Level     uint64    `json:"level" comment:"Index level"`
	UpdatedAt int       `gorm:"autoUpdateTime" comment:"Last updated timestamp"`
	CreatedAt int       `gorm:"autoCreateTime" comment:"Created timestamp"`
	// contains filtered or unexported fields
}

State -

func (*State) BeforeInsert

func (s *State) BeforeInsert(ctx context.Context) (context.Context, error)

BeforeInsert -

func (*State) BeforeUpdate

func (s *State) BeforeUpdate(ctx context.Context) (context.Context, error)

BeforeUpdate -

func (State) TableName

func (State) TableName() string

TableName -

type StateRepository

type StateRepository interface {
	State(ctx context.Context, name string) (*State, error)
	UpdateState(sctx context.Context, tate *State) error
	CreateState(ctx context.Context, state *State) error
	DeleteState(ctx context.Context, state *State) error
}

StateRepository -

Jump to

Keyboard shortcuts

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