sql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sql provides a SQL-based storage backend for gopotency. It supports any database compatible with database/sql, such as PostgreSQL, MySQL, or SQLite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage is a SQL implementation of idempotency.Storage

func NewSQLStorage

func NewSQLStorage(db *sql.DB, tableName string) *Storage

NewSQLStorage creates a new SQL storage instance. This implementation is optimized for PostgreSQL and SQLite as it uses positional placeholders ($1, $2) and "ON CONFLICT" syntax.

func (*Storage) Close

func (s *Storage) Close() error

Close closes the database connection

func (*Storage) Delete

func (s *Storage) Delete(ctx context.Context, key string) error

Delete removes an idempotency record

func (*Storage) Exists

func (s *Storage) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a record exists

func (*Storage) Get

func (s *Storage) Get(ctx context.Context, key string) (*idempotency.Record, error)

Get retrieves an idempotency record by key

func (*Storage) Set

func (s *Storage) Set(ctx context.Context, record *idempotency.Record, ttl time.Duration) error

Set stores an idempotency record

func (*Storage) TryLock

func (s *Storage) TryLock(ctx context.Context, key string, ttl time.Duration) (bool, error)

TryLock attempts to acquire a lock for the given key. Note: This is a simplified implementation using a locks table. For PostgreSQL, dedicated advisory locks might be better.

func (*Storage) Unlock

func (s *Storage) Unlock(ctx context.Context, key string) error

Unlock releases a lock

Jump to

Keyboard shortcuts

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