gorm

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 11 Imported by: 5

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 ExistsByFilterExprs

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

func ExistsById

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

func ExistsByIdWithDeletedAt

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

func ExistsByQuerySQL

func ExistsByQuerySQL(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 GetDBWithContext

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

func GetDBWithLogger

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

func NewScope

func NewScope(field string, op dbi.Operation, args ...interface{}) func(*gorm.DB) *gorm.DB

func NewTraceDB

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

Types

type ChainRepository added in v0.0.32

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

func NewChainRepository added in v0.0.32

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

type ChainScope

type ChainScope []func(db *gorm.DB) *gorm.DB

var dao ChainScope dao.ById(1),ByName("a").Exec(db).First(v)

func (ChainScope) ById

func (c ChainScope) ById(id int) ChainScope

func (ChainScope) ByIdNoCheck

func (c ChainScope) ByIdNoCheck(id any) ChainScope

func (ChainScope) ByName

func (c ChainScope) ByName(name string) ChainScope

func (ChainScope) ByNameNoCheck

func (c ChainScope) ByNameNoCheck(name any) ChainScope

func (ChainScope) Exec

func (c ChainScope) Exec(db *gorm.DB) *gorm.DB

type Config

type Config struct {
	Type, Charset, Database, TimeZone string
	Host                              string `flag:"name:db_host;usage:数据库host"`
	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 FilterExprs

type FilterExprs dbi.FilterExprs

func (FilterExprs) Build

func (f FilterExprs) Build(odb *gorm.DB) *gorm.DB

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 added in v0.0.32

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

func NewRepository

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

func (*Repository[T]) Create added in v0.0.32

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

func (*Repository[T]) Delete added in v0.0.32

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

func (*Repository[T]) Retrieve added in v0.0.32

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

func (*Repository[T]) Update added in v0.0.32

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

type Scope

type Scope func(*gorm.DB) *gorm.DB

type Sqlite

type Sqlite struct {
	DSN string
}

Directories

Path Synopsis
mysql

Jump to

Keyboard shortcuts

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