storage

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package storage provides database operations for conversations, messages, and metadata. ABOUTME: Conversation CRUD operations for SQLite storage ABOUTME: Create, read, update, delete, and list conversations

Package storage provides database operations for conversations, messages, and metadata. ABOUTME: Repository for command history with FTS5 full-text search ABOUTME: Manages storage and retrieval of user messages and assistant responses

Package storage provides database operations for conversations, messages, and metadata. ABOUTME: Message CRUD operations for SQLite storage ABOUTME: Create, read, and list messages within conversations

Package storage provides database operations for conversations, messages, and metadata. ABOUTME: SQLite schema initialization and migration management ABOUTME: Handles database setup, table creation, and version tracking

Package storage provides database operations for conversations, messages, and metadata. ABOUTME: Todo repository for CRUD operations on todo items ABOUTME: Handles saving, loading, and clearing todo lists with optional conversation scoping

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHistoryEntry

func AddHistoryEntry(db *sql.DB, entry *HistoryEntry) error

AddHistoryEntry saves a history entry to the database

func ClearCompleted

func ClearCompleted(db *sql.DB, conversationID *string) error

ClearCompleted removes all completed todos for the given conversation (or global if nil)

func CreateConversation

func CreateConversation(db *sql.DB, conv *Conversation) error

CreateConversation inserts a new conversation

func CreateMessage

func CreateMessage(db *sql.DB, msg *Message) error

CreateMessage inserts a new message and updates conversation timestamp atomically

func DeleteConversation

func DeleteConversation(db *sql.DB, id string) error

DeleteConversation deletes a conversation and its messages (via CASCADE)

func OpenDatabase

func OpenDatabase(path string) (*sql.DB, error)

OpenDatabase opens SQLite database at given path

func RunMigrations added in v1.4.0

func RunMigrations(db *sql.DB) error

RunMigrations executes database migrations using golang-migrate

func SaveTodos

func SaveTodos(db *sql.DB, todos []Todo, conversationID *string) error

SaveTodos replaces all todos for the given conversation (or global if nil) with the provided list

func SetFavorite

func SetFavorite(db *sql.DB, id string, isFavorite bool) error

SetFavorite sets or unsets a conversation as favorite

func UpdateConversationTimestamp

func UpdateConversationTimestamp(db *sql.DB, id string) error

UpdateConversationTimestamp updates the updated_at field

func UpdateConversationTitle

func UpdateConversationTitle(db *sql.DB, id, title string) error

UpdateConversationTitle updates the title of a conversation

Types

type Conversation

type Conversation struct {
	ID           string
	Title        string
	Provider     string
	Model        string
	SystemPrompt string
	CreatedAt    time.Time
	UpdatedAt    time.Time
	IsFavorite   bool
}

Conversation represents a chat conversation

func GetConversation

func GetConversation(db *sql.DB, id string) (*Conversation, error)

GetConversation retrieves a conversation by ID

func GetLatestConversation

func GetLatestConversation(db *sql.DB) (*Conversation, error)

GetLatestConversation retrieves the most recently updated conversation

func ListConversations

func ListConversations(db *sql.DB, limit, offset int) ([]*Conversation, error)

ListConversations returns conversations ordered by updated_at DESC

func ListFavorites

func ListFavorites(db *sql.DB) ([]*Conversation, error)

ListFavorites returns all favorite conversations ordered by updated_at DESC

type HistoryEntry

type HistoryEntry struct {
	ID                string
	ConversationID    string
	UserMessage       string
	AssistantResponse string
	CreatedAt         time.Time
}

HistoryEntry represents a single command history entry

func GetRecentHistory

func GetRecentHistory(db *sql.DB, limit int) ([]*HistoryEntry, error)

GetRecentHistory retrieves the most recent history entries

func SearchHistory

func SearchHistory(db *sql.DB, query string, limit int) ([]*HistoryEntry, error)

SearchHistory performs FTS5 search on history

type Message

type Message struct {
	ID             string
	ConversationID string
	Role           string
	Content        string
	ToolCalls      string // JSON string
	Metadata       string // JSON string
	CreatedAt      time.Time
}

Message represents a chat message

func GetMessage

func GetMessage(db *sql.DB, id string) (*Message, error)

GetMessage retrieves a message by ID

func ListMessages

func ListMessages(db *sql.DB, conversationID string) ([]*Message, error)

ListMessages returns all messages for a conversation ordered by created_at

type Todo

type Todo struct {
	ID             string
	Content        string
	ActiveForm     string
	Status         string // "pending", "in_progress", "completed"
	ConversationID *string
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

Todo represents a single todo item

func LoadTodos

func LoadTodos(db *sql.DB, conversationID *string) ([]Todo, error)

LoadTodos retrieves all todos for the given conversation (or global if nil), ordered by created_at ASC

Jump to

Keyboard shortcuts

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