dbdrivers

package
v1.1.33 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadgerGetBytes added in v1.1.30

func BadgerGetBytes(client *badger.DB, key string) ([]byte, error)

BadgerGetBytes returns a byte val of associated key.

func BadgerGetJson added in v1.1.30

func BadgerGetJson(client *badger.DB, key string) (map[string]interface{}, error)

BadgerGetJson returns a json representation of associated key.

func BadgerGetString added in v1.1.30

func BadgerGetString(client *badger.DB, key string) (string, error)

BadgerGetString returns a string val of associated key.

func BadgerSetBytes added in v1.1.30

func BadgerSetBytes(client *badger.DB, key string, val []byte, ttl time.Duration) error

BadgerSetBytes saves a string key and it's value in bytes into badgerdb. If you supply `ttl` greater than 0 then badger will save the key into the db for that many seconds. Once the TTL has elapsed, the key will no longer be retrievable and will be eligible for garbage collection. Pass `ttl` as 0 if you want to keep the key forever into the db until the server restarted or crashed.

func BadgerSetString added in v1.1.30

func BadgerSetString(client *badger.DB, key string, val string, ttl time.Duration) error

BadgerSetString saves a string key value pair to badgerdb. If you supply `ttl` greater than 0 then badger will save the key into the db for that many seconds. Once the TTL has elapsed, the key will no longer be retrievable and will be eligible for garbage collection. Pass `ttl` as 0 if you want to keep the key forever into the db until the server restarted or crashed.

func GetRedisCachePrefix

func GetRedisCachePrefix() string

func InitBadgerConn

func InitBadgerConn(config BadgerConfig) *badger.DB

Initialize the Badger database.

func InitMongoMasterConn

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

func InitMongoTenantConns

func InitMongoTenantConns(config MongoConfig, master *gorm.DB, tenantAlterDbHostParam, tenantDBPassPhraseKey string) (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 InitRedisMasterConn

func InitRedisMasterConn(config RedisConfig) map[uint64]*RedisDBConn

func InitRedisTenantConns

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

func RedisDelKey added in v1.1.17

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

func RedisExpireKey added in v1.1.28

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

func RedisGetLRange added in v1.1.17

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

func RedisGetString added in v1.1.17

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

func RedisHGet added in v1.1.28

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

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

func RedisHSet added in v1.1.28

func RedisHSet(c context.Context, clients *RedisDBConn, key string, field string, data interface{}) error

func RedisHgets added in v1.1.33

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

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 RedisIncrementValue added in v1.1.17

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

func RedisMGet added in v1.1.17

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

func RedisRPush added in v1.1.17

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

func RedisSAdd added in v1.1.17

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

func RedisSIsMember added in v1.1.17

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

func RedisSMembers added in v1.1.17

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

func RedisSRem added in v1.1.17

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

func RedisSet added in v1.1.17

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

func RedisSetJSON added in v1.1.17

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

Types

type BadgerConfig

type BadgerConfig struct {
	Path     string
	InMemory bool
}

type FieldValuePair added in v1.1.33

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

type KeyFieldPair added in v1.1.33

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

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
}

type RedisConfig

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

type RedisDBConn added in v1.1.17

type RedisDBConn struct {
	Host *redis.Client
	Read map[uint64]*redis.Client
	Name int
}

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

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