postgres

package
v0.0.0-...-ef789dd Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: GPL-3.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetRepo

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

AssetRepo implements media.AssetRepository using PostgreSQL.

func NewAssetRepo

func NewAssetRepo(db *sql.DB) (*AssetRepo, error)

NewAssetRepo returns a new AssetRepo backed by db.

func (*AssetRepo) Delete

func (r *AssetRepo) Delete(ctx context.Context, id string) error

Delete removes an asset record by ID.

func (*AssetRepo) FindByID

func (r *AssetRepo) FindByID(ctx context.Context, id string) (*media.Asset, error)

FindByID returns an asset by its ID. Returns (nil, nil) when the asset does not exist.

func (*AssetRepo) List

func (r *AssetRepo) List(ctx context.Context, offset, limit int) ([]media.Asset, error)

List returns a page of assets ordered by created_at desc.

func (*AssetRepo) Save

func (r *AssetRepo) Save(ctx context.Context, a *media.Asset) error

Save persists a new asset.

type AuditLogRepo

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

AuditLogRepo implements domainadmin.AuditLogRepository.

func NewAuditLogRepo

func NewAuditLogRepo(db *sql.DB) (*AuditLogRepo, error)

NewAuditLogRepo returns an AuditLogRepo backed by db.

func (*AuditLogRepo) DeleteBefore

func (r *AuditLogRepo) DeleteBefore(ctx context.Context, cutoff time.Time) (int64, error)

func (*AuditLogRepo) Insert

func (*AuditLogRepo) List

type CacheStore

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

CacheStore implements cache.Cache using a PostgreSQL UNLOGGED table.

func NewCacheStore

func NewCacheStore(db *sql.DB) (*CacheStore, error)

NewCacheStore returns a CacheStore backed by db.

func (*CacheStore) CompareAndSubtract

func (s *CacheStore) CompareAndSubtract(key string, expected int64) (int64, error)

CompareAndSubtract subtracts expected from the counter when current >= expected. Uses a single transaction with SELECT … FOR UPDATE on key so the locked row is the one deleted/updated (no ctid matching). When current < expected, returns the unchanged current count.

func (*CacheStore) Delete

func (s *CacheStore) Delete(key string) error

Delete removes the entry for key. A missing key is not an error.

func (*CacheStore) DeleteByPrefix

func (s *CacheStore) DeleteByPrefix(ctx context.Context, prefix string) error

DeleteByPrefix removes all entries whose key starts with prefix. LIKE metacharacters (%, _, \) in prefix are escaped so only true prefix matches are deleted.

func (*CacheStore) DeleteExpired

func (s *CacheStore) DeleteExpired(ctx context.Context) (int64, error)

DeleteExpired removes all entries whose TTL has elapsed. Called by the cache cleanup scheduled job.

func (*CacheStore) Get

func (s *CacheStore) Get(key string, dest any) (bool, error)

Get retrieves the cached value for key and unmarshals it into dest. Returns (true, nil) on hit, (false, nil) on miss.

func (*CacheStore) Incr

func (s *CacheStore) Incr(key string, delta int64, ttl time.Duration) (int64, error)

Incr atomically increments a JSON-number counter and refreshes TTL.

func (*CacheStore) Set

func (s *CacheStore) Set(key string, value any, ttl time.Duration) error

Set stores value under key with the given TTL. A zero TTL means the entry never expires automatically.

type CartRepo

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

CartRepo implements cart.CartRepository using PostgreSQL.

func NewCartRepo

func NewCartRepo(db *sql.DB) (*CartRepo, error)

NewCartRepo returns a new CartRepo backed by db.

func (*CartRepo) Delete

func (r *CartRepo) Delete(ctx context.Context, id string) error

Delete removes a cart and its items by ID (CASCADE handles items).

func (*CartRepo) FindActiveByCustomerID

func (r *CartRepo) FindActiveByCustomerID(ctx context.Context, customerID string) (*cart.Cart, error)

FindActiveByCustomerID returns the active cart for a customer. Returns (nil, nil) when not found. Uses a REPEATABLE READ read-only transaction for a consistent snapshot.

func (*CartRepo) FindByID

func (r *CartRepo) FindByID(ctx context.Context, id string) (*cart.Cart, error)

FindByID returns a cart with its items by ID. Returns (nil, nil) when not found. Uses a REPEATABLE READ read-only transaction for a consistent snapshot.

func (*CartRepo) FindRecoveryCandidates

func (r *CartRepo) FindRecoveryCandidates(ctx context.Context, staleBefore time.Time, limit int) ([]*cart.Cart, error)

FindRecoveryCandidates returns active customer carts with items that are stale and unemailed.

func (*CartRepo) MarkRecoveryEmailSent

func (r *CartRepo) MarkRecoveryEmailSent(ctx context.Context, cartID string, sentAt time.Time) (bool, error)

MarkRecoveryEmailSent records a recovery email send when not already recorded.

func (*CartRepo) Save

func (r *CartRepo) Save(ctx context.Context, c *cart.Cart) error

Save persists a cart and its items (upsert). Uses a transaction to ensure the cart header and items are written atomically. Optimistic locking: on update the version must match the value loaded by FindByID. If another writer incremented it first, Save returns a conflict error.

type CategoryRepo

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

CategoryRepo implements catalog.CategoryRepository using PostgreSQL.

func NewCategoryRepo

func NewCategoryRepo(db *sql.DB) (*CategoryRepo, error)

NewCategoryRepo returns a new CategoryRepo backed by db.

func (*CategoryRepo) Create

func (r *CategoryRepo) Create(ctx context.Context, c *catalog.Category) error

Create persists a new category.

func (*CategoryRepo) Delete

func (r *CategoryRepo) Delete(ctx context.Context, id string) error

Delete removes a category by ID.

func (*CategoryRepo) FindAll

func (r *CategoryRepo) FindAll(ctx context.Context) ([]catalog.Category, error)

FindAll returns all categories ordered by position asc, then name asc.

func (*CategoryRepo) FindByID

func (r *CategoryRepo) FindByID(ctx context.Context, id string) (*catalog.Category, error)

FindByID returns a category by its ID. Returns (nil, nil) when not found.

func (*CategoryRepo) FindByParentID

func (r *CategoryRepo) FindByParentID(ctx context.Context, parentID *string) ([]catalog.Category, error)

FindByParentID returns child categories of the given parent, ordered by position asc, then name asc. Pass nil parentID to get root categories.

func (*CategoryRepo) FindBySlug

func (r *CategoryRepo) FindBySlug(ctx context.Context, slug string) (*catalog.Category, error)

FindBySlug returns a category by its slug. Returns (nil, nil) when not found.

func (*CategoryRepo) Update

func (r *CategoryRepo) Update(ctx context.Context, c *catalog.Category) error

Update persists changes to an existing category.

type CollectionRepo

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

CollectionRepo implements catalog.CollectionRepository using PostgreSQL.

func NewCollectionRepo

func NewCollectionRepo(db *sql.DB) (*CollectionRepo, error)

NewCollectionRepo returns a new CollectionRepo backed by db.

func (*CollectionRepo) AddProduct

func (r *CollectionRepo) AddProduct(ctx context.Context, collectionID, productID string) error

AddProduct assigns a product to a manual collection.

func (*CollectionRepo) Create

Create persists a new collection.

func (*CollectionRepo) FindByID

func (r *CollectionRepo) FindByID(ctx context.Context, id string) (*catalog.Collection, error)

FindByID returns a collection by its ID. Returns (nil, nil) when not found.

func (*CollectionRepo) FindBySlug

func (r *CollectionRepo) FindBySlug(ctx context.Context, slug string) (*catalog.Collection, error)

