db

package
v0.0.0-...-46aef10 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = fmt.Errorf("not found")
	ErrKey      = fmt.Errorf("invalid key format")
)

Functions

func Ctx

func Ctx(ctx context.Context, db *gorm.DB) context.Context

func CtxNew

func CtxNew(ctx context.Context) context.Context

func DBAll

func DBAll[T DBModelID](db *gorm.DB, cb func(T) error) error

func ExecuteSQLFilesFromEmbed

func ExecuteSQLFilesFromEmbed(ctx context.Context, fs embed.FS, dir string) error

ExecuteSQLFilesFromEmbed reads SQL files from an embedded directory and executes them if not already executed. Uses a transaction to ensure atomicity of SQL execution and history recording.

func For

func For(ctx context.Context) *gorm.DB

func GenID

func GenID(ctx context.Context, name string) (int64, error)

Gen generates a new ID for the given name Uses Upsert to atomically increment the sequence number

func Loader

func Loader[T any](column string, key func(T) string, options ...dataloadgen.Option) *dataloadgen.Loader[string, T]

func LoaderCtx

func LoaderCtx[T any](column string, key func(context.Context, T) string, options ...dataloadgen.Option) *dataloadgen.Loader[string, T]

func LoaderCtxs

func LoaderCtxs[T any](columns []string, key func(context.Context, T) []string, options ...dataloadgen.Option) *dataloadgen.Loader[string, T]

func Loaders

func Loaders[T any](columns []string, key func(T) []string, options ...dataloadgen.Option) *dataloadgen.Loader[string, T]

func LoadersKey

func LoadersKey(keys ...string) string

func NewLoggerOp

func NewLoggerOp(logger logger.Interface) func(*gorm.Config)

func Tx

func Tx(ctx context.Context, f func(context.Context) error, opts ...*sql.TxOptions) error

func WhereCtx

func WhereCtx(ctx context.Context, query string, args ...any) context.Context

Types

type Array

type Array[T any] []T

type Config

type Config struct {
	Driver string `json:"driver" yaml:"driver"`
	URL    string `json:"url"    yaml:"url"`
	// contains filtered or unexported fields
}

func (*Config) Ctx

func (c *Config) Ctx(ctx context.Context) context.Context

func (*Config) DB

func (c *Config) DB() *gorm.DB

func (*Config) Open

func (d *Config) Open(ops ...Option) (*gorm.DB, error)

type DBModelID

type DBModelID interface {
	GetID() uint
}

type IDGen

type IDGen struct {
	Model
	Name string `gorm:"uniqueIndex"` // Unique name for ID generator
	Num  int64  // Current sequence number
}

type Map

type Map[K comparable, T any] map[K]T

type Model

type Model struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`

	ID uint `gorm:"primarykey"`
}

func (Model) GetID

func (d Model) GetID() uint

type Option

type Option func(*gorm.Config)

type SQLExecutionHistory

type SQLExecutionHistory struct {
	Model
	FileName string `gorm:"uniqueIndex"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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