database

package
v0.0.0-...-84048cf Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContactStore

func NewContactStore(db *DB, logger logging.Logger) contact.Store

NewContactStore creates a new contact store

func NewSubscriptionStore

func NewSubscriptionStore(db *sqlx.DB, logger logging.Logger) subscription.Store

NewSubscriptionStore creates a new subscription store

Types

type Config

type Config struct {
	Host     string
	Port     string
	Name     string
	User     string
	Password string
	SSLMode  string
}

Config holds database configuration

func NewConfig

func NewConfig(logger logging.Logger) *Config

NewConfig creates database configuration from environment variables

func (*Config) DSN

func (c *Config) DSN() string

DSN returns the database connection string

type ContactStore

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

ContactStore implements contact.Store

func (*ContactStore) Create

func (s *ContactStore) Create(ctx context.Context, sub *contact.Submission) error

Create creates a new contact submission

func (*ContactStore) Get

Get returns a contact submission by ID

func (*ContactStore) List

func (s *ContactStore) List(ctx context.Context) ([]contact.Submission, error)

List returns all contact submissions

func (*ContactStore) UpdateStatus

func (s *ContactStore) UpdateStatus(ctx context.Context, id int64, status contact.Status) error

UpdateStatus updates the status of a contact submission

type DB

type DB struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

DB wraps sqlx.DB with lifecycle management

func NewDB

func NewDB(lc fx.Lifecycle, cfg *config.Config, logger logging.Logger) (*DB, error)

NewDB creates a new database connection with proper configuration

func (*DB) PingContext

func (db *DB) PingContext(c echo.Context) error

PingContext implements the PingContexter interface for Echo

func (*DB) WithTx

func (db *DB) WithTx(ctx context.Context, fn func(*sqlx.Tx) error) error

WithTx executes a function within a transaction

type SubscriptionStore

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

SubscriptionStore implements subscription.Store

func (*SubscriptionStore) Create

Create creates a new subscription

func (*SubscriptionStore) Delete

func (s *SubscriptionStore) Delete(ctx context.Context, id int64) error

Delete removes a subscription

func (*SubscriptionStore) Get

Get implements subscription.Store

func (*SubscriptionStore) GetByEmail

func (s *SubscriptionStore) GetByEmail(ctx context.Context, email string) (*subscription.Subscription, error)

GetByEmail returns a subscription by email

func (*SubscriptionStore) GetByID

GetByID implements subscription.Store

func (*SubscriptionStore) List

List returns all subscriptions

func (*SubscriptionStore) UpdateStatus

func (s *SubscriptionStore) UpdateStatus(ctx context.Context, id int64, status subscription.Status) error

UpdateStatus updates the status of a subscription

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