FindBySlug returns a collection by its slug. Returns (nil, nil) when not found.

func (*CollectionRepo) List

List returns all collections ordered by name asc.

func (*CollectionRepo) ListProductIDs

func (r *CollectionRepo) ListProductIDs(ctx context.Context, collectionID string) ([]string, error)

ListProductIDs returns the product IDs assigned to a manual collection, ordered by product_id asc.

func (*CollectionRepo) RemoveProduct

func (r *CollectionRepo) RemoveProduct(ctx context.Context, collectionID, productID string) error

RemoveProduct removes a product from a manual collection.

func (*CollectionRepo) Update

Update persists changes to an existing collection.

type ConfigRepo

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

ConfigRepo implements config.Repository using PostgreSQL.

func NewConfigRepo

func NewConfigRepo(db configDB) *ConfigRepo

NewConfigRepo returns a ConfigRepo backed by db. db may be a *sql.DB or *sql.Tx; pass a Tx to run operations inside an existing transaction (e.g. bulk import).

func (*ConfigRepo) All

func (r *ConfigRepo) All(ctx context.Context) ([]domainCfg.Entry, error)

All returns every stored config entry.

func (*ConfigRepo) Delete

func (r *ConfigRepo) Delete(ctx context.Context, key string) error

Delete removes the entry for key. A missing key is not an error.

func (*ConfigRepo) Get

func (r *ConfigRepo) Get(ctx context.Context, key string) (interface{}, error)

Get retrieves the value for key. Returns (nil, nil) on miss.

func (*ConfigRepo) Set

func (r *ConfigRepo) Set(ctx context.Context, key string, value interface{}) error

Set stores value under key (upsert). Value must not be nil.

func (*ConfigRepo) SetMany

func (r *ConfigRepo) SetMany(ctx context.Context, entries map[string]interface{}) error

SetMany stores multiple config entries atomically.

type ConsentRepo

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

ConsentRepo implements legal.ConsentRepository using PostgreSQL.

func NewConsentRepo

func NewConsentRepo(db *sql.DB) (*ConsentRepo, error)

NewConsentRepo returns a new ConsentRepo backed by db.

func (*ConsentRepo) DeleteByCustomerID

func (r *ConsentRepo) DeleteByCustomerID(ctx context.Context, customerID string) error

DeleteByCustomerID removes the consent record for a customer.

func (*ConsentRepo) FindByCustomerID

func (r *ConsentRepo) FindByCustomerID(ctx context.Context, customerID string) (*legal.Consent, error)

FindByCustomerID returns the consent for a customer. Returns (nil, nil) when not found.

func (*ConsentRepo) Upsert

func (r *ConsentRepo) Upsert(ctx context.Context, c *legal.Consent) error

Upsert creates or updates a consent record.

func (*ConsentRepo) WithTx

func (r *ConsentRepo) WithTx(tx *sql.Tx) legal.ConsentRepository

WithTx returns a repo bound to the given transaction.

type ContentBlockRepo

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

ContentBlockRepo implements cms.ContentBlockRepository using PostgreSQL.

func NewContentBlockRepo

func NewContentBlockRepo(db *sql.DB) (*ContentBlockRepo, error)

NewContentBlockRepo returns a new ContentBlockRepo backed by db.

func (*ContentBlockRepo) Create

func (r *ContentBlockRepo) Create(ctx context.Context, block *cms.ContentBlock) error

Create persists a new content block.

func (*ContentBlockRepo) Delete

func (r *ContentBlockRepo) Delete(ctx context.Context, blockID string) error

Delete removes a content block by ID.

func (*ContentBlockRepo) FindActiveBlocksByTarget

func (r *ContentBlockRepo) FindActiveBlocksByTarget(ctx context.Context, targetType cms.TargetType, targetKey string) ([]*cms.ContentBlock, error)

FindActiveBlocksByTarget returns active placed blocks for storefront and public APIs.

func (*ContentBlockRepo) FindBlocksByTarget

func (r *ContentBlockRepo) FindBlocksByTarget(ctx context.Context, targetType cms.TargetType, targetKey string) ([]*cms.ContentBlock, error)

FindBlocksByTarget returns placed blocks for admin views, including inactive blocks.

func (*ContentBlockRepo) FindByID

func (r *ContentBlockRepo) FindByID(ctx context.Context, blockID string) (*cms.ContentBlock, error)

FindByID returns a block by ID.

func (*ContentBlockRepo) List

func (r *ContentBlockRepo) List(ctx context.Context, offset, limit int) ([]*cms.ContentBlock, error)

List returns content blocks ordered by title.

func (*ContentBlockRepo) SaveTargetPlacements

func (r *ContentBlockRepo) SaveTargetPlacements(ctx context.Context, targetType cms.TargetType, targetKey string, blockIDs []string) error

SaveTargetPlacements replaces all placements for a target with the given block IDs.

func (*ContentBlockRepo) Update

func (r *ContentBlockRepo) Update(ctx context.Context, block *cms.ContentBlock) error

Update persists changes to an existing content block.

type ContentTranslationRepo

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

ContentTranslationRepo implements translation.ContentTranslationRepository using PostgreSQL.

func NewContentTranslationRepo

func NewContentTranslationRepo(db *sql.DB) (*ContentTranslationRepo, error)

NewContentTranslationRepo returns a new ContentTranslationRepo backed by db.

func (*ContentTranslationRepo) DeleteByEntity

func (r *ContentTranslationRepo) DeleteByEntity(ctx context.Context, entityID string) error

DeleteByEntity removes all translations for an entity.

func (*ContentTranslationRepo) FindByEntityAndLanguage

func (r *ContentTranslationRepo) FindByEntityAndLanguage(ctx context.Context, entityID, language string) ([]translation.ContentTranslation, error)

FindByEntityAndLanguage returns all translated fields for an entity in a language. Returns an empty slice (not nil) when no translations exist.

func (*ContentTranslationRepo) FindFieldValue

func (r *ContentTranslationRepo) FindFieldValue(ctx context.Context, entityID, language, field string) (*translation.ContentTranslation, error)

FindFieldValue returns the translated value for a specific entity+language+field. Returns (nil, nil) when not found.

func (*ContentTranslationRepo) Upsert

Upsert creates or updates a content translation for an entity+language+field tuple.

type CouponRepo

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

CouponRepo implements promotion.CouponRepository using PostgreSQL.

func NewCouponRepo

func NewCouponRepo(db *sql.DB) (*CouponRepo, error)

NewCouponRepo returns a new CouponRepo backed by db.

func (*CouponRepo) Delete

func (r *CouponRepo) Delete(ctx context.Context, id string) error

func (*CouponRepo) FindByCode

func (r *CouponRepo) FindByCode(ctx context.Context, code string) (*promotion.Coupon, error)

func (*CouponRepo) FindByID

func (r *CouponRepo) FindByID(ctx context.Context, id string) (*promotion.Coupon, error)

func (*CouponRepo) List

func (r *CouponRepo) List(ctx context.Context, offset, limit int) ([]promotion.Coupon, error)

func (*CouponRepo) ListByPromotion

func (r *CouponRepo) ListByPromotion(ctx context.Context, promotionID string) ([]promotion.Coupon, error)

func (*CouponRepo) Save

func (r *CouponRepo) Save(ctx context.Context, c *promotion.Coupon) error

func (*CouponRepo) WithTx

func (r *CouponRepo) WithTx(tx *sql.Tx) *CouponRepo

WithTx returns a repo bound to the given transaction.

type CreditNoteRepo

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

CreditNoteRepo implements invoice.CreditNoteRepository using PostgreSQL.

func NewCreditNoteRepo

func NewCreditNoteRepo(db *sql.DB) (*CreditNoteRepo, error)

