database

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CUSTOM caching on local memory
	CUSTOM = iota
	// BIGCACHE database
	BIGCACHE
	// REDIS database
	REDIS
)
View Source
const (
	// SQL database
	SQL = iota
	// NOSQL database
	NOSQL
	// CACHING databse
	CACHING
)
View Source
const (
	// MONGODB database
	MONGODB = iota
)
View Source
const (
	// SQLLike database (common relational database)
	SQLLike = iota
)

Variables

This section is empty.

Functions

func New

func New(databaseType int) func(databaseCompany int, config *Config) interface{}

New database with abstract factory pattern

func NewCaching

func NewCaching(databaseCompany int, config *Config) interface{}

NewCaching factory pattern

func NewNoSQL

func NewNoSQL(
	databaseCompany int,
	config *Config) interface{}

NewNoSQL factory pattern

func NewSQL

func NewSQL(
	databaseCompany int,
	config *Config) interface{}

NewSQL factory pattern

Types

type BigCacheClient

type BigCacheClient struct {
	Client *bigcache.BigCache
}

BigCacheClient manage all BigCache actions

func (*BigCacheClient) Append

func (bc *BigCacheClient) Append(key string, value interface{}) error

Append new value base on the key provide, With Append() you can concatenate multiple entries under the same key in an lock optimized way.

func (*BigCacheClient) Close

func (bc *BigCacheClient) Close() error

Close function will close BigCache connection

func (*BigCacheClient) Delete

func (bc *BigCacheClient) Delete(key string) error

Delete function will delete value based on the key provided

func (*BigCacheClient) Get

func (bc *BigCacheClient) Get(key string) (interface{}, error)

Get return value based on the key provided

func (*BigCacheClient) GetCapacity

func (bc *BigCacheClient) GetCapacity() (interface{}, error)

GetCapacity method return redis database size

func (*BigCacheClient) GetNumberOfRecords

func (bc *BigCacheClient) GetNumberOfRecords() int

GetNumberOfRecords return number of records

func (*BigCacheClient) Middleware

func (bc *BigCacheClient) Middleware(hash hash.IHash) echo.MiddlewareFunc

Middleware for echo framework

func (*BigCacheClient) Set

func (bc *BigCacheClient) Set(key string, value interface{}, expire time.Duration) error

Set new record set key and value

func (*BigCacheClient) Update

func (bc *BigCacheClient) Update(key string, value interface{}, expire time.Duration) error

Update new value over the key provided

type ComparisonOperators

type ComparisonOperators string

ComparisonOperators mongodb comparition operation type

const (
	Equal                ComparisonOperators = "$eq"
	EqualAny             ComparisonOperators = "$in"
	NotEqual             ComparisonOperators = "$ne"
	NotEqualAnyLL        ComparisonOperators = "$nin"
	GreaterThan          ComparisonOperators = "$gt"
	GreaterThanOrEqualTo ComparisonOperators = "$gte"
	LessThan             ComparisonOperators = "$lt"
	LessThanOrEqualTo    ComparisonOperators = "$lte"
)

This is for mongodb comparition operation constant

type Config

type Config struct {
	LIKE        LIKE            `json:"like"`
	MongoDB     MongoDB         `json:"mongodb"`
	Redis       Redis           `json:"redis,omitempty"`
	CustomCache CustomCache     `json:"customCache,omitempty"`
	BigCache    bigcache.Config `json:"bigCache,omitempty"`
}

Config model for database config

type CustomCache

type CustomCache struct {
	CacheSize        int64         `json:"cacheSize,omitempty"` // byte
	CleaningEnable   bool          `json:"cleaningEnable,omitempty"`
	CleaningInterval time.Duration `json:"cleaningInterval,omitempty"` // nanosecond
}

CustomCache config model

type CustomClient

type CustomClient struct {
	// contains filtered or unexported fields
}

CustomClient manage all custom caching actions

func (*CustomClient) Close

func (cl *CustomClient) Close() error

Close closes the cache and frees up resources.

func (*CustomClient) Delete

