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 ¶
- type PostgresStorage
- func (s *PostgresStorage) Close() error
- func (s *PostgresStorage) Delete(ctx context.Context, userID, key string) error
- func (s *PostgresStorage) Get(ctx context.Context, userID, key string) (*userprefs.Preference, error)
- func (s *PostgresStorage) GetAll(ctx context.Context, userID string) (map[string]*userprefs.Preference, error)
- func (s *PostgresStorage) GetByCategory(ctx context.Context, userID, category string) (map[string]*userprefs.Preference, error)
- func (s *PostgresStorage) Set(ctx context.Context, pref *userprefs.Preference) error
- type SQLiteStorage
- func (s *SQLiteStorage) Close() error
- func (s *SQLiteStorage) Delete(ctx context.Context, userID, key string) error
- func (s *SQLiteStorage) Get(ctx context.Context, userID, key string) (*userprefs.Preference, error)
- func (s *SQLiteStorage) GetAll(ctx context.Context, userID string) (map[string]*userprefs.Preference, error)
- func (s *SQLiteStorage) GetByCategory(ctx context.Context, userID, category string) (map[string]*userprefs.Preference, error)
- func (s *SQLiteStorage) Set(ctx context.Context, pref *userprefs.Preference) error
- type Storage
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 ¶
func (s *PostgresStorage) Set(ctx context.Context, pref *userprefs.Preference) error
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 ¶
func (s *SQLiteStorage) Set(ctx context.Context, pref *userprefs.Preference) error
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.