NewCreditNoteRepo returns a new CreditNoteRepo backed by db.

func (*CreditNoteRepo) FindByID

func (r *CreditNoteRepo) FindByID(ctx context.Context, id string) (*invoice.CreditNote, error)

FindByID returns a credit note with its items by ID. Returns (nil, nil) when not found.

func (*CreditNoteRepo) FindByInvoiceID

func (r *CreditNoteRepo) FindByInvoiceID(ctx context.Context, invoiceID string) ([]invoice.CreditNote, error)

FindByInvoiceID returns all credit notes for an invoice, newest first.

func (*CreditNoteRepo) Save

Save persists a credit note and its items (insert-only). Assigns CreditNoteNumber from the DB sequence.

type CustomerAddressRepo

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

CustomerAddressRepo implements customer.AddressRepository using PostgreSQL.

func NewCustomerAddressRepo

func NewCustomerAddressRepo(db *sql.DB) (*CustomerAddressRepo, error)

NewCustomerAddressRepo returns a new CustomerAddressRepo backed by db.

func (*CustomerAddressRepo) Create

Create persists a new address. The first address a customer saves, or any address created with IsDefault set, becomes their default.

func (*CustomerAddressRepo) Delete

func (r *CustomerAddressRepo) Delete(ctx context.Context, customerID, addressID string) error

Delete removes an address owned by the customer.

func (*CustomerAddressRepo) FindByID

func (r *CustomerAddressRepo) FindByID(ctx context.Context, id string) (*customer.Address, error)

FindByID returns an address by its ID. Returns (nil, nil) when not found.

func (*CustomerAddressRepo) FindDefault

func (r *CustomerAddressRepo) FindDefault(ctx context.Context, customerID string) (*customer.Address, error)

FindDefault returns the customer's default address, or (nil, nil) when none.

func (*CustomerAddressRepo) ListByCustomer

func (r *CustomerAddressRepo) ListByCustomer(ctx context.Context, customerID string) ([]customer.Address, error)

ListByCustomer returns the customer's saved addresses, default first.

func (*CustomerAddressRepo) SetDefault

func (r *CustomerAddressRepo) SetDefault(ctx context.Context, customerID, addressID string) error

SetDefault marks one address as the customer's default and clears the rest.

func (*CustomerAddressRepo) Update

Update persists changes to an existing address.

type CustomerRepo

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

CustomerRepo implements customer.CustomerRepository using PostgreSQL.

func NewCustomerRepo

func NewCustomerRepo(db *sql.DB) (*CustomerRepo, error)

NewCustomerRepo returns a new CustomerRepo backed by db.

func (*CustomerRepo) BumpTokenGeneration

func (r *CustomerRepo) BumpTokenGeneration(ctx context.Context, customerID string) error

BumpTokenGeneration atomically increments the customer's token generation.

func (*CustomerRepo) ChangePasswordAndBumpTokenGeneration

func (r *CustomerRepo) ChangePasswordAndBumpTokenGeneration(ctx context.Context, customerID, passwordHash string) error

ChangePasswordAndBumpTokenGeneration atomically updates the password hash and invalidates previously issued tokens.

func (*CustomerRepo) Create

func (r *CustomerRepo) Create(ctx context.Context, c *customer.Customer) error

Create persists a new customer.

func (*CustomerRepo) Delete

func (r *CustomerRepo) Delete(ctx context.Context, id string) error

Delete removes a customer by ID.

func (*CustomerRepo) FindByEmail

func (r *CustomerRepo) FindByEmail(ctx context.Context, email string) (*customer.Customer, error)

FindByEmail returns a customer by email address (case-insensitive). Returns (nil, nil) when not found.

func (*CustomerRepo) FindByID

func (r *CustomerRepo) FindByID(ctx context.Context, id string) (*customer.Customer, error)

FindByID returns a customer by its ID. Returns (nil, nil) when not found.

func (*CustomerRepo) HasActiveAdmin

func (r *CustomerRepo) HasActiveAdmin(ctx context.Context) (bool, error)

HasActiveAdmin reports whether at least one active admin user exists.

func (*CustomerRepo) ListAdminUsers

func (r *CustomerRepo) ListAdminUsers(ctx context.Context, offset, limit int) ([]customer.Customer, error)

ListAdminUsers returns admin-capable users ordered by email.

func (*CustomerRepo) ListCustomers

func (r *CustomerRepo) ListCustomers(ctx context.Context, offset, limit int) ([]customer.Customer, error)

ListCustomers returns a paginated slice of customers ordered by email.

func (*CustomerRepo) Update

func (r *CustomerRepo) Update(ctx context.Context, c *customer.Customer) error

Update persists changes to an existing customer.

func (*CustomerRepo) UpdateAdminUser

func (r *CustomerRepo) UpdateAdminUser(ctx context.Context, c *customer.Customer, priorRole customer.Role, priorStatus customer.Status, revokeSessions bool) error

UpdateAdminUser atomically updates an admin user and enforces last-active-admin rules.

func (*CustomerRepo) WithTx

WithTx returns a repo bound to the given transaction.

type ExtensionFieldRepo

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

ExtensionFieldRepo persists extension field definitions in Postgres.

func NewExtensionFieldRepo

func NewExtensionFieldRepo(db *sql.DB) (*ExtensionFieldRepo, error)

NewExtensionFieldRepo creates an ExtensionFieldRepo.

func (*ExtensionFieldRepo) Create

Create inserts a new active field or restores a soft-deleted row.

func (*ExtensionFieldRepo) FindByCode

FindByCode returns an active field by code.

func (*ExtensionFieldRepo) ListActive

ListActive returns non-deleted fields, optionally filtered by scope.

func (*ExtensionFieldRepo) Save

Save upserts an extension field definition.

func (*ExtensionFieldRepo) SoftDelete

func (r *ExtensionFieldRepo) SoftDelete(ctx context.Context, code string) error

SoftDelete marks a field as deleted.

type ExtensionValueRepo

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

ExtensionValueRepo persists extension field values in Postgres.

func NewExtensionValueRepo

func NewExtensionValueRepo(db *sql.DB) (*ExtensionValueRepo, error)

NewExtensionValueRepo creates an ExtensionValueRepo.

func (*ExtensionValueRepo) Delete

func (r *ExtensionValueRepo) Delete(ctx context.Context, target domainext.Target, fieldCode string) error

Delete removes a value row.

func (*ExtensionValueRepo) ListByTarget

func (r *ExtensionValueRepo) ListByTarget(ctx context.Context, target domainext.Target) ([]domainext.Value, error)

ListByTarget returns all values for a target.

func (*ExtensionValueRepo) ListByTargets

func (r *ExtensionValueRepo) ListByTargets(ctx context.Context, targetType domainext.TargetType, targetIDs []string) ([]domainext.Value, error)

ListByTargets returns all values for many targets of the same type.

func (*ExtensionValueRepo) Upsert

func (r *ExtensionValueRepo) Upsert(ctx context.Context, value domainext.Value) error

Upsert stores or replaces a value row.

func (*ExtensionValueRepo) UpsertBatch

func (r *ExtensionValueRepo) UpsertBatch(ctx context.Context, values []domainext.Value) error

UpsertBatch stores or replaces value rows in a single transaction.

type IntegrationIdempotencyRepo

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

IntegrationIdempotencyRepo persists inbound integration idempotency keys in Postgres.

func NewIntegrationIdempotencyRepo

func NewIntegrationIdempotencyRepo(db *sql.DB) (*IntegrationIdempotencyRepo, error)

NewIntegrationIdempotencyRepo returns an IntegrationIdempotencyRepo backed by db.

func (*IntegrationIdempotencyRepo) Begin