func (cl *CustomClient) Delete(key string) error

Delete deletes the key and its value from the cache.

func (*CustomClient) Get

func (cl *CustomClient) Get(key string) (interface{}, error)

Get return value based on the key provided

func (*CustomClient) GetCapacity

func (cl *CustomClient) GetCapacity() (interface{}, error)

GetCapacity method return redis database size

func (*CustomClient) GetMany

func (cl *CustomClient) GetMany(keys []string) (map[string]interface{}, []string, error)

GetMany return value based on the list of keys provided

func (*CustomClient) GetNumberOfRecords

func (cl *CustomClient) GetNumberOfRecords() int

GetNumberOfRecords return number of records

func (*CustomClient) Middleware

func (cl *CustomClient) Middleware(hash hash.IHash) echo.MiddlewareFunc

Middleware for echo framework

func (*CustomClient) Range

func (cl *CustomClient) Range(f func(key, value interface{}) bool)

Range over linear data structure

func (*CustomClient) Set

func (cl *CustomClient) Set(key string, value interface{}, expire time.Duration) error

Set new record set key and value

func (*CustomClient) Update

func (cl *CustomClient) Update(key string, value interface{}, expire time.Duration) error

Update new value over the key provided

type ICaching

type ICaching interface {
	Middleware(hash hash.IHash) echo.MiddlewareFunc
	Get(key string) (interface{}, error)
	Set(key string, value interface{}, expire time.Duration) error
	Update(key string, value interface{}, expire time.Duration) error
	Delete(key string) error
	GetNumberOfRecords() int
	GetCapacity() (interface{}, error)
	Close() error
}

ICaching caching factory pattern interface

func NewBigCache

func NewBigCache(config *Config) ICaching

NewBigCache init new instance

func NewCustom

func NewCustom(config *Config) ICaching

NewCustom init new instance

func NewRedis

func NewRedis(config *Config) ICaching

NewRedis init new instance

type INoSQL

type INoSQL interface {
	GetALL(
		databaseName,
		collectionName,
		lastID,
		pageSize string,
		dataModel reflect.Type) (results interface{}, err error)

	GetByField(
		databaseName,
		collectionName,
		field,
		value string,
		dataModel reflect.Type) (interface{}, error)

	Create(
		databaseName,
		collectionName string,
		dataModel interface{}) (result interface{}, err error)

	Update(
		databaseName,
		collectionName,
		ID string,
		dataModel interface{}) (result interface{}, err error)

	Delete(
		databaseName,
		collectionName,
		ID string) (result interface{}, err error)

	MatchAndLookup(
		databaseName,
		collectionName string,
		model MatchLookup,
		dataModel reflect.Type) (results interface{}, err error)
}

INoSQL factory pattern interface

func NewMongoDB

func NewMongoDB(config *MongoDB) INoSQL

NewMongoDB init new instance

type ISQL

type ISQL interface {
	Execute(
		query string,
		dataModel interface{}) (interface{}, error)
}

ISQL factory pattern interface

type LIKE

type LIKE struct {
	DriverName            string        `json:"driverName"`
	DataSourceName        string        `json:"dataSourceName"`
	MaxConnectionLifetime time.Duration `json:"maxConnectionLifetime"`
	MaxConnectionIdle     int           `json:"maxConnectionIdle"`
	MaxConnectionOpen     int           `json:"maxConnectionOpen"`
}

LIKE model for SQL-LIKE connection config

type Lookup

type Lookup struct {
	From         string `json:"From"`
	LocalField   string `json:"localField"`
	ForeignField string `json:"foreignField"`
	As           string `json:"as"`
}

Lookup mongo model

type Match

type Match struct {
	Field    string              `json:"field"`
	Operator ComparisonOperators `json:"operator"`
	Value    string              `json:"value"`
}

Match mongo model

type MatchLookup

type MatchLookup struct {
	Match  []Match  `json:"match"`
	Lookup []Lookup `json:"lookup"`
}

MatchLookup mongo model

type MongoClient

type MongoClient struct {
	Client *mongo.Client
	Config *MongoDB
}

