sqlitestore

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: MIT Imports: 9 Imported by: 1

README

sessionup-sqlitestore

CI pipeline codecov Go Report Card GoDoc

SQLite session store implementation for sessionup

Installation

go get github.com/hyzual/sessionup-sqlitestore

Usage

db, err := sql.Open("sqlite3", "...")
if err != nil {
    // handle error
}

store, err := sqlitestore.New(db, "sessions", time.Minute * 5)
if err != nil {
    // handle error
}

manager := sessionup.NewManager(store)

Documentation

Overview

Package sqlitestore implements sessionup.Store interface for SQLite database.

Index

Constants

View Source
const (
	PART_SEPARATOR      = ";"
	KEY_VALUE_SEPARATOR = ":"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SqliteStore

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

SqliteStore is a SQLite implementation of sessionup.Store.

func New

func New(db *sql.DB, tableName string, duration time.Duration) (*SqliteStore, error)

New returns a fresh instance of SqliteStore. tableName parameter determines the name of the table that will be used for sessions. If it does not exist, it will be created. Duration parameter determines how often the cleanup function wil be called to remove the expired sessions. Setting it to 0 will prevent cleanup from being activated.

func (*SqliteStore) CleanupErr

func (store *SqliteStore) CleanupErr() <-chan error

CleanupErr returns a receive-only channel to get errors produced during the automatic cleanup. NOTE: channel must be drained in order for the cleanup process to be able to continue.

func (*SqliteStore) Create

func (store *SqliteStore) Create(ctx context.Context, session sessionup.Session) error

Create implements sessionup.Store interface's Create method.

func (*SqliteStore) DeleteByID

func (store *SqliteStore) DeleteByID(ctx context.Context, id string) error

DeleteByID implements sessionup.Store interface's DeleteByID method.

func (*SqliteStore) DeleteByUserKey

func (store *SqliteStore) DeleteByUserKey(ctx context.Context, key string, sessionIDsToKeep ...string) error

DeleteByUserKey implements sessionup.Store interface's DeleteByUserKey method.

func (*SqliteStore) FetchByID

func (store *SqliteStore) FetchByID(ctx context.Context, id string) (sessionup.Session, bool, error)

FetchByID implements sessionup.Store interface's FetchByID method.

func (*SqliteStore) FetchByUserKey

func (store *SqliteStore) FetchByUserKey(ctx context.Context, key string) ([]sessionup.Session, error)

FetchByUserKey implements sessionup.Store interface's FetchByUserKey method.

func (*SqliteStore) StopCleanup

func (store *SqliteStore) StopCleanup()

StopCleanup terminates the automatic cleanup process. Useful for testing and cases when store is used only temporarily. In order to restart the cleanup, a new store must be created.

Jump to

Keyboard shortcuts

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