func (r *IntegrationIdempotencyRepo) Begin(ctx context.Context, plugin, key, method, path, requestHash string, expiresAt time.Time) (*integrationhttp.IdempotencyRecord, bool, error)

Begin claims or loads an idempotency key.

func (*IntegrationIdempotencyRepo) Complete

func (r *IntegrationIdempotencyRepo) Complete(ctx context.Context, plugin, key string, statusCode int, body []byte) error

Complete stores the response for a claimed idempotency key.

func (*IntegrationIdempotencyRepo) Get

Get returns one idempotency record by plugin slug and key (includes stored response body).

func (*IntegrationIdempotencyRepo) List

List returns idempotency records ordered by newest first (without response bodies).

type InvoiceRepo

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

InvoiceRepo implements invoice.InvoiceRepository using PostgreSQL.

func NewInvoiceRepo

func NewInvoiceRepo(db *sql.DB) (*InvoiceRepo, error)

NewInvoiceRepo returns a new InvoiceRepo backed by db.

func (*InvoiceRepo) FindByID

func (r *InvoiceRepo) FindByID(ctx context.Context, id string) (*invoice.Invoice, error)

FindByID returns an invoice with its items by ID. Returns (nil, nil) when not found.

func (*InvoiceRepo) FindByOrderID

func (r *InvoiceRepo) FindByOrderID(ctx context.Context, orderID string) (*invoice.Invoice, error)

FindByOrderID returns the invoice for an order. Returns (nil, nil) when not found.

func (*InvoiceRepo) Save

func (r *InvoiceRepo) Save(ctx context.Context, inv *invoice.Invoice) error

Save persists an invoice and its items (insert-only). Assigns InvoiceNumber from the DB sequence.

type JobQueue

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

JobQueue implements jobs.Queue using PostgreSQL with FOR UPDATE SKIP LOCKED.

func NewJobQueue

func NewJobQueue(db *sql.DB) (*JobQueue, error)

NewJobQueue returns a new JobQueue backed by db.

func (*JobQueue) Complete

func (q *JobQueue) Complete(ctx context.Context, id string) error

Complete marks a job as done.

func (*JobQueue) Dequeue

func (q *JobQueue) Dequeue(ctx context.Context) (*jobs.Job, error)

Dequeue atomically claims the next pending job using FOR UPDATE SKIP LOCKED. Returns nil, nil when no jobs are available.

func (*JobQueue) Enqueue

func (q *JobQueue) Enqueue(ctx context.Context, job jobs.Job) error

Enqueue inserts a new job into the queue.

func (*JobQueue) Fail

func (q *JobQueue) Fail(ctx context.Context, id string, jobErr error) error

Fail re-queues a job for retry or marks it as permanently failed. Uses atomic conditional UPDATEs to avoid read-then-write races.

type MFARepo

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

MFARepo implements mfa.Repository using PostgreSQL.

func NewMFARepo

func NewMFARepo(db *sql.DB) (*MFARepo, error)

NewMFARepo returns an MFARepo backed by db.

func (*MFARepo) ClearEnrollment

func (r *MFARepo) ClearEnrollment(ctx context.Context, customerID string) error

ClearEnrollment removes MFA state for a customer.

func (*MFARepo) ConsumeRecoveryCode

func (r *MFARepo) ConsumeRecoveryCode(ctx context.Context, customerID, codeHash string) (bool, error)

ConsumeRecoveryCode marks a matching unused recovery code as used.

func (*MFARepo) FinalizeEnrollment

func (r *MFARepo) FinalizeEnrollment(ctx context.Context, customerID string, confirmedAt time.Time, codeHashes []string) error

ConfirmEnrollment marks TOTP as active and stores recovery codes atomically.

func (*MFARepo) GetState

func (r *MFARepo) GetState(ctx context.Context, customerID string) (domainMFA.State, error)

GetState returns MFA enrollment state for a customer.

func (*MFARepo) ReplaceRecoveryCodes

func (r *MFARepo) ReplaceRecoveryCodes(ctx context.Context, customerID string, codeHashes []string) error

ReplaceRecoveryCodes replaces all recovery codes for a customer.

func (*MFARepo) SavePendingSecret

func (r *MFARepo) SavePendingSecret(ctx context.Context, customerID, secretEnc string) error

SavePendingSecret stores an unconfirmed encrypted TOTP secret.

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

MenuRepo implements cms.MenuRepository using PostgreSQL.

func NewMenuRepo

func NewMenuRepo(db *sql.DB) (*MenuRepo, error)

NewMenuRepo returns a new MenuRepo backed by db.

func (r *MenuRepo) FindByCode(ctx context.Context, code string) (*cms.MenuWithItems, error)

FindByCode returns a menu with items by code.

func (r *MenuRepo) FindByID(ctx context.Context, id string) (*cms.MenuWithItems, error)

FindByID returns a menu with items by ID.

func (r *MenuRepo) List(ctx context.Context) ([]*cms.Menu, error)

List returns all menus ordered by code.

func (r *MenuRepo) Save(ctx context.Context, data *cms.MenuWithItems) error

Save updates menu metadata and replaces all items atomically.

type OrderRepo

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

OrderRepo implements order.OrderRepository using PostgreSQL.

func NewOrderRepo

func NewOrderRepo(db *sql.DB) (*OrderRepo, error)

NewOrderRepo returns a new OrderRepo backed by db.

func (*OrderRepo) FindByContactEmail

func (r *OrderRepo) FindByContactEmail(ctx context.Context, contactEmail string) ([]order.Order, error)

FindByContactEmail returns all orders with a matching contact email, newest first. Used for guest order discovery. Returns empty slice if none found.

func (*OrderRepo) FindByCustomerID

func (r *OrderRepo) FindByCustomerID(ctx context.Context, customerID string) ([]order.Order, error)

FindByCustomerID returns all orders for a customer, newest first.

func (*OrderRepo) FindByID

func (r *OrderRepo) FindByID(ctx context.Context, id string) (*order.Order, error)

FindByID returns an order with its items by ID. Returns (nil, nil) when not found.

func (*OrderRepo) LinkToCustomer

func (r *OrderRepo) LinkToCustomer(ctx context.Context, o *order.Order) error

LinkToCustomer persists customer ownership for a previously guest order. The WHERE guard (customer_id = ”) ensures an already-linked order is never silently reassigned to another customer.

func (*OrderRepo) LinkToCustomerByContactEmail

func (r *OrderRepo) LinkToCustomerByContactEmail(ctx context.Context, contactEmail, customerID string, updatedAt time.Time) (int64, error)

LinkToCustomerByContactEmail atomically links every unclaimed guest order carrying the contact email to the customer. A single UPDATE statement keeps the multi-order claim all-or-nothing.

func (*OrderRepo) List

func (r *OrderRepo) List(ctx context.Context, offset, limit int) ([]order.Order, error)

List returns a page of orders, newest first.

func (*OrderRepo) ListPaidTaxSnapshots

func (r *OrderRepo) ListPaidTaxSnapshots(ctx context.Context, from, to time.Time) ([]order.TaxSnapshotRow, error)

ListPaidTaxSnapshots returns paid orders with destination country in [from, to).

func (*OrderRepo) Save

func (r *OrderRepo) Save(ctx context.Context, o *order.Order) error

Save persists an order and its items (insert-only).

func (*OrderRepo) UpdateStatus

func (r *OrderRepo) UpdateStatus(ctx context.Context, o *order.Order) error

UpdateStatus updates only the status and updated_at of an existing order.

type PageRepo

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

PageRepo implements cms.PageRepository using PostgreSQL.

func NewPageRepo

func NewPageRepo(db *sql.DB) (*PageRepo, error)

