gorm

package
v1.7.10 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete added in v1.6.13

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

func DeleteById added in v1.7.6

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

func Exists added in v1.6.13

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

func ExistsByColumn added in v1.6.13

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

func ExistsByFilterExprs added in v1.6.13

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

func ExistsById added in v1.6.13

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

func ExistsByIdWithDeletedAt added in v1.6.13

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

func ExistsByQuerySQL added in v1.6.13

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

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

func ExistsBySQL added in v1.6.13

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 added in v1.6.13

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

func GetDBWithLogger added in v1.6.13

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

func NewScope added in v1.7.8

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 BaseDao added in v1.7.8

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

func NewRepository

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

func (*BaseDao[T]) Create added in v1.7.8

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

func (*BaseDao[T]) Delete added in v1.7.8

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

func (*BaseDao[T]) Retrieve added in v1.7.8

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

func (*BaseDao[T]) Update added in v1.7.8

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

type ChainScope added in v1.7.8

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

func (ChainScope) ById added in v1.7.8

func (c ChainScope) ById(id int) ChainScope

db.Scope(ById(1),ByName("a")).First(v)

func (ChainScope) ByIdNoCheck added in v1.7.8

func (c ChainScope) ByIdNoCheck(id any) ChainScope

func (ChainScope) ByName added in v1.7.8

func (c ChainScope) ByName(name string) ChainScope

func (ChainScope) ByNameNoCheck added in v1.7.8

func (c ChainScope) ByNameNoCheck(name any) ChainScope

func (ChainScope) Exec added in v1.7.8

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 added in v1.6.13

type FilterExprs dbi.FilterExprs

func (FilterExprs) Build added in v1.6.13

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

type Mysql added in v1.2.1

type Mysql struct {
	ParseTime string
	Loc       string
}

type Postgres added in v1.2.1

type Postgres struct {
	Schema  string
	SSLMode string
}

type PrometheusConfig

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

type Scope added in v1.7.8

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

type Sqlite added in v1.2.1

type Sqlite struct {
	Path string
}

Directories

Path Synopsis
mysql

Jump to

Keyboard shortcuts

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