infra

package
v0.0.0-...-aa3a8fa Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GormCloseDB

func GormCloseDB(db *gorm.DB) (err error)

func GormEquals

func GormEquals[T comparable](tx *gorm.DB, field string, values []T) *gorm.DB

Abandoned, GormEquals(_DB.Table("accounts"), "id", ids).Delete(nil)

func GormFlip

func GormFlip(tx *gorm.DB, pageSize, pageIndex int) *gorm.DB

func GormFmtExpr

func GormFmtExpr(state string, a []any, b ...any) clause.Expr

func GormTransaction

func GormTransaction(db *gorm.DB, state string, a ...any) (err error)

func MigratePgDir

func MigratePgDir(dsn, migrations string) (err error)

func MigratePgFs

func MigratePgFs(dsn string, src embed.FS, subpath string) (err error)

//go:embed migrations/*.sql src embed.FS

MigratePgFs(dsn, src, "migrations")

func NewRedisClient

func NewRedisClient(vp *viper.Viper) (client *redis.Client, err error)

func PgArrayContains

func PgArrayContains[T any](tx *gorm.DB, field string, value T) *gorm.DB

func PgArrayIncludes

func PgArrayIncludes[T any](tx *gorm.DB, field string, arr []T) *gorm.DB

func PgArrayPush

func PgArrayPush[T any](field string, value T) clause.Expr

func PgConcateArrays

func PgConcateArrays[T any](tx *gorm.DB, field string, arr []T) clause.Expr

#### concat to array

func PgConnect

func PgConnect(vp *viper.Viper, release bool) (gormDB *gorm.DB, sqlDB *sql.DB, err error)

dsn: - postgres://{USERANME}:{PASSWORD}@tcp({IP})/{DATABASE}?sslmode=disable - "host=%s user=%s password=%s dbname=%s port=5432 sslmode=disable TimeZone=Asia/Shanghai"

func PgFindTables

func PgFindTables(db *gorm.DB, m string) (tables []string, err error)

"sys_.*", "sys_\\d+$"

func PgMergeArrays

func PgMergeArrays[T any](field string, arr []T) clause.Expr

#### push to array and remove duplicates

func PgNotFound

func PgNotFound(err error) bool

func PgTableExists

func PgTableExists(db *gorm.DB, table string) (existence bool, err error)

func PgTimestamptz

func PgTimestamptz(t ...time.Time) []byte

func PgUniqueViolation

func PgUniqueViolation(err error) bool

!!! works as expected only version(gorm.io/driver/postgres) <= v1.4.5

and errors.Is(e, gorm.ErrDuplicatedKey) doesn't work as expected

func SQLxCol

func SQLxCol(table string) func(...string) string

func SQLxInStrings

func SQLxInStrings[T uuid.UUID](ids []T) string

func SQLxInStrings[T uuid.UUID | string](ids []T) string {

func SQLxOrStrings

func SQLxOrStrings[T uuid.UUID | string](field string, ids []T) string

Abandoned

Types

type GormDate

type GormDate string

Date

func (*GormDate) Scan

func (self *GormDate) Scan(value interface{}) error

func (*GormDate) Validate

func (self *GormDate) Validate() (err error)

func (GormDate) Value

func (self GormDate) Value() (driver.Value, error)

type GormJSONAny

type GormJSONAny[T any] struct {
	Item T
}

GormJSON

func (GormJSONAny[T]) MarshalJSON

func (self GormJSONAny[T]) MarshalJSON() ([]byte, error)

func (*GormJSONAny[T]) Scan

func (self *GormJSONAny[T]) Scan(value any) (err error)

func (*GormJSONAny[T]) UnmarshalJSON

func (self *GormJSONAny[T]) UnmarshalJSON(data []byte) error

func (GormJSONAny[T]) Value

func (self GormJSONAny[T]) Value() (driver.Value, error)

type GormJSONArray

type GormJSONArray[T any] []T

GormJSONArray, json array

func (*GormJSONArray[T]) Scan

func (self *GormJSONArray[T]) Scan(value any) (err error)

func (GormJSONArray[T]) Value

func (self GormJSONArray[T]) Value() (driver.Value, error)

type GormJSONMap

type GormJSONMap[T any] map[string]T

GormJSONMap, json map

func (GormJSONMap[T]) JSON

func (self GormJSONMap[T]) JSON() (bts []byte)

func (*GormJSONMap[T]) Scan

func (self *GormJSONMap[T]) Scan(value any) (err error)

func (GormJSONMap[T]) Value

func (self GormJSONMap[T]) Value() (driver.Value, error)

type GormUUIDs

type GormUUIDs []uuid.UUID

https://github.com/jackc/pgx/issues/1781

func NewGormUUIDs

func NewGormUUIDs(a ...int) GormUUIDs

func (*GormUUIDs) FromStrings

func (self *GormUUIDs) FromStrings(ids []string) (err error)

func (*GormUUIDs) Scan

func (self *GormUUIDs) Scan(value any) error

Scan implements the sql.Scanner interface for postgres uuid[] deserialization. e.g. single: {23e4aa0c-8591-4544-8cc1-8348d9d7f901} e.g. multiple: {23e4aa0c-8591-4544-8cc1-8348d9d7f901,aee911e4-3fa8-4866-95ac-e4878d3e06e5}

func (GormUUIDs) Value

func (self GormUUIDs) Value() (driver.Value, error)

Value implements the driver.Valuer interface for postgres uuid[] serialization.

Jump to

Keyboard shortcuts

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