NewPageRepo returns a new PageRepo backed by db.

func (*PageRepo) Create

func (r *PageRepo) Create(ctx context.Context, p *cms.Page) error

Create inserts a new page.

func (*PageRepo) Delete

func (r *PageRepo) Delete(ctx context.Context, id string) error

Delete removes a page by its ID.

func (*PageRepo) FindActiveBySlug

func (r *PageRepo) FindActiveBySlug(ctx context.Context, slug string) (*cms.Page, error)

FindActiveBySlug returns an active page by its slug. Returns (nil, nil) when not found or inactive.

func (*PageRepo) FindByID

func (r *PageRepo) FindByID(ctx context.Context, id string) (*cms.Page, error)

FindByID returns a page by its ID. Returns (nil, nil) when not found.

func (*PageRepo) FindBySlug

func (r *PageRepo) FindBySlug(ctx context.Context, slug string) (*cms.Page, error)

FindBySlug returns a page by its slug regardless of active status. Returns (nil, nil) when not found.

func (*PageRepo) List

func (r *PageRepo) List(ctx context.Context, offset, limit int) ([]*cms.Page, error)

List returns pages ordered by created_at desc with pagination.

func (*PageRepo) Update

func (r *PageRepo) Update(ctx context.Context, p *cms.Page) error

Update saves changes to an existing page.

type PaymentRepo

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

PaymentRepo implements payment.PaymentRepository using PostgreSQL.

func NewPaymentRepo

func NewPaymentRepo(db *sql.DB) (*PaymentRepo, error)

NewPaymentRepo returns a new PaymentRepo backed by db.

func (*PaymentRepo) Create

func (r *PaymentRepo) Create(ctx context.Context, p *payment.Payment) error

Create persists a new payment.

func (*PaymentRepo) FindByID

func (r *PaymentRepo) FindByID(ctx context.Context, id string) (*payment.Payment, error)

FindByID returns a payment by its ID. Returns (nil, nil) when not found.

func (*PaymentRepo) FindByOrderID

func (r *PaymentRepo) FindByOrderID(ctx context.Context, orderID string) (*payment.Payment, error)

FindByOrderID returns the payment for a given order. Returns (nil, nil) when no payment exists for the order.

func (*PaymentRepo) List

func (r *PaymentRepo) List(ctx context.Context, filter payment.ListFilter) ([]payment.Payment, error)

List returns payments ordered by created_at desc with optional status filter.

func (*PaymentRepo) UpdateStatus

func (r *PaymentRepo) UpdateStatus(ctx context.Context, p *payment.Payment, prevUpdatedAt time.Time) error

UpdateStatus updates the status, provider_ref, and updated_at of a payment. Uses optimistic locking via updated_at to detect concurrent modifications.

type PriceHistoryRepo

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

PriceHistoryRepo implements pricing.PriceHistoryRepository using PostgreSQL.

func NewPriceHistoryRepo

func NewPriceHistoryRepo(db *sql.DB) (*PriceHistoryRepo, error)

NewPriceHistoryRepo returns a new PriceHistoryRepo backed by db.

func (*PriceHistoryRepo) LowestSince

func (r *PriceHistoryRepo) LowestSince(ctx context.Context, variantID, currency, storeID string, since time.Time) (*pricing.PriceSnapshot, error)

LowestSince returns the snapshot with the lowest amount for the given variant, currency, and store recorded on or after since. Returns (nil, nil) when no snapshots exist in the window.

func (*PriceHistoryRepo) LowestSinceByVariants

func (r *PriceHistoryRepo) LowestSinceByVariants(ctx context.Context, variantIDs []string, currency, storeID string, since time.Time) (map[string]*pricing.PriceSnapshot, error)

LowestSinceByVariants returns the lowest snapshot per variant in the window.

func (*PriceHistoryRepo) Record

Record inserts a new price snapshot.

func (*PriceHistoryRepo) WithTx

WithTx returns a repo bound to the given transaction.

type PriceRepo

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

PriceRepo implements pricing.PriceRepository using PostgreSQL.

func NewPriceRepo

func NewPriceRepo(db *sql.DB) (*PriceRepo, error)

NewPriceRepo returns a new PriceRepo backed by db.

func (*PriceRepo) FindByVariantCurrencyAndStore

func (r *PriceRepo) FindByVariantCurrencyAndStore(ctx context.Context, variantID, currency, storeID string) (*pricing.Price, error)

FindByVariantCurrencyAndStore returns the price for a variant in the given currency and store. An empty storeID means the global/default price. Returns (nil, nil) when no price exists.

func (*PriceRepo) FindByVariantsCurrencyAndStore

func (r *PriceRepo) FindByVariantsCurrencyAndStore(ctx context.Context, variantIDs []string, currency, storeID string) (map[string]*pricing.Price, error)

FindByVariantsCurrencyAndStore returns prices for multiple variants.

func (*PriceRepo) List

func (r *PriceRepo) List(ctx context.Context, offset, limit int) ([]pricing.Price, error)

List returns a page of prices ordered by variant_id then currency.

func (*PriceRepo) ListByVariantID

func (r *PriceRepo) ListByVariantID(ctx context.Context, variantID string) ([]pricing.Price, error)

ListByVariantID returns all prices for a variant.

func (*PriceRepo) Upsert

func (r *PriceRepo) Upsert(ctx context.Context, p *pricing.Price) error

Upsert creates or updates a price for a variant+currency+store tuple.

func (*PriceRepo) WithTx

func (r *PriceRepo) WithTx(tx *sql.Tx) pricing.PriceRepository

WithTx returns a repo bound to the given transaction.

type ProductRepo

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

ProductRepo implements catalog.ProductRepository using PostgreSQL.

func NewProductRepo

func NewProductRepo(db *sql.DB) (*ProductRepo, error)

NewProductRepo returns a new ProductRepo backed by db.

func (*ProductRepo) AssignCategory

func (r *ProductRepo) AssignCategory(ctx context.Context, productID, categoryID string) error

AssignCategory creates a product-category link when it does not already exist.

func (*ProductRepo) Create

func (r *ProductRepo) Create(ctx context.Context, p *catalog.Product) error

Create persists a new product.

func (*ProductRepo) FindByCategoryID

func (r *ProductRepo) FindByCategoryID(ctx context.Context, categoryID string, offset, limit int) ([]catalog.Product, error)

FindByCategoryID returns products belonging to the given category, ordered by created_at desc.

func (*ProductRepo) FindByID

func (r *ProductRepo) FindByID(ctx context.Context, id string) (*catalog.Product, error)

FindByID returns a product by its ID. Returns (nil, nil) when the product does not exist.

func (*ProductRepo) FindBySlug

func (r *ProductRepo) FindBySlug(ctx context.Context, slug string) (*catalog.Product, error)

FindBySlug returns a product by its slug. Returns (nil, nil) when no product matches the slug.

func (*ProductRepo) List

func (r *ProductRepo) List(ctx context.Context, offset, limit int) ([]catalog.Product, error)

List returns a page of products ordered by created_at desc.

func (*ProductRepo) ListCategoryIDsByProduct

func (r *ProductRepo) ListCategoryIDsByProduct(ctx context.Context, productID string) ([]string, error)

ListCategoryIDsByProduct returns assigned category IDs for a product.

func (*ProductRepo) RemoveCategory

func (r *ProductRepo) RemoveCategory(ctx context.Context, productID, categoryID string) error

RemoveCategory deletes a product-category link.

func (*ProductRepo) Update

func (r *ProductRepo) Update(ctx context.Context, p *catalog.Product) error

Update persists changes to an existing product.

func (*ProductRepo) WithTx

func (r *ProductRepo) WithTx(tx *sql.Tx) catalog.ProductRepository

