gorm

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EndCallback

func EndCallback(db *gorm.DB, mod string)

func EndCallbackReq

func EndCallbackReq(db *gorm.DB, mod string) *crawler.Request

func GetById

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

func GetDB

func GetDB(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

Types

type ChainDao

type ChainDao struct {
	Ctx          context.Context
	DB, OriginDB *gorm.DB
}

func NewChainDao

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

func (*ChainDao) ById

func (c *ChainDao) ById(id int) *ChainDao

func (*ChainDao) ByName

func (c *ChainDao) ByName(name string) *ChainDao

func (*ChainDao) ResetDB

func (c *ChainDao) ResetDB()

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 Cursor

type Cursor struct {
	Type   string `json:"type" gorm:"primaryKey"`
	Cursor string
	Prev   string
	Next   string
}

func GetCursor

func GetCursor(db *gorm.DB, mod string) (*Cursor, error)

type DB

type DB[T any] gorm.DB

func (*DB[T]) GetById

func (db *DB[T]) GetById(id int) (*T, error)

type DB2

type DB2[T any] struct {
	gorm.DB
}

func (*DB2[T]) GetById

func (db *DB2[T]) GetById(id int) (*T, error)

type FilterExpressions

type FilterExpressions []dbi.FilterExpression

func (FilterExpressions) BuildORM

func (f FilterExpressions) BuildORM(odb *gorm.DB) *gorm.DB

type ModelTime

type ModelTime struct {
	CreatedAt time.Time `json:"created_at" gorm:"default:current_timestamp"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt time.Time `json:"deleted_at" gorm:"default:null"`
}

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 Repository

type Repository[T any] struct {
	ChainDao
}

func NewRepository

func NewRepository[T any](ctx context.Context, 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 int) error

func (*Repository[T]) Read

func (r *Repository[T]) Read(id int) (*T, error)

func (*Repository[T]) Update

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

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