Documentation
¶
Overview ¶
Package store provides storage backends for PromptPipe.
This file implements a PostgreSQL-backed store for receipts.
Package store provides storage backends for PromptPipe.
This file implements an SQLite-backed store for receipts and responses.
Package store provides storage backends for PromptPipe.
This file defines the common interfaces and option types used by all store implementations.
Index ¶
- Constants
- func DetectDSNType(dsn string) string
- func ExtractDirFromSQLiteDSN(dsn string) (string, error)
- type InMemoryStore
- func (s *InMemoryStore) AddReceipt(r models.Receipt) error
- func (s *InMemoryStore) AddResponse(r models.Response) error
- func (s *InMemoryStore) ClearReceipts() error
- func (s *InMemoryStore) ClearResponses() error
- func (s *InMemoryStore) Close() error
- func (s *InMemoryStore) DeleteConversationParticipant(id string) error
- func (s *InMemoryStore) DeleteFlowState(participantID, flowType string) error
- func (s *InMemoryStore) DeleteRegisteredHook(phoneNumber string) error
- func (s *InMemoryStore) GetConversationParticipant(id string) (*models.ConversationParticipant, error)
- func (s *InMemoryStore) GetConversationParticipantByPhone(phoneNumber string) (*models.ConversationParticipant, error)
- func (s *InMemoryStore) GetFlowState(participantID, flowType string) (*models.FlowState, error)
- func (s *InMemoryStore) GetReceipts() ([]models.Receipt, error)
- func (s *InMemoryStore) GetRegisteredHook(phoneNumber string) (*models.RegisteredHook, error)
- func (s *InMemoryStore) GetResponses() ([]models.Response, error)
- func (s *InMemoryStore) ListConversationParticipants() ([]models.ConversationParticipant, error)
- func (s *InMemoryStore) ListRegisteredHooks() ([]models.RegisteredHook, error)
- func (s *InMemoryStore) SaveConversationParticipant(participant models.ConversationParticipant) error
- func (s *InMemoryStore) SaveFlowState(state models.FlowState) error
- func (s *InMemoryStore) SaveRegisteredHook(hook models.RegisteredHook) error
- type Option
- type Opts
- type PostgresStore
- func (s *PostgresStore) AddReceipt(r models.Receipt) error
- func (s *PostgresStore) AddResponse(r models.Response) error
- func (s *PostgresStore) ClearReceipts() error
- func (s *PostgresStore) ClearResponses() error
- func (s *PostgresStore) Close() error
- func (s *PostgresStore) DeleteConversationParticipant(id string) error
- func (s *PostgresStore) DeleteFlowState(participantID, flowType string) error
- func (s *PostgresStore) DeleteRegisteredHook(phoneNumber string) error
- func (s *PostgresStore) GetConversationParticipant(id string) (*models.ConversationParticipant, error)
- func (s *PostgresStore) GetConversationParticipantByPhone(phoneNumber string) (*models.ConversationParticipant, error)
- func (s *PostgresStore) GetFlowState(participantID, flowType string) (*models.FlowState, error)
- func (s *PostgresStore) GetReceipts() ([]models.Receipt, error)
- func (s *PostgresStore) GetRegisteredHook(phoneNumber string) (*models.RegisteredHook, error)
- func (s *PostgresStore) GetResponses() ([]models.Response, error)
- func (s *PostgresStore) ListConversationParticipants() ([]models.ConversationParticipant, error)
- func (s *PostgresStore) ListRegisteredHooks() ([]models.RegisteredHook, error)
- func (s *PostgresStore) SaveConversationParticipant(participant models.ConversationParticipant) error
- func (s *PostgresStore) SaveFlowState(state models.FlowState) error
- func (s *PostgresStore) SaveRegisteredHook(hook models.RegisteredHook) error
- type SQLiteStore
- func (s *SQLiteStore) AddReceipt(r models.Receipt) error
- func (s *SQLiteStore) AddResponse(r models.Response) error
- func (s *SQLiteStore) ClearReceipts() error
- func (s *SQLiteStore) ClearResponses() error
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) DeleteConversationParticipant(id string) error
- func (s *SQLiteStore) DeleteFlowState(participantID, flowType string) error
- func (s *SQLiteStore) DeleteRegisteredHook(phoneNumber string) error
- func (s *SQLiteStore) GetConversationParticipant(id string) (*models.ConversationParticipant, error)
- func (s *SQLiteStore) GetConversationParticipantByPhone(phoneNumber string) (*models.ConversationParticipant, error)
- func (s *SQLiteStore) GetFlowState(participantID, flowType string) (*models.FlowState, error)
- func (s *SQLiteStore) GetReceipts() ([]models.Receipt, error)
- func (s *SQLiteStore) GetRegisteredHook(phoneNumber string) (*models.RegisteredHook, error)
- func (s *SQLiteStore) GetResponses() ([]models.Response, error)
- func (s *SQLiteStore) ListConversationParticipants() ([]models.ConversationParticipant, error)
- func (s *SQLiteStore) ListRegisteredHooks() ([]models.RegisteredHook, error)
- func (s *SQLiteStore) SaveConversationParticipant(participant models.ConversationParticipant) error
- func (s *SQLiteStore) SaveFlowState(state models.FlowState) error
- func (s *SQLiteStore) SaveRegisteredHook(hook models.RegisteredHook) error
- type Store
Constants ¶
const ( // DefaultMaxOpenConns is the default maximum number of open connections to the database DefaultMaxOpenConns = 25 // DefaultMaxIdleConns is the default maximum number of idle connections in the pool DefaultMaxIdleConns = 25 // DefaultConnMaxLifetime is the default maximum amount of time a connection may be reused DefaultConnMaxLifetime = 5 * time.Minute )
Database connection pool configuration constants
const ( // DefaultDirPermissions defines the default permissions for database directories DefaultDirPermissions = 0755 // SQLiteMaxOpenConns is the maximum number of open connections for SQLite (should be 1 for WAL mode safety) SQLiteMaxOpenConns = 1 // SQLiteMaxIdleConns is the maximum number of idle connections for SQLite SQLiteMaxIdleConns = 1 // SQLiteConnMaxLifetime is the maximum amount of time a SQLite connection may be reused SQLiteConnMaxLifetime = 30 * time.Minute )
Constants for SQLite store configuration
Variables ¶
This section is empty.
Functions ¶
func DetectDSNType ¶
DetectDSNType analyzes a DSN and returns the appropriate database driver. Returns "postgres" for PostgreSQL DSNs, "sqlite3" for SQLite file paths.
func ExtractDirFromSQLiteDSN ¶
ExtractDirFromSQLiteDSN extracts the directory path from a SQLite DSN string, handling both file URIs (e.g., "file:/path/to/file?_foreign_keys=on") and regular file paths. This function is specifically designed for SQLite DSNs and will return an error if called with non-SQLite DSNs (e.g., PostgreSQL DSNs). Returns the directory containing the SQLite database file, or an error if: - The DSN is not a SQLite DSN - The file URI cannot be parsed - The resulting path is invalid
Types ¶
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore is a simple in-memory implementation of the Store interface. Data is stored in memory and will be lost when the application restarts.
func NewInMemoryStore ¶
func NewInMemoryStore() *InMemoryStore
NewInMemoryStore creates a new in-memory store.
func (*InMemoryStore) AddReceipt ¶
func (s *InMemoryStore) AddReceipt(r models.Receipt) error
AddReceipt stores a receipt in memory.
func (*InMemoryStore) AddResponse ¶
func (s *InMemoryStore) AddResponse(r models.Response) error
AddResponse stores an incoming response in memory.
func (*InMemoryStore) ClearReceipts ¶
func (s *InMemoryStore) ClearReceipts() error
ClearReceipts clears all stored receipts (for tests).
func (*InMemoryStore) ClearResponses ¶
func (s *InMemoryStore) ClearResponses() error
ClearResponses clears all stored responses (for tests).
func (*InMemoryStore) Close ¶
func (s *InMemoryStore) Close() error
Close is a no-op for in-memory store as there are no resources to clean up.
func (*InMemoryStore) DeleteConversationParticipant ¶
func (s *InMemoryStore) DeleteConversationParticipant(id string) error
DeleteConversationParticipant removes a conversation participant.
func (*InMemoryStore) DeleteFlowState ¶
func (s *InMemoryStore) DeleteFlowState(participantID, flowType string) error
DeleteFlowState removes flow state for a participant.
func (*InMemoryStore) DeleteRegisteredHook ¶
func (s *InMemoryStore) DeleteRegisteredHook(phoneNumber string) error
DeleteRegisteredHook removes a registered hook by phone number.
func (*InMemoryStore) GetConversationParticipant ¶
func (s *InMemoryStore) GetConversationParticipant(id string) (*models.ConversationParticipant, error)
GetConversationParticipant retrieves a conversation participant by ID.
func (*InMemoryStore) GetConversationParticipantByPhone ¶
func (s *InMemoryStore) GetConversationParticipantByPhone(phoneNumber string) (*models.ConversationParticipant, error)
GetConversationParticipantByPhone retrieves a conversation participant by phone number.
func (*InMemoryStore) GetFlowState ¶
func (s *InMemoryStore) GetFlowState(participantID, flowType string) (*models.FlowState, error)
GetFlowState retrieves flow state for a participant.
func (*InMemoryStore) GetReceipts ¶
func (s *InMemoryStore) GetReceipts() ([]models.Receipt, error)
GetReceipts retrieves all stored receipts from memory.
func (*InMemoryStore) GetRegisteredHook ¶
func (s *InMemoryStore) GetRegisteredHook(phoneNumber string) (*models.RegisteredHook, error)
GetRegisteredHook retrieves a registered hook by phone number.
func (*InMemoryStore) GetResponses ¶
func (s *InMemoryStore) GetResponses() ([]models.Response, error)
GetResponses retrieves all stored responses from memory.
func (*InMemoryStore) ListConversationParticipants ¶
func (s *InMemoryStore) ListConversationParticipants() ([]models.ConversationParticipant, error)
ListConversationParticipants retrieves all conversation participants.
func (*InMemoryStore) ListRegisteredHooks ¶
func (s *InMemoryStore) ListRegisteredHooks() ([]models.RegisteredHook, error)
ListRegisteredHooks retrieves all registered hooks.
func (*InMemoryStore) SaveConversationParticipant ¶
func (s *InMemoryStore) SaveConversationParticipant(participant models.ConversationParticipant) error
SaveConversationParticipant stores or updates a conversation participant.
func (*InMemoryStore) SaveFlowState ¶
func (s *InMemoryStore) SaveFlowState(state models.FlowState) error
SaveFlowState stores or updates flow state for a participant.
func (*InMemoryStore) SaveRegisteredHook ¶
func (s *InMemoryStore) SaveRegisteredHook(hook models.RegisteredHook) error
SaveRegisteredHook stores a registered hook.
type Option ¶
type Option func(*Opts)
Option defines a configuration option for store implementations.
func WithPostgresDSN ¶
WithPostgresDSN sets the PostgreSQL database connection string.
func WithSQLiteDSN ¶
WithSQLiteDSN sets the SQLite database file path.
type Opts ¶
type Opts struct {
DSN string // Database connection string or file path for SQLite
}
Opts holds configuration options for store implementations.
type PostgresStore ¶
type PostgresStore struct {
// contains filtered or unexported fields
}
func NewPostgresStore ¶
func NewPostgresStore(opts ...Option) (*PostgresStore, error)
NewPostgresStore creates a new Postgres store based on provided options.
func (*PostgresStore) AddReceipt ¶
func (s *PostgresStore) AddReceipt(r models.Receipt) error
func (*PostgresStore) AddResponse ¶
func (s *PostgresStore) AddResponse(r models.Response) error
AddResponse stores an incoming response in Postgres.
func (*PostgresStore) ClearReceipts ¶
func (s *PostgresStore) ClearReceipts() error
ClearReceipts deletes all records in receipts table (for tests).
func (*PostgresStore) ClearResponses ¶
func (s *PostgresStore) ClearResponses() error
ClearResponses deletes all records in responses table (for tests).
func (*PostgresStore) Close ¶
func (s *PostgresStore) Close() error
Close closes the PostgreSQL database connection.
func (*PostgresStore) DeleteConversationParticipant ¶
func (s *PostgresStore) DeleteConversationParticipant(id string) error
DeleteConversationParticipant removes a conversation participant.
func (*PostgresStore) DeleteFlowState ¶
func (s *PostgresStore) DeleteFlowState(participantID, flowType string) error
DeleteFlowState removes flow state for a participant.
func (*PostgresStore) DeleteRegisteredHook ¶
func (s *PostgresStore) DeleteRegisteredHook(phoneNumber string) error
DeleteRegisteredHook deletes a registered hook by phone number
func (*PostgresStore) GetConversationParticipant ¶
func (s *PostgresStore) GetConversationParticipant(id string) (*models.ConversationParticipant, error)
GetConversationParticipant retrieves a conversation participant by ID.
func (*PostgresStore) GetConversationParticipantByPhone ¶
func (s *PostgresStore) GetConversationParticipantByPhone(phoneNumber string) (*models.ConversationParticipant, error)
GetConversationParticipantByPhone retrieves a conversation participant by phone number.
func (*PostgresStore) GetFlowState ¶
func (s *PostgresStore) GetFlowState(participantID, flowType string) (*models.FlowState, error)
GetFlowState retrieves flow state for a participant.
func (*PostgresStore) GetReceipts ¶
func (s *PostgresStore) GetReceipts() ([]models.Receipt, error)
func (*PostgresStore) GetRegisteredHook ¶
func (s *PostgresStore) GetRegisteredHook(phoneNumber string) (*models.RegisteredHook, error)
GetRegisteredHook retrieves a registered hook by phone number
func (*PostgresStore) GetResponses ¶
func (s *PostgresStore) GetResponses() ([]models.Response, error)
GetResponses retrieves all stored responses from Postgres.
func (*PostgresStore) ListConversationParticipants ¶
func (s *PostgresStore) ListConversationParticipants() ([]models.ConversationParticipant, error)
ListConversationParticipants retrieves all conversation participants.
func (*PostgresStore) ListRegisteredHooks ¶
func (s *PostgresStore) ListRegisteredHooks() ([]models.RegisteredHook, error)
ListRegisteredHooks retrieves all registered hooks
func (*PostgresStore) SaveConversationParticipant ¶
func (s *PostgresStore) SaveConversationParticipant(participant models.ConversationParticipant) error
SaveConversationParticipant stores or updates a conversation participant.
func (*PostgresStore) SaveFlowState ¶
func (s *PostgresStore) SaveFlowState(state models.FlowState) error
SaveFlowState stores or updates flow state for a participant.
func (*PostgresStore) SaveRegisteredHook ¶
func (s *PostgresStore) SaveRegisteredHook(hook models.RegisteredHook) error
SaveRegisteredHook stores or updates a registered hook.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
func NewSQLiteStore ¶
func NewSQLiteStore(opts ...Option) (*SQLiteStore, error)
NewSQLiteStore creates a new SQLite store with the given DSN. The DSN should be a file path to the SQLite database file. If the directory doesn't exist, it will be created.
func (*SQLiteStore) AddReceipt ¶
func (s *SQLiteStore) AddReceipt(r models.Receipt) error
func (*SQLiteStore) AddResponse ¶
func (s *SQLiteStore) AddResponse(r models.Response) error
func (*SQLiteStore) ClearReceipts ¶
func (s *SQLiteStore) ClearReceipts() error
ClearReceipts deletes all records in receipts table (for tests).
func (*SQLiteStore) ClearResponses ¶
func (s *SQLiteStore) ClearResponses() error
ClearResponses deletes all records in responses table (for tests).
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
Close closes the SQLite database connection.
func (*SQLiteStore) DeleteConversationParticipant ¶
func (s *SQLiteStore) DeleteConversationParticipant(id string) error
DeleteConversationParticipant removes a conversation participant.
func (*SQLiteStore) DeleteFlowState ¶
func (s *SQLiteStore) DeleteFlowState(participantID, flowType string) error
DeleteFlowState removes flow state for a participant.
func (*SQLiteStore) DeleteRegisteredHook ¶
func (s *SQLiteStore) DeleteRegisteredHook(phoneNumber string) error
DeleteRegisteredHook removes a registered hook by phone number.
func (*SQLiteStore) GetConversationParticipant ¶
func (s *SQLiteStore) GetConversationParticipant(id string) (*models.ConversationParticipant, error)
GetConversationParticipant retrieves a conversation participant by ID.
func (*SQLiteStore) GetConversationParticipantByPhone ¶
func (s *SQLiteStore) GetConversationParticipantByPhone(phoneNumber string) (*models.ConversationParticipant, error)
GetConversationParticipantByPhone retrieves a conversation participant by phone number.
func (*SQLiteStore) GetFlowState ¶
func (s *SQLiteStore) GetFlowState(participantID, flowType string) (*models.FlowState, error)
GetFlowState retrieves flow state for a participant.
func (*SQLiteStore) GetReceipts ¶
func (s *SQLiteStore) GetReceipts() ([]models.Receipt, error)
func (*SQLiteStore) GetRegisteredHook ¶
func (s *SQLiteStore) GetRegisteredHook(phoneNumber string) (*models.RegisteredHook, error)
GetRegisteredHook retrieves a registered hook by phone number.
func (*SQLiteStore) GetResponses ¶
func (s *SQLiteStore) GetResponses() ([]models.Response, error)
func (*SQLiteStore) ListConversationParticipants ¶
func (s *SQLiteStore) ListConversationParticipants() ([]models.ConversationParticipant, error)
ListConversationParticipants retrieves all conversation participants.
func (*SQLiteStore) ListRegisteredHooks ¶
func (s *SQLiteStore) ListRegisteredHooks() ([]models.RegisteredHook, error)
ListRegisteredHooks retrieves all registered hooks.
func (*SQLiteStore) SaveConversationParticipant ¶
func (s *SQLiteStore) SaveConversationParticipant(participant models.ConversationParticipant) error
SaveConversationParticipant stores or updates a conversation participant.
func (*SQLiteStore) SaveFlowState ¶
func (s *SQLiteStore) SaveFlowState(state models.FlowState) error
SaveFlowState stores or updates flow state for a participant.
func (*SQLiteStore) SaveRegisteredHook ¶
func (s *SQLiteStore) SaveRegisteredHook(hook models.RegisteredHook) error
SaveRegisteredHook stores or updates a registered hook.
type Store ¶
type Store interface { AddReceipt(r models.Receipt) error GetReceipts() ([]models.Receipt, error) AddResponse(r models.Response) error GetResponses() ([]models.Response, error) ClearReceipts() error // for tests ClearResponses() error // for tests Close() error // for proper resource cleanup // Flow state management SaveFlowState(state models.FlowState) error GetFlowState(participantID, flowType string) (*models.FlowState, error) DeleteFlowState(participantID, flowType string) error // Conversation participant management SaveConversationParticipant(participant models.ConversationParticipant) error GetConversationParticipant(id string) (*models.ConversationParticipant, error) GetConversationParticipantByPhone(phoneNumber string) (*models.ConversationParticipant, error) ListConversationParticipants() ([]models.ConversationParticipant, error) DeleteConversationParticipant(id string) error // Response hook persistence management SaveRegisteredHook(hook models.RegisteredHook) error GetRegisteredHook(phoneNumber string) (*models.RegisteredHook, error) ListRegisteredHooks() ([]models.RegisteredHook, error) DeleteRegisteredHook(phoneNumber string) error }
Store defines the interface for storing receipts, responses, and flow state.