WithTx returns a repo bound to the given transaction.

type PromotionRepo

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

PromotionRepo implements promotion.PromotionRepository using PostgreSQL.

func NewPromotionRepo

func NewPromotionRepo(db *sql.DB) (*PromotionRepo, error)

NewPromotionRepo returns a new PromotionRepo backed by db.

func (*PromotionRepo) Delete

func (r *PromotionRepo) Delete(ctx context.Context, id string) error

func (*PromotionRepo) FindByID

func (r *PromotionRepo) FindByID(ctx context.Context, id string) (*promotion.Promotion, error)

func (*PromotionRepo) List

func (r *PromotionRepo) List(ctx context.Context, offset, limit int) ([]promotion.Promotion, error)

func (*PromotionRepo) ListActive

func (*PromotionRepo) Save

func (*PromotionRepo) WithTx

func (r *PromotionRepo) WithTx(tx *sql.Tx) *PromotionRepo

WithTx returns a repo bound to the given transaction.

type ReservationRepo

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

ReservationRepo implements inventory.ReservationRepository using PostgreSQL.

func NewReservationRepo

func NewReservationRepo(db *sql.DB) (*ReservationRepo, error)

NewReservationRepo returns a new ReservationRepo backed by db.

func (*ReservationRepo) Confirm

func (r *ReservationRepo) Confirm(ctx context.Context, reservationID string) error

Confirm marks a reservation as confirmed without restoring stock.

func (*ReservationRepo) FindByID

func (r *ReservationRepo) FindByID(ctx context.Context, id string) (*inventory.Reservation, error)

FindByID returns a reservation by its ID.

func (*ReservationRepo) ListActiveByVariantID

func (r *ReservationRepo) ListActiveByVariantID(ctx context.Context, variantID string) ([]inventory.Reservation, error)

ListActiveByVariantID returns all active reservations for a variant.

func (*ReservationRepo) Release

func (r *ReservationRepo) Release(ctx context.Context, reservationID string) error

Release cancels an active reservation and restores stock.

func (*ReservationRepo) ReleaseExpiredBefore

func (r *ReservationRepo) ReleaseExpiredBefore(ctx context.Context, cutoff time.Time) (int, error)

ReleaseExpiredBefore atomically releases all active reservations that expired before cutoff and restores their quantities to stock.

func (*ReservationRepo) Reserve

func (r *ReservationRepo) Reserve(ctx context.Context, res *inventory.Reservation) error

Reserve atomically decrements stock and creates a reservation within a transaction.

type ResetTokenRepo

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

ResetTokenRepo implements customer.PasswordResetRepository using PostgreSQL.

func NewResetTokenRepo

func NewResetTokenRepo(db *sql.DB) (*ResetTokenRepo, error)

NewResetTokenRepo returns a new ResetTokenRepo backed by db.

func (*ResetTokenRepo) Create

Create persists a new password reset token.

func (*ResetTokenRepo) FindByTokenHash

func (r *ResetTokenRepo) FindByTokenHash(ctx context.Context, hash string) (*customer.PasswordResetToken, error)

FindByTokenHash returns a reset token by its hash.

func (*ResetTokenRepo) MarkUsed

func (r *ResetTokenRepo) MarkUsed(ctx context.Context, id string) error

MarkUsed sets the used_at timestamp on a reset token. Only updates if the token has not already been used (used_at IS NULL), preventing TOCTOU races between concurrent callers.

func (*ResetTokenRepo) WithTx

func (r *ResetTokenRepo) WithTx(tx *sql.Tx) *ResetTokenRepo

WithTx returns a repo bound to the given transaction.

type ReturnRepo

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

ReturnRepo implements returns.Repository using PostgreSQL.

func NewReturnRepo

func NewReturnRepo(db *sql.DB) (*ReturnRepo, error)

NewReturnRepo returns a new ReturnRepo backed by db.

func (*ReturnRepo) FindByCustomerID

func (r *ReturnRepo) FindByCustomerID(ctx context.Context, customerID string) ([]domainReturns.Return, error)

FindByCustomerID returns all returns for a customer, newest first.

func (*ReturnRepo) FindByID

func (r *ReturnRepo) FindByID(ctx context.Context, id string) (*domainReturns.Return, error)

FindByID returns a return with its items.

func (*ReturnRepo) FindByOrderID

func (r *ReturnRepo) FindByOrderID(ctx context.Context, orderID string) ([]domainReturns.Return, error)

FindByOrderID returns all returns for an order, newest first.

func (*ReturnRepo) List

func (r *ReturnRepo) List(ctx context.Context, offset, limit int) ([]domainReturns.Return, error)

List returns returns ordered by created_at desc with pagination.

func (*ReturnRepo) Save

func (r *ReturnRepo) Save(ctx context.Context, ret *domainReturns.Return) error

Save inserts a new return and its items.

func (*ReturnRepo) Update

func (r *ReturnRepo) Update(ctx context.Context, ret *domainReturns.Return) error

Update persists status transitions and timestamps.

type ReviewRepo

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

ReviewRepo implements review.Repository using PostgreSQL.

func NewReviewRepo

func NewReviewRepo(db *sql.DB) (*ReviewRepo, error)

NewReviewRepo returns a new ReviewRepo backed by db.

func (*ReviewRepo) FindByID

func (r *ReviewRepo) FindByID(ctx context.Context, id string) (*domainReview.Review, error)

FindByID returns a review by ID.

func (*ReviewRepo) FindByProductAndCustomer

func (r *ReviewRepo) FindByProductAndCustomer(ctx context.Context, productID, customerID string) (*domainReview.Review, error)

FindByProductAndCustomer returns a review for the product/customer pair.

func (*ReviewRepo) List

func (r *ReviewRepo) List(ctx context.Context, status domainReview.Status, offset, limit int) ([]domainReview.Review, error)

List returns reviews with optional status filter.

func (*ReviewRepo) ListApprovedByProduct

func (r *ReviewRepo) ListApprovedByProduct(ctx context.Context, productID string, offset, limit int) ([]domainReview.Review, error)

ListApprovedByProduct returns approved reviews with reviewer first name.

func (*ReviewRepo) Save

func (r *ReviewRepo) Save(ctx context.Context, rev *domainReview.Review) error

Save inserts a new review.

func (*ReviewRepo) SummaryByProduct

func (r *ReviewRepo) SummaryByProduct(ctx context.Context, productID string) (domainReview.ProductSummary, error)

SummaryByProduct returns aggregate stats for approved reviews.

func (*ReviewRepo) Update

func (r *ReviewRepo) Update(ctx context.Context, rev *domainReview.Review, priorStatus domainReview.Status) error

Update persists moderation transitions when the review still has priorStatus.

type RewriteRepo

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

RewriteRepo implements routing.RewriteRepository using PostgreSQL.

func NewRewriteRepo

func NewRewriteRepo(db *sql.DB) (*RewriteRepo, error)

NewRewriteRepo returns a new RewriteRepo backed by db.

func (*RewriteRepo) Delete

func (r *RewriteRepo) Delete(ctx context.Context, path string) error

Delete removes the URL rewrite for the given path.

func (*RewriteRepo) FindByPath

func (r *RewriteRepo) FindByPath(ctx context.Context, path string) (*routing.URLRewrite, error)

FindByPath returns a URL rewrite for the given path. Returns (nil, nil) when not found.

func (*RewriteRepo) Save

func (r *RewriteRepo) Save(ctx context.Context, rw *routing.URLRewrite) error

Save inserts or updates a URL rewrite.

type RolePermissionRepo

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

RolePermissionRepo implements rbac.Repository using PostgreSQL.

func NewRolePermissionRepo

