store

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a requested resource does not exist.

Functions

This section is empty.

Types

type APIKeyStore

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

APIKeyStore handles persistence for APIKey records.

func NewAPIKeyStore

func NewAPIKeyStore(pool *pgxpool.Pool) *APIKeyStore

NewAPIKeyStore creates an APIKeyStore backed by the given pool.

func (*APIKeyStore) Create

func (s *APIKeyStore) Create(ctx context.Context, tenantID, appID, name, role string) (plaintext string, key *model.APIKey, err error)

Create generates a new API key, stores the hash, and returns the plaintext (shown once). The plaintext has the form "cm_live_<32 random hex bytes>".

func (*APIKeyStore) GetByPlaintext

func (s *APIKeyStore) GetByPlaintext(ctx context.Context, plaintext string) (*model.APIKey, error)

GetByPlaintext hashes plaintext and fetches the matching active (non-revoked, non-expired) key.

func (*APIKeyStore) ListByApp

func (s *APIKeyStore) ListByApp(ctx context.Context, appID string) ([]model.APIKey, error)

ListByApp returns all non-revoked keys for the given app with KeyHash cleared.

func (*APIKeyStore) Revoke

func (s *APIKeyStore) Revoke(ctx context.Context, id string) error

Revoke sets revoked_at = now() for the given key.

func (*APIKeyStore) TouchLastUsed

func (s *APIKeyStore) TouchLastUsed(ctx context.Context, id string) error

TouchLastUsed sets last_used_at = now() for the given key.

type AppStore

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

AppStore handles persistence for App records.

func NewAppStore

func NewAppStore(pool *pgxpool.Pool) *AppStore

NewAppStore creates an AppStore backed by the given pool.

func (*AppStore) Create

func (s *AppStore) Create(ctx context.Context, a *model.App) error

Create inserts a new app and populates ID and CreatedAt via RETURNING.

func (*AppStore) Delete

func (s *AppStore) Delete(ctx context.Context, id string) error

Delete removes an app by primary key.

func (*AppStore) Get

func (s *AppStore) Get(ctx context.Context, id string) (*model.App, error)

Get fetches an app by primary key.

func (*AppStore) GetByEndpoint

func (s *AppStore) GetByEndpoint(ctx context.Context, endpoint string) (*model.App, error)

GetByEndpoint fetches an app by its endpoint value.

func (*AppStore) ListByTenant

func (s *AppStore) ListByTenant(ctx context.Context, tenantID string) ([]model.App, error)

ListByTenant returns all apps for the given tenant, oldest-first.

func (*AppStore) Update

func (s *AppStore) Update(ctx context.Context, a *model.App) error

Update persists mutable fields of the given app.

type AuditFilter

type AuditFilter struct {
	TenantID     string
	ActorID      string
	Action       string
	ResourceType string
	Limit        int
	Offset       int
}

AuditFilter specifies filter criteria for audit log queries.

type AuditStore

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

AuditStore handles persistence for AuditEntry records.

func NewAuditStore

func NewAuditStore(pool *pgxpool.Pool) *AuditStore

NewAuditStore creates an AuditStore backed by the given pool.

func (*AuditStore) Append

func (s *AuditStore) Append(ctx context.Context, e *model.AuditEntry) error

Append inserts a new audit log entry (append-only by design). Metadata is marshalled to JSONB.

func (*AuditStore) Count

func (s *AuditStore) Count(ctx context.Context, f AuditFilter) (int64, error)

Count returns the number of audit log entries matching the filter.

func (*AuditStore) Query

func (s *AuditStore) Query(ctx context.Context, f AuditFilter) ([]model.AuditEntry, error)

Query returns audit log entries matching the filter, ordered newest-first.

type RetentionStore

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

RetentionStore handles persistence for DataRetention records.

func NewRetentionStore

func NewRetentionStore(pool *pgxpool.Pool) *RetentionStore

NewRetentionStore creates a RetentionStore backed by the given pool.

func (*RetentionStore) GetByTenant

func (s *RetentionStore) GetByTenant(ctx context.Context, tenantID string) ([]model.DataRetention, error)

GetByTenant returns all data retention policies for the given tenant.

func (*RetentionStore) Upsert

func (s *RetentionStore) Upsert(ctx context.Context, tenantID, resourceType string, days int) error

Upsert inserts or updates a data retention policy for (tenantID, resourceType).

type TenantStore

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

TenantStore handles persistence for Tenant records.

func NewTenantStore

func NewTenantStore(pool *pgxpool.Pool) *TenantStore

NewTenantStore creates a TenantStore backed by the given pool.

func (*TenantStore) Create

func (s *TenantStore) Create(ctx context.Context, t *model.Tenant) error

Create inserts a new tenant and populates ID, CreatedAt, and UpdatedAt via RETURNING.

func (*TenantStore) Delete

func (s *TenantStore) Delete(ctx context.Context, id string) error

Delete removes a tenant by primary key.

func (*TenantStore) Get

func (s *TenantStore) Get(ctx context.Context, id string) (*model.Tenant, error)

Get fetches a tenant by primary key.

func (*TenantStore) GetByClerkOrgID

func (s *TenantStore) GetByClerkOrgID(ctx context.Context, clerkOrgID string) (*model.Tenant, error)

GetByClerkOrgID fetches a tenant by Clerk organisation ID.

func (*TenantStore) GetBySlug

func (s *TenantStore) GetBySlug(ctx context.Context, slug string) (*model.Tenant, error)

GetBySlug fetches a tenant by slug.

func (*TenantStore) List

func (s *TenantStore) List(ctx context.Context) ([]model.Tenant, error)

List returns all tenants ordered newest-first.

func (*TenantStore) Update

func (s *TenantStore) Update(ctx context.Context, t *model.Tenant) error

Update persists mutable fields of the given tenant.

type UsageStore

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

UsageStore handles persistence for UsageRecord records.

func NewUsageStore

func NewUsageStore(pool *pgxpool.Pool) *UsageStore

NewUsageStore creates a UsageStore backed by the given pool.

func (*UsageStore) GetByTenant

func (s *UsageStore) GetByTenant(ctx context.Context, tenantID string, start, end time.Time) ([]model.UsageRecord, error)

GetByTenant returns usage records for a tenant within [start, end).

func (*UsageStore) GetCurrentPeriodCount

func (s *UsageStore) GetCurrentPeriodCount(ctx context.Context, tenantID string) (int64, error)

GetCurrentPeriodCount returns the sum of request_count for the current calendar month.

func (*UsageStore) GetUnreported

func (s *UsageStore) GetUnreported(ctx context.Context) ([]model.UsageRecord, error)

GetUnreported returns all usage records that have not been reported to Stripe and whose period_end is in the past.

func (*UsageStore) IncrementRequestCount

func (s *UsageStore) IncrementRequestCount(ctx context.Context, tenantID, appID string) error

IncrementRequestCount upserts a usage record for the current hourly period. It first tries to UPDATE an existing row; if no row exists it INSERTs one.

func (*UsageStore) MarkReported

func (s *UsageStore) MarkReported(ctx context.Context, id string) error

MarkReported sets reported_to_stripe = true for the given record.

func (*UsageStore) PurgeOlderThan

func (s *UsageStore) PurgeOlderThan(ctx context.Context, tenantID string, before time.Time) (int64, error)

PurgeOlderThan deletes reported usage records older than before for the given tenant. Returns the number of rows deleted.

Jump to

Keyboard shortcuts

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