gorm

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT, Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(db *gorm.DB, tableName string, column string, value any) error

func DeleteById

func DeleteById(db *gorm.DB, tableName string, id uint64) error

func Exists

func Exists(db *gorm.DB, tableName, column string, value interface{}, withDeletedAt bool) (bool, error)

func ExistsByColumn

func ExistsByColumn(db *gorm.DB, tableName, column string, value interface{}) (bool, error)

func ExistsByColumnWithDeletedAt

func ExistsByColumnWithDeletedAt(db *gorm.DB, tableName, column string, value interface{}) (bool, error)

func ExistsByFilterExprs

func ExistsByFilterExprs(db *gorm.DB, tableName string, filters sql3.FilterExprs) (bool, error)

func ExistsByQuery

func ExistsByQuery(db *gorm.DB, qsql string, value ...any) (bool, error)

根据查询语句查询数据是否存在

func ExistsBySQL

func ExistsBySQL(db *gorm.DB, sql string, value ...any) (bool, error)

func GetById

func GetById[T any](db *gorm.DB, id any) (*T, error)

func NewDBWithContext

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

func NewDBWithLogger

func NewDBWithLogger(db *gorm.DB, log *log.Logger, conf *logger.Config) *gorm.DB

func NewTraceDB

func NewTraceDB(db *gorm.DB, ctx context.Context, traceId string) *gorm.DB

func TableName

func TableName(tx *gorm.DB, name string) *gorm.DB

Types

type ChainRepository

type ChainRepository[T any] struct {
	scope.ChainScope
	*gorm.DB
}

func NewChainRepository

func NewChainRepository[T any](db *gorm.DB) *ChainRepository[T]

type Config

type Config struct {
	Type, Charset, Database, TimeZone string
	Host                              string
	Port                              int32
	User, Password                    string
	Postgres                          Postgres
	Mysql                             Mysql
	Sqlite                            Sqlite
	MaxIdleConns, MaxOpenConns        int
	ConnMaxLifetime, ConnMaxIdleTime  time.Duration

	Gorm gorm.Config

	EnableStdLogger bool
	Logger          logger.Config

	NamingStrategy schema.NamingStrategy

	EnablePrometheus  bool
	Prometheus        prometheus.Config
	PrometheusConfigs []PrometheusConfig
}

func (*Config) Init

func (c *Config) Init()

type Mysql

type Mysql struct {
	ParseTime string
	Loc       string
}

type Postgres

type Postgres struct {
	Schema  string
	SSLMode string
}

type PrometheusConfig

type PrometheusConfig struct {
	Prefix        string
	Interval      uint32
	VariableNames []string
}

type Repository

type Repository[T any] struct {
	*gorm.DB
}

func NewRepository

func NewRepository[T any](db *gorm.DB) *Repository[T]

func (*Repository[T]) Create

func (r *Repository[T]) Create(t *T) error

func (*Repository[T]) Delete

func (r *Repository[T]) Delete(id any) error

func (*Repository[T]) Retrieve

func (r *Repository[T]) Retrieve(id any) (*T, error)

func (*Repository[T]) Update

func (r *Repository[T]) Update(t *T) error

type Sqlite

type Sqlite struct {
	DSN string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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