func NewRolePermissionRepo(db *sql.DB) (*RolePermissionRepo, error)

NewRolePermissionRepo returns a RolePermissionRepo backed by db.

func (*RolePermissionRepo) EnsurePermissions

func (r *RolePermissionRepo) EnsurePermissions(ctx context.Context, role identity.Role, perms []rbac.Permission) error

EnsurePermissions inserts missing role/permission pairs.

func (*RolePermissionRepo) ListAll

ListAll returns permissions grouped by admin role.

func (*RolePermissionRepo) ReplaceForRole

func (r *RolePermissionRepo) ReplaceForRole(ctx context.Context, role identity.Role, perms []rbac.Permission) error

ReplaceForRole replaces all permissions for a role.

type SearchEngine

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

SearchEngine implements search.SearchEngine using PostgreSQL full-text search.

func NewSearchEngine

func NewSearchEngine(db *sql.DB) (*SearchEngine, error)

NewSearchEngine returns a new SearchEngine backed by db.

func (*SearchEngine) IndexProduct

func (e *SearchEngine) IndexProduct(ctx context.Context, p search.Product) error

IndexProduct updates the search vector for a product. The search_vector trigger on the products table handles normal INSERT/UPDATE, so this method is primarily useful for explicit reindexing.

func (*SearchEngine) Name

func (e *SearchEngine) Name() string

Name returns "postgres".

func (*SearchEngine) RemoveProduct

func (e *SearchEngine) RemoveProduct(ctx context.Context, productID string) error

RemoveProduct clears the search vector for a product, making it unsearchable.

func (*SearchEngine) Search

Search executes a full-text search query with optional filters, sorting, and facets.

func (*SearchEngine) Suggest

func (e *SearchEngine) Suggest(ctx context.Context, prefix string, limit int) ([]search.Suggestion, error)

Suggest returns autocomplete suggestions using prefix matching on product names.

type ShippingRepo

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

ShippingRepo implements shipping.ShipmentRepository using PostgreSQL.

func NewShippingRepo

func NewShippingRepo(db *sql.DB) (*ShippingRepo, error)

NewShippingRepo returns a new ShippingRepo backed by db.

func (*ShippingRepo) Create

func (r *ShippingRepo) Create(ctx context.Context, s *shipping.Shipment) error

Create persists a new shipment.

func (*ShippingRepo) FindByID

func (r *ShippingRepo) FindByID(ctx context.Context, id string) (*shipping.Shipment, error)

FindByID returns a shipment by its ID. Returns (nil, nil) when not found.

func (*ShippingRepo) FindByOrderID

func (r *ShippingRepo) FindByOrderID(ctx context.Context, orderID string) (*shipping.Shipment, error)

FindByOrderID returns the shipment for a given order. Returns (nil, nil) when no shipment exists for the order.

func (*ShippingRepo) UpdateStatus

func (r *ShippingRepo) UpdateStatus(ctx context.Context, s *shipping.Shipment, prevUpdatedAt time.Time) error

UpdateStatus updates the status, tracking_number, provider_ref, and updated_at of a shipment. Uses optimistic locking via updated_at to detect concurrent modifications.

type StatsRepo

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

StatsRepo implements admin.StatsRepository using PostgreSQL.

func NewStatsRepo

func NewStatsRepo(db *sql.DB) (*StatsRepo, error)

NewStatsRepo returns a new StatsRepo backed by db.

func (*StatsRepo) GetDashboardStats

func (r *StatsRepo) GetDashboardStats(ctx context.Context, lowStockThreshold, recentLimit int) (admin.DashboardStats, error)

GetDashboardStats returns the dashboard overview aggregations.

type StockRepo

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

StockRepo implements inventory.StockRepository using PostgreSQL.

func NewStockRepo

func NewStockRepo(db *sql.DB) (*StockRepo, error)

NewStockRepo returns a new StockRepo backed by db.

func (*StockRepo) GetInventoryItem

func (r *StockRepo) GetInventoryItem(ctx context.Context, variantID string) (inventory.InventoryListItem, error)

GetInventoryItem returns the admin inventory view for a single variant.

func (*StockRepo) GetStock

func (r *StockRepo) GetStock(ctx context.Context, variantID string) (inventory.StockEntry, error)

GetStock returns the stock entry for a variant. Returns a zero-quantity entry when no record exists.

func (*StockRepo) ListInventory

func (r *StockRepo) ListInventory(ctx context.Context, offset, limit int, search string) ([]inventory.InventoryListItem, error)

ListInventory returns a paginated admin inventory view for all variants.

func (*StockRepo) ListStock

func (r *StockRepo) ListStock(ctx context.Context, offset, limit int) ([]inventory.StockEntry, error)

ListStock returns a page of stock entries ordered by variant_id.

func (*StockRepo) SetStock

func (r *StockRepo) SetStock(ctx context.Context, entry *inventory.StockEntry) error

SetStock upserts the stock quantity for a variant.

func (*StockRepo) SetStocks

func (r *StockRepo) SetStocks(ctx context.Context, entries []inventory.StockEntry) error

SetStocks upserts stock quantities for multiple variants in one statement.

type StoreCreditRepo

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

StoreCreditRepo implements storecredit.Repository.

func NewStoreCreditRepo

func NewStoreCreditRepo(db *sql.DB) (*StoreCreditRepo, error)

NewStoreCreditRepo creates a StoreCreditRepo.

func (*StoreCreditRepo) GetBalance

func (r *StoreCreditRepo) GetBalance(ctx context.Context, customerID, currency string) (shared.Money, error)

func (*StoreCreditRepo) Issue

func (r *StoreCreditRepo) Issue(ctx context.Context, customerID string, amount shared.Money, note string) error

func (*StoreCreditRepo) ListLedger

func (r *StoreCreditRepo) ListLedger(ctx context.Context, customerID, currency string, offset, limit int) ([]storecredit.Entry, error)

func (*StoreCreditRepo) Redeem

func (r *StoreCreditRepo) Redeem(ctx context.Context, customerID, orderID string, amount shared.Money) error

type StoreRepo

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

StoreRepo implements store.StoreRepository using PostgreSQL.

func NewStoreRepo

func NewStoreRepo(db *sql.DB) (*StoreRepo, error)

NewStoreRepo returns a new StoreRepo backed by db.

func (*StoreRepo) Create

func (r *StoreRepo) Create(ctx context.Context, s *store.Store) error

Create persists a new store.

func (*StoreRepo) FindAll

func (r *StoreRepo) FindAll(ctx context.Context) ([]store.Store, error)

FindAll returns all stores ordered by name asc.

func (*StoreRepo) FindByCode

func (r *StoreRepo) FindByCode(ctx context.Context, code string) (*store.Store, error)

FindByCode returns a store by its unique code.

func (*StoreRepo) FindByDomain

func (r *StoreRepo) FindByDomain(ctx context.Context, domain string) (*store.Store, error)

FindByDomain returns a store by its domain.

func (*StoreRepo) FindByID

func (r *StoreRepo) FindByID(ctx context.Context, id string) (*store.Store, error)

FindByID returns a store by its ID.

func (*StoreRepo) FindDefault

func (r *StoreRepo) FindDefault(ctx context.Context) (*store.Store, error)

FindDefault returns the default store.

func (*StoreRepo) Update

func (r *StoreRepo) Update(ctx context.Context, s *store.Store) error

Update persists changes to an existing store.

type TaxRateRepo

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

TaxRateRepo implements tax.RateRepository using PostgreSQL.

func NewTaxRateRepo

func NewTaxRateRepo(db *sql.DB) (*TaxRateRepo, error)

NewTaxRateRepo returns a new TaxRateRepo backed by db.

func (*TaxRateRepo) CreateIfNotExists

