cpool

package module
v0.0.0-...-5ebd165 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 7 Imported by: 0

README

A multi tenant connection pool for your lambdas

A simple connection pool for multi tenant lambas using the silo or bridged model. Used correctly this pool will persist between invokations of lambas to reuse the database connections.

The intented use is for those that are stuck with RDS and not able to use RDS Proxy for various reasons.

Usage

import cpool "github.com/alexanderwink/lambda-multi-tenant-connection-pool"

// --- //

db, err := cpool.Pool.GetConnection(databaseName)
Defaults
MaxSize 100 Max total number of connections for the pool
MaxConnectionsPerDatabase 5 Max connections in pool for each database
TTL 300 Connections will be removed from the pool when their TTL has been exceeded

Custom configuration

cpool.Pool.Init(100, 5, 300)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Pool = &ConnectionPool{
		InnerPool:                 []PoolItem{},
		MaxSize:                   100,
		MaxConnectionsPerDatabase: 5,
		TTL:                       300 * time.Second,
	}
)

Functions

This section is empty.

Types

type ConnectionPool

type ConnectionPool struct {
	sync.Mutex
	InnerPool                 []PoolItem
	MaxSize                   int
	MaxConnectionsPerDatabase int
	TTL                       time.Duration
}

func (*ConnectionPool) GetConnection

func (c *ConnectionPool) GetConnection(dbName string) (*sql.DB, error)

func (*ConnectionPool) Init

func (c *ConnectionPool) Init(maxSize int, maxConnectionsPerDatabase int, ttl int)

type PoolItem

type PoolItem struct {
	Connection *sql.DB
	Time       time.Time
	Name       string
}

Jump to

Keyboard shortcuts

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