datasource

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDatasourceNotFound = errors.New("datasource not found")
View Source
var ErrUsernameNotFound = errors.New("datasource username is empty")

Functions

func AutoMigrate

func AutoMigrate(dst ...interface{})

func AutoMigrateWithName

func AutoMigrateWithName(name string, dst ...interface{})

func ConvertBoolValue

func ConvertBoolValue(src any) (bool, error)

func Db

func Db() *gorm.DB

func GetDb

func GetDb(datasourceName string) *gorm.DB

func GetDbByCtx

func GetDbByCtx(ctx context.Context) *gorm.DB

func GetDbByCtxAndName

func GetDbByCtxAndName(ctx context.Context, name string) *gorm.DB

func InitDataSource

func InitDataSource(configMap map[string]Config) error

func RowsToListMap

func RowsToListMap(rows *sql.Rows) []cmap.Map[string, any]

func ToSqlTx

func ToSqlTx(db *gorm.DB) *sql.Tx

func Transaction

func Transaction(ctx context.Context, f func(txCtx context.Context) error) error

func TransactionWithDsName

func TransactionWithDsName(ctx context.Context, datasourceName string, f func(txCtx context.Context) error) error

Types

type BoolValue

type BoolValue interface {
	BoolValue() (*bool, error)
}

type Config

type Config struct {

	// 数据库类型
	Type string

	// 数据库url
	Host string

	// 数据库Username
	Username string

	// 数据库Password
	Password string

	// Silent 1 Error 2 Warn 3 Info 4
	LogLevel int

	// 数据库名称
	Dbname string

	// 连接池中最大空闲连接的数量  n <= 0 代表没有空闲
	MaxIdleConns int

	// 打开数据库连接的最大数量 n <= 0 代表不限制
	MaxOpenConns int

	// 连接可复用的最大时间(单位分钟) n <= 0 则不关闭连接
	ConnMaxLifetime int

	// 连接空闲的最大时间(单位分钟) n <= 0 则不关闭连接
	ConnMaxIdleTime int

	// 自动创建数据表
	AutoMigrate bool
}

type NullBool

type NullBool struct {
	Val   int64
	Valid bool // Valid is true if Bool is not NULL
}

NullBool represents a bool that may be null. NullBool implements the Scanner interface it can be used as a scan destination, similar to NullString.

func NewBool

func NewBool(value bool) NullBool

func (NullBool) BoolValue

func (n NullBool) BoolValue() (*bool, error)

func (NullBool) GormDBDataType

func (NullBool) GormDBDataType(db *gorm.DB, _ *schema.Field) string

func (NullBool) GormDataType

func (NullBool) GormDataType() string

func (NullBool) MarshalJSON

func (n NullBool) MarshalJSON() ([]byte, error)

MarshalJSON on JSONTime format Time field with Y-m-d H:i:s

func (*NullBool) Scan

func (n *NullBool) Scan(value any) error

Scan implements the Scanner interface.

func (*NullBool) UnmarshalJSON

func (n *NullBool) UnmarshalJSON(data []byte) (err error)

func (NullBool) Value

func (n NullBool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

Jump to

Keyboard shortcuts

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