func (r *TaxRateRepo) CreateIfNotExists(ctx context.Context, tr *tax.TaxRate) (bool, error)

CreateIfNotExists inserts a rate for a country+class+store tuple and leaves existing rows untouched. It returns true when a row was inserted.

func (*TaxRateRepo) Delete

func (r *TaxRateRepo) Delete(ctx context.Context, id string) error

Delete removes a tax rate by ID.

func (*TaxRateRepo) FindByCountryClassAndStore

func (r *TaxRateRepo) FindByCountryClassAndStore(ctx context.Context, country, class, storeID string) (*tax.TaxRate, error)

FindByCountryClassAndStore returns the rate for a country+class+store tuple. An empty storeID means the global/default rate. Returns (nil, nil) when no rate exists.

func (*TaxRateRepo) ListByCountry

func (r *TaxRateRepo) ListByCountry(ctx context.Context, country string) ([]tax.TaxRate, error)

ListByCountry returns all rates for a country, ordered by class then store_id.

func (*TaxRateRepo) Upsert

func (r *TaxRateRepo) Upsert(ctx context.Context, tr *tax.TaxRate) error

Upsert creates or updates a rate for a country+class+store tuple.

func (*TaxRateRepo) WithTx

func (r *TaxRateRepo) WithTx(tx *sql.Tx) *TaxRateRepo

WithTx returns a repo bound to the given transaction.

type TranslationRepo

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

TranslationRepo implements translation.TranslationRepository using PostgreSQL.

func NewTranslationRepo

func NewTranslationRepo(db *sql.DB) (*TranslationRepo, error)

NewTranslationRepo returns a new TranslationRepo backed by db.

func (*TranslationRepo) Delete

func (r *TranslationRepo) Delete(ctx context.Context, key, language string) error

Delete removes a translation by key and language.

func (*TranslationRepo) FindByKeyAndLanguage

func (r *TranslationRepo) FindByKeyAndLanguage(ctx context.Context, key, language string) (*translation.Translation, error)

FindByKeyAndLanguage returns a single translation. Returns (nil, nil) when not found.

func (*TranslationRepo) ListByLanguage

func (r *TranslationRepo) ListByLanguage(ctx context.Context, language string) ([]translation.Translation, error)

ListByLanguage returns all translations for a language, ordered by key.

func (*TranslationRepo) Upsert

Upsert creates or updates a translation for a key+language pair.

type VariantRepo

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

VariantRepo implements catalog.VariantRepository using PostgreSQL.

func NewVariantRepo

func NewVariantRepo(db *sql.DB) (*VariantRepo, error)

NewVariantRepo returns a new VariantRepo backed by db.

func (*VariantRepo) Create

func (r *VariantRepo) Create(ctx context.Context, v *catalog.Variant) error

Create persists a new variant.

func (*VariantRepo) FindByID

func (r *VariantRepo) FindByID(ctx context.Context, id string) (*catalog.Variant, error)

FindByID returns a variant by its ID. Returns (nil, nil) when the variant does not exist.

func (*VariantRepo) FindBySKU

func (r *VariantRepo) FindBySKU(ctx context.Context, sku string) (*catalog.Variant, error)

FindBySKU returns a variant by its SKU. Returns (nil, nil) when no variant matches the SKU.

func (*VariantRepo) FindBySKUs

func (r *VariantRepo) FindBySKUs(ctx context.Context, skus []string) (map[string]*catalog.Variant, error)

FindBySKUs returns variants keyed by SKU for the given SKUs.

func (*VariantRepo) ListByProductID

func (r *VariantRepo) ListByProductID(ctx context.Context, productID string, offset, limit int) ([]catalog.Variant, error)

ListByProductID returns variants for the given product ordered by created_at asc.

func (*VariantRepo) ListByProductIDs

func (r *VariantRepo) ListByProductIDs(ctx context.Context, productIDs []string, limitPerProduct int) (map[string][]catalog.Variant, error)

ListByProductIDs returns variants grouped by product ID.

func (*VariantRepo) Update

func (r *VariantRepo) Update(ctx context.Context, v *catalog.Variant) error

Update persists changes to an existing variant.

func (*VariantRepo) WithTx

func (r *VariantRepo) WithTx(tx *sql.Tx) catalog.VariantRepository

WithTx returns a repo bound to the given transaction.

type WebhookEndpointRepo

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

WebhookEndpointRepo implements domainwebhook.Repository.

func NewWebhookEndpointRepo

func NewWebhookEndpointRepo(db *sql.DB) (*WebhookEndpointRepo, error)

NewWebhookEndpointRepo returns a WebhookEndpointRepo backed by db.

func (*WebhookEndpointRepo) Create

func (r *WebhookEndpointRepo) Create(ctx context.Context, endpoint *domainwebhook.Endpoint) error

func (*WebhookEndpointRepo) Delete

func (r *WebhookEndpointRepo) Delete(ctx context.Context, endpointID string) error

func (*WebhookEndpointRepo) FindByID

func (r *WebhookEndpointRepo) FindByID(ctx context.Context, endpointID string) (*domainwebhook.Endpoint, error)

func (*WebhookEndpointRepo) List

func (*WebhookEndpointRepo) ListActive

func (*WebhookEndpointRepo) Update

func (r *WebhookEndpointRepo) Update(ctx context.Context, endpoint *domainwebhook.Endpoint) error

type ZoneRepo

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

ZoneRepo implements shipping.ZoneRepository using PostgreSQL.

func NewZoneRepo

func NewZoneRepo(db *sql.DB) (*ZoneRepo, error)

NewZoneRepo returns a new ZoneRepo backed by db.

func (*ZoneRepo) CreateRateTier

func (r *ZoneRepo) CreateRateTier(ctx context.Context, rt *shipping.RateTier) error

CreateRateTier persists a new rate tier.

func (*ZoneRepo) CreateZone

func (r *ZoneRepo) CreateZone(ctx context.Context, z *shipping.Zone) error

CreateZone persists a new shipping zone.

func (*ZoneRepo) DeleteRateTier

func (r *ZoneRepo) DeleteRateTier(ctx context.Context, id string) error

DeleteRateTier removes a rate tier by ID.

func (*ZoneRepo) DeleteZone

func (r *ZoneRepo) DeleteZone(ctx context.Context, id string) error

DeleteZone removes a zone and its rate tiers (cascaded by FK).

func (*ZoneRepo) FindRateTierByID

func (r *ZoneRepo) FindRateTierByID(ctx context.Context, id string) (*shipping.RateTier, error)

FindRateTierByID returns a rate tier by its ID. Returns (nil, nil) when not found.

func (*ZoneRepo) FindZoneByID

func (r *ZoneRepo) FindZoneByID(ctx context.Context, id string) (*shipping.Zone, error)

FindZoneByID returns a zone by its ID. Returns (nil, nil) when not found.

func (*ZoneRepo) ListRateTiers

func (r *ZoneRepo) ListRateTiers(ctx context.Context, zoneID string) ([]shipping.RateTier, error)

ListRateTiers returns all rate tiers for a zone ordered by min_weight.

func (*ZoneRepo) ListZones

func (r *ZoneRepo) ListZones(ctx context.Context) ([]shipping.Zone, error)

ListZones returns all shipping zones ordered by priority descending.

func (*ZoneRepo) UpdateRateTier

func (r *ZoneRepo) UpdateRateTier(ctx context.Context, rt *shipping.RateTier) error

UpdateRateTier updates a rate tier's fields.

func (*ZoneRepo) UpdateZone

func (r *ZoneRepo) UpdateZone(ctx context.Context, z *shipping.Zone) error

UpdateZone updates a shipping zone's mutable fields.

Jump to

Keyboard shortcuts

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