storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package storage provides a PostgreSQL-based implementation of the Storage interface.

Package storage provides a SQLite-based implementation of the Storage interface.

Package storage defines the Storage interface for user preferences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresStorage

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

PostgresStorage implements the Storage interface using PostgreSQL.

func NewPostgresStorage

func NewPostgresStorage(connString string) (*PostgresStorage, error)

NewPostgresStorage initializes a new PostgresStorage instance. It connects to the PostgreSQL database using the provided connection string and runs migrations.

func (*PostgresStorage) Close

func (s *PostgresStorage) Close() error

Close closes the PostgreSQL database connection.

func (*PostgresStorage) Delete

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

Delete removes a preference by user ID and key. It returns ErrNotFound if the preference does not exist.

func (*PostgresStorage) Get

func (s *PostgresStorage) Get(ctx context.Context, userID, key string) (*userprefs.Preference, error)

Get retrieves a preference by user ID and key. It returns ErrNotFound if the preference does not exist.

func (*PostgresStorage) GetAll

func (s *PostgresStorage) GetAll(ctx context.Context, userID string) (map[string]*userprefs.Preference, error)

GetAll retrieves all preferences for a user.

func (*PostgresStorage) GetByCategory

func (s *PostgresStorage) GetByCategory(ctx context.Context, userID, category string) (map[string]*userprefs.Preference, error)

GetByCategory retrieves all preferences for a user within a specific category.

func (*PostgresStorage) Set

Set stores or updates a preference. It marshals the value to JSON before storing.

type SQLiteStorage

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

SQLiteStorage implements the Storage interface using SQLite.

func NewSQLiteStorage

func NewSQLiteStorage(dbPath string) (*SQLiteStorage, error)

NewSQLiteStorage initializes a new SQLiteStorage instance. It connects to the SQLite database at the specified path and runs migrations.

func (*SQLiteStorage) Close

func (s *SQLiteStorage) Close() error

Close closes the SQLite database connection.

func (*SQLiteStorage) Delete

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

Delete removes a preference by user ID and key. It returns ErrNotFound if the preference does not exist.

func (*SQLiteStorage) Get

func (s *SQLiteStorage) Get(ctx context.Context, userID, key string) (*userprefs.Preference, error)

Get retrieves a preference by user ID and key. It returns ErrNotFound if the preference does not exist.

func (*SQLiteStorage) GetAll

func (s *SQLiteStorage) GetAll(ctx context.Context, userID string) (map[string]*userprefs.Preference, error)

GetAll retrieves all preferences for a user.

func (*SQLiteStorage) GetByCategory

func (s *SQLiteStorage) GetByCategory(ctx context.Context, userID, category string) (map[string]*userprefs.Preference, error)

GetByCategory retrieves all preferences for a user within a specific category.

func (*SQLiteStorage) Set

Set stores or updates a preference. It marshals the value to JSON before storing.

type Storage

type Storage interface {
	Get(ctx context.Context, userID, key string) (*userprefs.Preference, error)
	Set(ctx context.Context, pref *userprefs.Preference) error
	Delete(ctx context.Context, userID, key string) error
	GetAll(ctx context.Context, userID string) (map[string]*userprefs.Preference, error)
	GetByCategory(ctx context.Context, userID, category string) (map[string]*userprefs.Preference, error)
	Close() error
}

Storage defines the methods required for a storage backend.

Jump to

Keyboard shortcuts

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