db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLite     = "sqlite"
	MySQL      = "mysql"
	Postgres   = "postgres"
	Clickhouse = "clickhouse"
)

Variables

This section is empty.

Functions

func WrapContext

func WrapContext(ctx context.Context, tx *gorm.DB) context.Context

Types

type ConnectionConfig

type ConnectionConfig struct {
	MaxOpen     int
	MaxIdle     int
	MaxLifetime time.Duration
	ExecTimeout time.Duration
}

type Manager

type Manager interface {
	common.Service
	common.Initializable
	common.Debuggable
	ORM() *gorm.DB
	DB() *sql.DB
	FromContext(ctx context.Context) *gorm.DB
	FromContextTimeout(ctx context.Context, timeout time.Duration) (*gorm.DB, context.CancelFunc)
	Cleanup(schema bool) error
	Reload() error
}

func New

func New(opts ...Option) Manager

type MigrationConfig

type MigrationConfig struct {
	Directory string
	Version   uint
}

type Option

type Option func(*manager)

func WithConnection

func WithConnection(maxOpen int, maxIdle int, maxLifetime time.Duration, execTimeout time.Duration) Option

func WithDataSource

func WithDataSource(source Source) Option

func WithLogger

func WithLogger(logger log.Logger) Option

func WithMigration

func WithMigration(sqlDir string, version uint) Option

func WithName

func WithName(name string) Option

func WithType

func WithType(dbtype string) Option

type Source

type Source struct {
	Host     string
	Port     uint
	User     string
	Password string `print:"-"`
	DBName   string
}

func (*Source) DSN

func (s *Source) DSN(dbtype string) (string, error)

Jump to

Keyboard shortcuts

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