sql

package
v3.0.0-...-c7bdcb9 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

Provider backend manager

func NewProvider

func NewProvider(cfg ProviderConfig) (*Provider, error)

NewProvider returns a new configured sql provider

func (*Provider) Close

func (p *Provider) Close() error

Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.

It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.

func (*Provider) Count

func (p *Provider) Count() int

Count returns the total of stored sessions

func (*Provider) Destroy

func (p *Provider) Destroy(id []byte) error

Destroy destroys the session from the given id

func (*Provider) Exec

func (p *Provider) Exec(query string, args ...interface{}) (int64, error)

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

Returns the number of rows affected by an update, insert, or delete. Not every database or database driver may support this.

func (*Provider) GC

func (p *Provider) GC() error

GC destroys the expired sessions

func (*Provider) Get

func (p *Provider) Get(id []byte) ([]byte, error)

Get returns the data of the given session id

func (*Provider) NeedGC

func (p *Provider) NeedGC() bool

NeedGC indicates if the GC needs to be run

func (*Provider) Regenerate

func (p *Provider) Regenerate(id, newID []byte, expiration time.Duration) error

Regenerate updates the session id and expiration with the new session id of the the given current session id

func (*Provider) Save

func (p *Provider) Save(id, data []byte, expiration time.Duration) error

Save saves the session data and expiration from the given session id

type ProviderConfig

type ProviderConfig struct {
	// SQL driver
	Driver string

	// DB connection string
	DSN string

	// The maximum number of connections in the idle connection pool.
	//
	// If MaxOpenConns is greater than 0 but less than the new MaxIdleConns,
	// then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
	//
	// If n <= 0, no idle connections are retained.
	//
	// The default max idle connections is currently 2. This may change in
	// a future release.
	MaxIdleConns int

	// The maximum number of open connections to the database.
	//
	// If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
	// MaxIdleConns, then MaxIdleConns will be reduced to match the new
	// MaxOpenConns limit.
	//
	// If n <= 0, then there is no limit on the number of open connections.
	// The default is 0 (unlimited).
	MaxOpenConns int

	// The maximum amount of time a connection may be reused.
	//
	// Expired connections may be closed lazily before reuse.
	//
	// If d <= 0, connections are reused forever.
	ConnMaxLifetime time.Duration

	SQLGet        string
	SQLSave       string
	SQLRegenerate string
	SQLDestroy    string
	SQLCount      string
	SQLInsert     string
	SQLGC         string
}

ProviderConfig provider settings

Jump to

Keyboard shortcuts

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