sdgorm

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package sdgorm GORM扩展

Index

Constants

This section is empty.

Variables

View Source
var (
	LoggerDiscard        = gormlogger.Discard
	LoggerGormDefault    = gormlogger.Default
	LoggerPlainInfo      = newGormLogger(gormlogger.Info, false)
	LoggerPlainWarn      = newGormLogger(gormlogger.Warn, false)
	LoggerPlainError     = newGormLogger(gormlogger.Error, false)
	LoggerPlainSilent    = newGormLogger(gormlogger.Silent, false)
	LoggerColorfulInfo   = newGormLogger(gormlogger.Info, true)
	LoggerColorfulWarn   = newGormLogger(gormlogger.Warn, true)
	LoggerColorfulError  = newGormLogger(gormlogger.Error, true)
	LoggerColorfulSilent = newGormLogger(gormlogger.Silent, true)
	LoggerBuiltin        = newBuiltinLogger(200 * time.Millisecond)
)
View Source
var (
	ErrIllegalDriver = sderr.Sentinel("illegal driver")
)

Functions

func Create

func Create(tx *gorm.DB, row any) (int64, error)

func CreateAndTake

func CreateAndTake[T any](tx *gorm.DB, row T, q any, args ...any) (T, error)

func CreateInBatches

func CreateInBatches(tx *gorm.DB, rows any, opts *CreateInBatchesOptions) (int64, error)

func Delete

func Delete[T any](tx *gorm.DB, conds ...any) (int64, error)

func Dial

func Dial(addr Address, config *gorm.Config) (*gorm.DB, error)

func Exec

func Exec(tx *gorm.DB, q string, values ...any) (int64, error)

func Exists

func Exists[T any](tx *gorm.DB, conds ...any) (bool, error)

func Find

func Find[T any](tx *gorm.DB, conds ...any) ([]T, error)

func FindPaging

func FindPaging[T any](builder func() *gorm.DB, p sdsql.Page) (*sdsql.PagingResult[T], error)

func First

func First[T any](tx *gorm.DB, conds ...any) (T, error)

func Last

func Last[T any](tx *gorm.DB, conds ...any) (T, error)

func LoggerOf

func LoggerOf(name string) gormlogger.Interface

func Modify

func Modify[T any](tx *gorm.DB, modifier func(T) T, q any, args ...any) (int64, error)

func ModifyAndTake

func ModifyAndTake[T any](tx *gorm.DB, modifier func(T) T, q any, args ...any) (T, error)

func MustMapper

func MustMapper[M any](asPrimitive bool) func(sdjson.Object) (M, error)

func MustMapperToAny

func MustMapperToAny[M any](asPrimitive bool) func(sdjson.Object) (any, error)

func NewMapper

func NewMapper[M any](asPrimitive bool) (func(sdjson.Object) (M, error), error)

func NewMapperToAny

func NewMapperToAny[M any](asPrimitive bool) (func(sdjson.Object) (any, error), error)

func PageScope added in v0.2.0

func PageScope(p sdsql.Page) func(*gorm.DB) *gorm.DB

func Raw

func Raw[T any](tx *gorm.DB, q string, values ...any) (T, error)

func RawPaging

func RawPaging[T any](tx *gorm.DB, selectSql string, args map[string]any, p sdsql.Page) (*sdsql.PagingResult[T], error)

func RowExists

func RowExists[T any](_ T, err error) (bool, error)

func Scan

func Scan[T any](tx *gorm.DB) (T, error)

func Take

func Take[T any](tx *gorm.DB, conds ...any) (T, error)

func Transaction

func Transaction[R any](db *gorm.DB, action func(tx *gorm.DB) (R, error), opts ...*sql.TxOptions) (R, error)

func UpdateColumns

func UpdateColumns[T any](tx *gorm.DB, colVals map[string]any, q any, args ...any) (int64, error)

func UpdateColumnsAndTake

func UpdateColumnsAndTake[T any](tx *gorm.DB, colVals map[string]any, q any, args ...any) (T, error)

Types

type Address

type Address struct {
	// common
	Driver string `json:"driver" toml:"driver" yaml:"driver"`
	DSN    string `json:"dsn" toml:"dsn" yaml:"dsn"`
	Logger string `json:"logger" toml:"logger"`

	// mysql
	MySqlConn                      gorm.ConnPool `json:"-" toml:"-"`
	MySqlSkipInitializeWithVersion bool          `json:"mysql_skip_initialize_with_version" toml:"mysql_skip_initialize_with_version" yaml:"mysql_skip_initialize_with_version"`
	MySqlDefaultStringSize         uint          `json:"mysql_default_string_size" toml:"mysql_default_string_size" yaml:"mysql_default_string_size"`
	MySqlDefaultDatetimePrecision  *int          `json:"mysql_default_datetime_precision" toml:"mysql_default_datetime_precision" yaml:"mysql_default_datetime_precision"`
	MySqlDisableDatetimePrecision  bool          `json:"mysql_disable_datetime_precision" toml:"mysql_disable_datetime_precision" yaml:"mysql_disable_datetime_precision"`
	MySqlDontSupportRenameIndex    bool          `json:"mysql_dont_support_rename_index" toml:"mysql_dont_support_rename_index" yaml:"mysql_dont_support_rename_index"`
	MySqlDontSupportRenameColumn   bool          `json:"mysql_dont_support_rename_column" toml:"mysql_dont_support_rename_column" yaml:"mysql_dont_support_rename_column"`
	MySqlDontSupportForShareClause bool          `` /* 128-byte string literal not displayed */

	// postgres
	PostgresConn                 *sql.DB `json:"-" toml:"-"`
	PostgresPreferSimpleProtocol bool    `json:"postgres_prefer_simple_protocol" toml:"postgres_prefer_simple_protocol" yaml:"postgres_prefer_simple_protocol"`
	PostgresWithoutReturning     bool    `json:"postgres_without_returning" toml:"postgres_without_returning" yaml:"postgres_without_returning"`
}

type CreateInBatchesOptions

type CreateInBatchesOptions struct {
	Table     string // 可以指定表名,如果为空,则使用model中表名
	Clear     bool   // 在插入数据前删除表中所有数据(危险操作)
	Overwrite bool   // 如果为true,如果表中存在相同ID的行,则覆盖掉原来的行;否则不修改任何数据
}

type Schema

type Schema struct {
	*schema.Schema
}

func ParseSchema

func ParseSchema(model any, namer schema.Namer) (Schema, error)

func (Schema) DBFieldNames

func (s Schema) DBFieldNames() []string

func (Schema) IsNil

func (s Schema) IsNil() bool

Jump to

Keyboard shortcuts

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