Categorygithub.com/jstemmer/sqlstore
modulepackage
0.0.0-20210912091201-4b7df273a27a
Repository: https://github.com/jstemmer/sqlstore.git
Documentation: pkg.go.dev

# README

sqlstore

SQL session store for the Gorilla web toolkit.

Work in progress, API may not be stable. Currently only supports the PostgreSQL dialect for either the stdlib database/sql package or the pgx driver.

GoDoc

Build Status

Usage

See the Gorilla toolkit sessions documentation on how to use the sessions package.

Get the package go get github.com/jstemmer/sqlstore and import github.com/jstemmer/sqlstore. Depending on which database implementation you want to use either import github.com/jstemmer/sqlstore/pgdb or github.com/jstemmer/sqlstore/pgxdb.

Call sqlstore.New() to create a new store and provide it with a database implementation and keyPairs. See the session.NewCookieStore documentation on how to use the keyPairs parameter.

For example:

store := sqlstore.New(pgdb.New(db), []byte("something-very-secret"))

Sessions are stored in a sessions table, which is assumed to exist. It should have the following schema:

CREATE TABLE sessions (
	id varchar(100) PRIMARY KEY,
	data bytea NOT NULL,
	created_at timestamp NOT NULL,
	updated_at timestamp NOT NULL
);

License

MIT, see LICENSE.

# Packages

Package pgdb provides a sqlstore.Database implementation for a PostgreSQL database accessed through the standard library database/sql package.
Package pgxdb provides a sqlstore.Database implementation for a PostgreSQL database accessed through the github.com/jackc/pgx package.

# Functions

New returns a new SQLStore.

# Structs

SQLStore stores gorilla sessions in a database.

# Interfaces

Database describes a session store database interface.