dbdrivers

package
v2.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRedisInvalidParameter = errors.New("redis invalid parameter")

Functions

func GetRedisCachePrefix

func GetRedisCachePrefix() string

func InitMongoMasterConn

func InitMongoMasterConn(config MongoConfig, logger echo.Logger) (*mongo.Client, string)

func InitMongoTenantConns

func InitMongoTenantConns(config MongoConfig, master *gorm.DB, tenantAlterDbHostParam, tenantDBPassPhraseKey string, logger echo.Logger) (map[uint64]*mongo.Client, map[uint64]string)

Init the mongo database connection map.

func InitMysqlMasterConn

func InitMysqlMasterConn(config SQLConfig) (*gorm.DB, string)

InitMysqlMasterConn returns mysql master db connection.

func InitMysqlTenantConns

func InitMysqlTenantConns(config SQLConfig, master *gorm.DB, tenantAlterDbHostParam, tenantDBPassPhraseKey string) (map[uint64]*gorm.DB, map[uint64]string)

func InitRedisTenantConns

func InitRedisTenantConns(config RedisConfig, masterMySQL *gorm.DB, tenantAlterDbHostParam, tenantDBPassPhraseKey string) map[uint64]*RedisDBConn

Types

type FieldValuePair

type FieldValuePair struct {
	Field string `json:"field"`
	Value string `json:"value"`
}

type KeyFieldPair

type KeyFieldPair struct {
	Key   string `json:"key"`
	Field string `json:"field"`
}

type MemoryConfig

type MemoryConfig struct {
	On        bool
	DelKeyAPI struct {
		EndPoint        string
		AuthBearerToken string
	}
}

type MongoConfig

type MongoConfig struct {
	Master *struct {
		Database string
		Username string
		Password string
		Host     string
		Port     string
	}
	ConnectTimeout        time.Duration
	MaxConnectionPoolSize uint64
	MaxConnectionLifeTime time.Duration
	Debug                 bool
}

type RedisConfig

type RedisConfig struct {
	Master *struct {
		Database int
		Password string
		Host     string
		Port     string
		Reads    []string
	}
	Prefix             string
	Maxretries         int
	PoolSize           int
	MinIdleConnections int
	DialTimeout        time.Duration
	ReadTimeout        time.Duration
	WriteTimeout       time.Duration
	PoolTimeout        time.Duration
}

type RedisDBConn

type RedisDBConn struct {
	Primary redis.UniversalClient
	Reads   map[uint64]redis.UniversalClient
	Name    int
	// contains filtered or unexported fields
}

RedisDBConn IMPORTANT: This structure is holding any kind of redis connection using a map in bean.go.

func InitRedisMasterConn

func InitRedisMasterConn(config RedisConfig) *RedisDBConn

func (*RedisDBConn) DelKey

func (clients *RedisDBConn) DelKey(c context.Context, keys ...string) error

func (*RedisDBConn) ExpireKey

func (clients *RedisDBConn) ExpireKey(c context.Context, key string, ttl time.Duration) error

func (*RedisDBConn) GetLRange

func (clients *RedisDBConn) GetLRange(c context.Context, key string, start, stop int64) (str []string, err error)

func (*RedisDBConn) GetString

func (clients *RedisDBConn) GetString(c context.Context, key string) (str string, err error)

func (*RedisDBConn) HGet

func (clients *RedisDBConn) HGet(c context.Context, key string, field string) (result string, err error)

HGet To get single redis hash key and it's field from redis.

func (*RedisDBConn) HGetAll added in v2.0.7

func (clients *RedisDBConn) HGetAll(c context.Context, key string) (result map[string]string, err error)

HGet To get all fields with their corresponding values in a hash in a single call to redis.

func (*RedisDBConn) HGets

func (clients *RedisDBConn) HGets(c context.Context, redisKeysWithField map[string]string) (map[string]string, error)

HGets To get one field from multiple redis hashes in one call to redis. Input is a map of keys and the respective field for those keys. Output is a map of keys and the respective values for those keys in redis.

func (*RedisDBConn) HMGet added in v2.0.7

func (clients *RedisDBConn) HMGet(c context.Context, key string, fields ...string) (result []interface{}, err error)

func (*RedisDBConn) HSet

func (clients *RedisDBConn) HSet(c context.Context, key string, args ...interface{}) error

- HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"}) - HSet("myhash", []string{"key1", "value1", "key2", "value2"}) - HSet("myhash", "key1", "value1", "key2", "value2")

func (*RedisDBConn) IncrementValue

func (clients *RedisDBConn) IncrementValue(c context.Context, key string) error

