db

package
v0.0.0-...-bff178f Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package db contains function which helps to work with PostgreSQL

Package db contains function which helps to work with PostgreSQL

Package db contains function which helps to work with PostgreSQL

Package db contains function which helps to work with PostgreSQL

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Options(
	fx.Provide(
		NewModule,
	),
)

Module for uber fx

Functions

func HandleDbError

func HandleDbError(err error) error

func IsAlreadyExistError

func IsAlreadyExistError(err error) bool

IsAlreadyExistError shows if entity already exist in db

func IsContextCanceledError

func IsContextCanceledError(err error) bool

IsContextCanceledError shows if operation was canceled

func IsForeignKeyViolationError

func IsForeignKeyViolationError(err error) bool

IsForeignKeyViolationError shows if foreign key violation error

func IsInvalidLength

func IsInvalidLength(err error) bool

IsInvalidValueError check if any field has invalid length

func IsInvalidTextRepresentationError

func IsInvalidTextRepresentationError(err error) bool

Useful for invalid enum values

func IsInvalidValueError

func IsInvalidValueError(err error) bool

IsInvalidValueError shows if foreign key violation error

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError shows if foreign key violation error

func IsUniqueViolationError

func IsUniqueViolationError(err error) bool

func New

func New(cfg *Config, opts ...Option) (*sql.DB, *gorm.DB, error)

New inits new database

func NewGormDB

func NewGormDB(cfg *Config, opts ...Option) (*sql.DB, error)

NewGormDB inits new gorm database connection

func NewModule

func NewModule(p ModuleParams) (*sql.DB, *gorm.DB, error)

NewModule returns new module for uber fx

Types

type Config

type Config struct {
	Postgres Postgres
}

Config should be included as part of service config.

func (*Config) Validate

func (c *Config) Validate() error

Validate config.

type ModuleParams

type ModuleParams struct {
	fx.In

	Config Config
}

ModuleParams contains module params

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option applies option

func WithMaxOpenConns

func WithMaxOpenConns(n int) Option

WithMaxOpenConns set max open connections to database

type Postgres

type Postgres struct {
	Host     string
	Port     int
	Database string
	User     string
	Password string
	SSLMode  string
}

Postgres defines configuration of the database

func (*Postgres) URL

func (p *Postgres) URL() string

URL for postgres.

func (*Postgres) Validate

func (p *Postgres) Validate() error

Validate config.

Directories

Path Synopsis
Package migrate
Package migrate

Jump to

Keyboard shortcuts

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