gormi

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MYSQL    = "mysql"
	POSTGRES = "postgres"
	SQLite   = "sqlite3"
)

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, Schema, TimeZone string
	Host                                      string `flag:"name:db_host;usage:数据库host"`
	Port                                      int32
	User, Password                            string
	TimeFormat                                string
	MaxIdleConns, MaxOpenConns                int

	GormConfig 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 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

Directories

Path Synopsis
mysql

Jump to

Keyboard shortcuts

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