func (*RedisDBConn) KeyExists added in v2.0.3

func (clients *RedisDBConn) KeyExists(c context.Context, key string) (bool, error)

func (*RedisDBConn) Keys added in v2.0.7

func (clients *RedisDBConn) Keys(c context.Context, pattern string) (keys []string, err error)

func (*RedisDBConn) MGet

func (clients *RedisDBConn) MGet(c context.Context, keys ...string) (result []interface{}, err error)

MGet This is a replacement of the original `MGet` method by utilizing the `pipeline` approach when Redis is in `cluster` mode.

func (*RedisDBConn) MSet

func (clients *RedisDBConn) MSet(c context.Context, values ...interface{}) (err error)

MSet This is a replacement of the original `MSet` method by utilizing the `pipeline` approach when Redis is in `cluster` mode. it accepts multiple values:

  • RedisMSet("key1", "value1", "key2", "value2")
  • RedisMSet([]string{"key1", "value1", "key2", "value2"})
  • RedisMSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

For `struct` values, please implement the `encoding.BinaryMarshaler` interface.

func (*RedisDBConn) MSetWithTTL

func (clients *RedisDBConn) MSetWithTTL(c context.Context, ttl time.Duration, values ...interface{}) (err error)

MSetWithTTL This method is implemented using `pipeline`. For accepts multiple values, see RedisMSet description.

func (*RedisDBConn) Pipeline added in v2.0.8

func (clients *RedisDBConn) Pipeline() redis.Pipeliner

func (*RedisDBConn) Pipelined added in v2.0.3

func (clients *RedisDBConn) Pipelined(c context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error)

func (*RedisDBConn) RPush

func (clients *RedisDBConn) RPush(c context.Context, key string, valueList []string) error

func (*RedisDBConn) SAdd

func (clients *RedisDBConn) SAdd(c context.Context, key string, elements interface{}) error

func (*RedisDBConn) SIsMember

func (clients *RedisDBConn) SIsMember(c context.Context, key string, element interface{}) (found bool, err error)

func (*RedisDBConn) SMembers

func (clients *RedisDBConn) SMembers(c context.Context, key string) (str []string, err error)

func (*RedisDBConn) SRandMemberN

func (clients *RedisDBConn) SRandMemberN(c context.Context, key string, count int64) (result []string, err error)

func (*RedisDBConn) SRem

func (clients *RedisDBConn) SRem(c context.Context, key string, elements interface{}) error

func (*RedisDBConn) Set

func (clients *RedisDBConn) Set(c context.Context, key string, data interface{}, ttl time.Duration) error

func (*RedisDBConn) SetJSON

func (clients *RedisDBConn) SetJSON(c context.Context, key string, data interface{}, ttl time.Duration) error

func (*RedisDBConn) TTL added in v2.0.7

func (clients *RedisDBConn) TTL(c context.Context, key string) (ttl time.Duration, err error)

type SQLConfig

type SQLConfig struct {
	Master *struct {
		Database string
		Username string
		Password string
		Host     string
		Port     string
	}
	MaxIdleConnections        int
	MaxOpenConnections        int
	MaxConnectionLifeTime     time.Duration
	MaxIdleConnectionLifeTime time.Duration
	Debug                     bool
}

type TenantConnections

type TenantConnections struct {
	ID          uint64         `gorm:"primary_key;AUTO_INCREMENT;column:Id"`
	UUID        string         `gorm:"type:CHAR(36);not null;unique;column:Uuid"`
	TenantID    uint64         `gorm:"not null;column:TenantId"`
	Code        string         `gorm:"type:VARCHAR(20);not null;unique;column:Code"`
	Connections datatypes.JSON `gorm:"not null;column:Connections"`
	CreatedBy   uint64         `gorm:"not null;default:0;column:CreatedBy"`
	UpdatedBy   uint64         `gorm:"not null;default:0;column:UpdatedBy"`
	DeletedBy   uint64         `gorm:"default:NULL;column:DeletedBy"`
	CreatedAt   time.Time      `gorm:"type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;column:CreatedAt"`
	UpdatedAt   time.Time      `gorm:"type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;column:UpdatedAt"`
	DeletedAt   gorm.DeletedAt `gorm:"type:timestamp NULL DEFAULT NULL;column:DeletedAt"`
}

TenantConnections represent a tenant database configuration record in master database

func GetAllTenantCfgs

func GetAllTenantCfgs(db *gorm.DB) []*TenantConnections

GetAllTenantCfgs return all Tenant data from master db.

func (TenantConnections) TableName

func (TenantConnections) TableName() string

Jump to

Keyboard shortcuts

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