db

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     string
	Username string
	Password string
	Database string
	Options  string

	MaxOpenConns    int
	MaxIdleConns    int
	MaxIdleConnTime time.Duration
	MaxConnLifetime time.Duration
}

func PosgresConfigFromEnv

func PosgresConfigFromEnv() PostgresConfig

PosgresConfigFromEnv returns a PostgresConfig struct with values from the environment. If no environment variables are set, it will return a PostgresConfig with default values.

The following environment variables are used: - POSTGRES_HOST (default: localhost) - POSTGRES_PORT (default: 5432) - POSTGRES_USERNAME (default: "") - POSTGRES_PASSWORD (default: "") - POSTGRES_DATABASE (default: "") - POSTGRES_OPTIONS (default: sslmode=disable) - POSTGRES_MAX_OPEN_CONNS (default: 10) - POSTGRES_MAX_IDLE_CONNS (default: 10) - POSTGRES_MAX_IDLE_CONN_TIME_SEC (default: 10) - POSTGRES_MAX_CONN_LIFETIME_SEC (default: 10)

type Repository

type Repository interface {
	Create(ctx context.Context, data any) error
	Find(data any) TX
	Update(data any) TX
	Delete(data any) TX
	Raw(ctx context.Context, query string, args ...any) error
	Migrate(ctx context.Context, model any) error
	Close(context.Context) error
}

Repository represents an interface between the application and the database.

func NewGormRepository

func NewGormRepository(conf PostgresConfig) (Repository, error)

NewGormRepository opens a connection to the database using the GORM library.

type TX

type TX interface {
	// Where adds a where clause to the query.
	Where(field string, value any) TX
	// Or adds an or clause to the query.
	Or(field string, value any) TX
	// Not adds a not clause to the query.
	Not(field string, value any) TX
	// Limit adds a limit clause to the query.
	Limit(limit int) TX
	// Commit executes the query.
	Commit(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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