Documentation
¶
Overview ¶
Package sqlkv implements kv.Cache on a single table of the SQL database you already run for theauth storage. It works on Postgres, MySQL and SQLite.
Build the full set of shared stores with kv.FromCache(store). Create the table once with EnsureSchema (idempotent) or run Schema(dialect) in your own migration tool.
Index ¶
- Constants
- func Schema(d Dialect, table string) string
- type Dialect
- type Option
- type Store
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) EnsureSchema(ctx context.Context) error
- func (s *Store) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (s *Store) Incr(ctx context.Context, key string, ttl time.Duration) (int64, error)
- func (s *Store) Prune(ctx context.Context) (int64, error)
- func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (s *Store) SetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error)
Constants ¶
const DefaultPrefix = "theauth:"
DefaultPrefix is prepended to every key unless WithPrefix or WithoutPrefix says otherwise. Prune only removes rows under this store's prefix.
const DefaultTable = "theauth_kv"
DefaultTable is the table name used when none is given.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Store)
Option tunes New.
func WithPrefix ¶ added in v2.12.0
WithPrefix sets the prefix prepended to every stored key. WithPrefix("") turns prefixing off and keeps the exact key names the library chose, which is how a deployment keeps the rows it wrote before the default prefix existed.
func WithTable ¶
WithTable overrides the table name. The name is validated as a plain identifier because it is interpolated into SQL.
func WithoutPrefix ¶ added in v2.12.0
func WithoutPrefix() Option
WithoutPrefix disables the prefix. It is shorthand for WithPrefix("").
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements kv.Cache over database/sql.
func New ¶
New returns a Store whose keys carry DefaultPrefix. It does not touch the database; call EnsureSchema.
func (*Store) EnsureSchema ¶
EnsureSchema creates the table and its expiry index when missing.
func (*Store) Prune ¶
Prune deletes expired rows under this store's prefix and returns how many it removed. Rows under other prefixes, including other apps sharing the table, are never touched. Writes call it opportunistically; call it from a timer if the table sees little traffic.