MongoClient manage all mongodb actions

func (*MongoClient) Create

func (m *MongoClient) Create(
	databaseName,
	collectionName string,
	dataModel interface{}) (result interface{}, err error)

Create new record base on model

func (*MongoClient) Delete

func (m *MongoClient) Delete(
	databaseName,
	collectionName,
	ID string) (result interface{}, err error)

Delete record base on _id

func (*MongoClient) GetALL

func (m *MongoClient) GetALL(
	databaseName,
	collectionName,
	lastID,
	pageSize string,
	dataModel reflect.Type) (results interface{}, err error)

GetALL from collection with pagination

func (*MongoClient) GetByField

func (m *MongoClient) GetByField(
	databaseName,
	collectionName,
	field,
	value string,
	dataModel reflect.Type) (result interface{}, err error)

GetByField base on field and value

func (*MongoClient) MatchAndLookup

func (m *MongoClient) MatchAndLookup(
	databaseName,
	collectionName string,
	model MatchLookup,
	dataModel reflect.Type) (results interface{}, err error)

MatchAndLookup ...

func (*MongoClient) Update

func (m *MongoClient) Update(
	databaseName,
	collectionName,
	ID string,
	dataModel interface{}) (result interface{}, err error)

Update record with new value base on _id and model

type MongoDB

type MongoDB struct {
	User     string   `json:"user"`
	Password string   `json:"password"`
	Hosts    []string `json:"hosts"`
	DB       string   `json:"db"`
	Options  []string `json:"options"`
}

MongoDB model for MongoDB connection config

type Redis

type Redis struct {
	Password   string `json:"password,omitempty"`
	Host       string `json:"host,omitempty"`
	DB         int    `json:"db,omitempty"`
	MaxRetries int    `json:"maxRetries,omitempty"`
}

Redis model for redis config

type RedisClient

type RedisClient struct {
	Client *redis.Client
}

RedisClient manage all redis actions

func (*RedisClient) Append

func (r *RedisClient) Append(key string, value interface{}) error

Append new value over the key provided

func (*RedisClient) Close

func (r *RedisClient) Close() error

Close method will close redis connection

func (*RedisClient) Delete

func (r *RedisClient) Delete(key string) error

Delete method delete value based on the key provided

func (*RedisClient) Get

func (r *RedisClient) Get(key string) (interface{}, error)

Get return value based on the key provided

func (*RedisClient) GetCapacity

func (r *RedisClient) GetCapacity() (interface{}, error)

GetCapacity method return redis database size

func (*RedisClient) GetNumberOfRecords

func (r *RedisClient) GetNumberOfRecords() int

GetNumberOfRecords return number of records

func (*RedisClient) Middleware

func (r *RedisClient) Middleware(hash hash.IHash) echo.MiddlewareFunc

Middleware for echo framework

func (*RedisClient) Set

func (r *RedisClient) Set(key string, value interface{}, expire time.Duration) error

Set new record set key and value

func (*RedisClient) Update

func (r *RedisClient) Update(key string, value interface{}, expire time.Duration) error

Update new value over the key provided

type SQLLikeClient

type SQLLikeClient struct {
	Client *sql.DB
	Config *LIKE
}

SQLLikeClient manage all SQL-Like actions

func NewSQLLike

func NewSQLLike(config *LIKE) *SQLLikeClient

NewSQLLike init new instance The sql package must be used in conjunction with a database driver. See https://golang.org/s/sqldrivers for a list of driverNames.

func (*SQLLikeClient) Execute

func (c *SQLLikeClient) Execute(
	query string,
	dataModel interface{}) (interface{}, error)

Execute return results based on 'query' and 'dataModel'

type Set

type Set struct {
	Operator UpdateOperators `json:"operator"`
	Data     interface{}     `json:"data"`
}

Set mongo model

type UpdateOperators

type UpdateOperators string

UpdateOperators mongodb update operation type

const (
	Replaces UpdateOperators = "$set"
)

This is for mongodb update operation constant

Jump to

Keyboard shortcuts

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