dbpool

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: MIT Imports: 7 Imported by: 0

README

ngr-dbpool

import "github.com/NGRsoftlab/ngr-dbpool"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConnectionByParams

func GetConnectionByParams(Ctx context.Context, connCache *SafeDbMapCache,
	duration time.Duration, driver, connString string) (*sqlx.DB, error)

GetConnectionByParams - get *sqlx.DB from cache (if exists) or create new and put into cache

Types

type PoolItem

type PoolItem struct {
	Expiration int64
	Duration   time.Duration
	Created    time.Time

	Db *sqlx.DB
}

type SafeDbMapCache

type SafeDbMapCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(defaultExpiration, cleanupInterval time.Duration) *SafeDbMapCache

New - initializing a new SafeDbMapCache cache

func (*SafeDbMapCache) ClearAll

func (c *SafeDbMapCache) ClearAll()

ClearAll - removes all items.

func (*SafeDbMapCache) Delete

func (c *SafeDbMapCache) Delete(key string) error

Delete - delete *sqlx.DB value by key Return false if key not found

func (*SafeDbMapCache) ExpiredKeys

func (c *SafeDbMapCache) ExpiredKeys() (keys []string)

ExpiredKeys - returns list of expired keys.

func (*SafeDbMapCache) GC

func (c *SafeDbMapCache) GC()

GC - Garbage Collection cycle

func (*SafeDbMapCache) Get

func (c *SafeDbMapCache) Get(key string) (*sqlx.DB, bool)

Get - getting *sqlx.DB value by key

func (*SafeDbMapCache) GetItems

func (c *SafeDbMapCache) GetItems() (items []string)

GetItems - returns item list.

func (*SafeDbMapCache) Set

func (c *SafeDbMapCache) Set(key string, value *sqlx.DB, duration time.Duration)

Set - setting *sqlx.DB value by key

func (*SafeDbMapCache) StartGC

func (c *SafeDbMapCache) StartGC()

StartGC - start Garbage Collection

Jump to

Keyboard shortcuts

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