postgres

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PqForeignKeyViolationError = pq.ErrorCode("23503")
	PqUniqueViolationError     = pq.ErrorCode("23505")
)

Variables

This section is empty.

Functions

func MapError

func MapError(err error) error

func MapPqError

func MapPqError(err error) error

Types

type Chunk

type Chunk struct {
	ID           string `db:"id"`
	LogID        string `db:"log_id"`
	Min          string `db:"min"`
	Max          string `db:"max"`
	RecordsCount int    `db:"records"`
}

type Db

type Db struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

Db exposes db operations

func GetDb

func GetDb(ctx context.Context, dsName string) (*Db, error)

GetDb returns the Db object built for the given configuration

func MustGetDb

func MustGetDb(ctx context.Context, dsName string) *Db

MustGetDb does the same as GetDb but panics in case of an error

func (*Db) Init

func (s *Db) Init(ctx context.Context) error

Init implements linker.Initializer

func (*Db) Shutdown

func (s *Db) Shutdown()

Shutdown implements linker.Shutdowner

type DbConfig

type DbConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	DbName   string
	SslMode  string
}

func (DbConfig) DataSourceFull

func (ds DbConfig) DataSourceFull() string

func (DbConfig) DataSourceNoDb

func (ds DbConfig) DataSourceNoDb() string

type DbContainer

type DbContainer interface {
	io.Closer
	DbConfig() DbConfig
}

func NewNilDbContainer

func NewNilDbContainer(opts ...DbOption) (DbContainer, error)

func NewPgDbContainer

func NewPgDbContainer(ctx context.Context, image string, opts ...DbOption) (DbContainer, error)

NewPgDbContainer runs pg database in a docker container.

type DbOption

type DbOption func(cfg *DbConfig)

func WithDbName

func WithDbName(dbName string) DbOption

func WithHost

func WithHost(host string) DbOption

func WithPassword

func WithPassword(password string) DbOption

func WithPort

func WithPort(port string) DbOption

func WithSslMode

func WithSslMode(sslMode string) DbOption

func WithUser

func WithUser(user string) DbOption

type Log

type Log struct {
	ID        string    `db:"id"`
	Tags      Tags      `db:"tags"`
	Records   int64     `db:"records"`
	Deleted   bool      `db:"deleted"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type Storage

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

Storage is the logs meta storage

func NewStorage

func NewStorage(db *Db) *Storage

NewStorage creates new logs meta storage based on Postgres

func (*Storage) CreateLog

func (s *Storage) CreateLog(ctx context.Context, log *solaris.Log) (*solaris.Log, error)

CreateLog implements storage.Logs

func (*Storage) DeleteLogs

func (s *Storage) DeleteLogs(ctx context.Context, req storage.DeleteLogsRequest) (*solaris.DeleteLogsResult, error)

DeleteLogs implements storage.Logs

func (*Storage) GetChunks

func (s *Storage) GetChunks(ctx context.Context, logID string) ([]logfs.ChunkInfo, error)

GetChunks implements logfs.LogsMetaStorage

func (*Storage) GetLastChunk

func (s *Storage) GetLastChunk(ctx context.Context, logID string) (logfs.ChunkInfo, error)

GetLastChunk implements logfs.LogsMetaStorage

func (*Storage) GetLogByID

func (s *Storage) GetLogByID(ctx context.Context, id string) (*solaris.Log, error)

GetLogByID implements storage.Logs

func (*Storage) QueryLogs

func (s *Storage) QueryLogs(ctx context.Context, qr storage.QueryLogsRequest) (*solaris.QueryLogsResult, error)

QueryLogs implements storage.Logs

func (*Storage) UpdateLog

func (s *Storage) UpdateLog(ctx context.Context, log *solaris.Log) (*solaris.Log, error)

UpdateLog implements storage.Logs

func (*Storage) UpsertChunkInfos

func (s *Storage) UpsertChunkInfos(ctx context.Context, logID string, cis []logfs.ChunkInfo) error

UpsertChunkInfos implements logfs.LogsMetaStorage

type Tags

type Tags map[string]string

func (Tags) JSON

func (t Tags) JSON() string

func (*Tags) Scan

func (t *Tags) Scan(value any) error

func (Tags) Value

func (t Tags) Value() (value driver.Value, err error)

Jump to

Keyboard shortcuts

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