db

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMigrations

func RunMigrations(ctx context.Context, sqlDB *sql.DB) error

RunMigrations executes all pending schema migrations.

Types

type Channel

type Channel struct {
	ID        int64          `json:"id"`
	ChannelID string         `json:"channel_id"`
	GuildID   string         `json:"guild_id"`
	Name      string         `json:"name"`
	DirPath   string         `json:"dir_path"`
	ParentID  string         `json:"parent_id"`
	Platform  types.Platform `json:"platform"`
	Active    bool           `json:"active"`
	SessionID string         `json:"session_id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}

Channel represents a chat platform channel where the bot operates.

type Message

type Message struct {
	ID          int64     `json:"id"`
	ChatID      int64     `json:"chat_id"`
	ChannelID   string    `json:"channel_id"`
	MsgID       string    `json:"msg_id"`
	AuthorID    string    `json:"author_id"`
	AuthorName  string    `json:"author_name"`
	Content     string    `json:"content"`
	IsBot       bool      `json:"is_bot"`
	IsProcessed bool      `json:"is_processed"`
	CreatedAt   time.Time `json:"created_at"`
}

Message represents a chat message stored for context.

type RunStatus

type RunStatus string

RunStatus represents the execution status of a task run.

const (
	RunStatusPending RunStatus = "pending"
	RunStatusRunning RunStatus = "running"
	RunStatusSuccess RunStatus = "success"
	RunStatusFailed  RunStatus = "failed"
)

type SQLiteStore

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

SQLiteStore implements Store using SQLite.

func NewSQLiteStore

func NewSQLiteStore(dsn string) (*SQLiteStore, error)

NewSQLiteStore opens a SQLite database and returns a new SQLiteStore.

func NewSQLiteStoreFromDB

func NewSQLiteStoreFromDB(sqlDB *sql.DB) *SQLiteStore

NewSQLiteStoreFromDB creates a SQLiteStore from an existing *sql.DB connection.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

func (*SQLiteStore) CreateScheduledTask

func (s *SQLiteStore) CreateScheduledTask(ctx context.Context, task *ScheduledTask) (int64, error)

func (*SQLiteStore) DeleteChannel added in v0.1.12

func (s *SQLiteStore) DeleteChannel(ctx context.Context, channelID string) error

func (*SQLiteStore) DeleteChannelsByParentID added in v0.1.12

func (s *SQLiteStore) DeleteChannelsByParentID(ctx context.Context, parentID string) error

func (*SQLiteStore) DeleteScheduledTask

func (s *SQLiteStore) DeleteScheduledTask(ctx context.Context, id int64) error

func (*SQLiteStore) GetChannel

func (s *SQLiteStore) GetChannel(ctx context.Context, channelID string) (*Channel, error)

func (*SQLiteStore) GetChannelByDirPath

func (s *SQLiteStore) GetChannelByDirPath(ctx context.Context, dirPath string, platform types.Platform) (*Channel, error)

func (*SQLiteStore) GetDueTasks

func (s *SQLiteStore) GetDueTasks(ctx context.Context, now time.Time) ([]*ScheduledTask, error)

func (*SQLiteStore) GetRecentMessages

func (s *SQLiteStore) GetRecentMessages(ctx context.Context, channelID string, limit int) ([]*Message, error)

func (*SQLiteStore) GetScheduledTask

func (s *SQLiteStore) GetScheduledTask(ctx context.Context, id int64) (*ScheduledTask, error)

func (*SQLiteStore) GetScheduledTaskByTemplateName

func (s *SQLiteStore) GetScheduledTaskByTemplateName(ctx context.Context, channelID, templateName string) (*ScheduledTask, error)

func (*SQLiteStore) GetUnprocessedMessages

func (s *SQLiteStore) GetUnprocessedMessages(ctx context.Context, channelID string) ([]*Message, error)

func (*SQLiteStore) InsertMessage

func (s *SQLiteStore) InsertMessage(ctx context.Context, msg *Message) error

func (*SQLiteStore) InsertTaskRunLog

func (s *SQLiteStore) InsertTaskRunLog(ctx context.Context, trl *TaskRunLog) (int64, error)

func (*SQLiteStore) IsChannelActive

func (s *SQLiteStore) IsChannelActive(ctx context.Context, channelID string) (bool, error)

func (*SQLiteStore) ListChannels added in v0.1.15

func (s *SQLiteStore) ListChannels(ctx context.Context) ([]*Channel, error)

func (*SQLiteStore) ListScheduledTasks

func (s *SQLiteStore) ListScheduledTasks(ctx context.Context, channelID string) ([]*ScheduledTask, error)

func (*SQLiteStore) MarkMessagesProcessed

func (s *SQLiteStore) MarkMessagesProcessed(ctx context.Context, ids []int64) error

func (*SQLiteStore) UpdateScheduledTask

func (s *SQLiteStore) UpdateScheduledTask(ctx context.Context, task *ScheduledTask) error

func (*SQLiteStore) UpdateScheduledTaskEnabled

func (s *SQLiteStore) UpdateScheduledTaskEnabled(ctx context.Context, id int64, enabled bool) error

func (*SQLiteStore) UpdateSessionID

func (s *SQLiteStore) UpdateSessionID(ctx context.Context, channelID string, sessionID string) error

func (*SQLiteStore) UpdateTaskRunLog

func (s *SQLiteStore) UpdateTaskRunLog(ctx context.Context, trl *TaskRunLog) error

func (*SQLiteStore) UpsertChannel

func (s *SQLiteStore) UpsertChannel(ctx context.Context, ch *Channel) error

type ScheduledTask

type ScheduledTask struct {
	ID           int64     `json:"id"`
	ChannelID    string    `json:"channel_id"`
	GuildID      string    `json:"guild_id"`
	Schedule     string    `json:"schedule"`
	Type         TaskType  `json:"type"`
	Prompt       string    `json:"prompt"`
	Enabled      bool      `json:"enabled"`
	NextRunAt    time.Time `json:"next_run_at"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	TemplateName string    `json:"template_name"`
}

ScheduledTask represents a task scheduled for execution.

type Store

type Store interface {
	UpsertChannel(ctx context.Context, ch *Channel) error
	GetChannel(ctx context.Context, channelID string) (*Channel, error)
	GetChannelByDirPath(ctx context.Context, dirPath string, platform types.Platform) (*Channel, error)
	IsChannelActive(ctx context.Context, channelID string) (bool, error)
	UpdateSessionID(ctx context.Context, channelID string, sessionID string) error
	DeleteChannel(ctx context.Context, channelID string) error
	DeleteChannelsByParentID(ctx context.Context, parentID string) error
	InsertMessage(ctx context.Context, msg *Message) error
	GetUnprocessedMessages(ctx context.Context, channelID string) ([]*Message, error)
	MarkMessagesProcessed(ctx context.Context, ids []int64) error
	GetRecentMessages(ctx context.Context, channelID string, limit int) ([]*Message, error)
	CreateScheduledTask(ctx context.Context, task *ScheduledTask) (int64, error)
	GetDueTasks(ctx context.Context, now time.Time) ([]*ScheduledTask, error)
	UpdateScheduledTask(ctx context.Context, task *ScheduledTask) error
	DeleteScheduledTask(ctx context.Context, id int64) error
	ListScheduledTasks(ctx context.Context, channelID string) ([]*ScheduledTask, error)
	UpdateScheduledTaskEnabled(ctx context.Context, id int64, enabled bool) error
	GetScheduledTask(ctx context.Context, id int64) (*ScheduledTask, error)
	GetScheduledTaskByTemplateName(ctx context.Context, channelID, templateName string) (*ScheduledTask, error)
	ListChannels(ctx context.Context) ([]*Channel, error)
	InsertTaskRunLog(ctx context.Context, log *TaskRunLog) (int64, error)
	UpdateTaskRunLog(ctx context.Context, log *TaskRunLog) error
	Close() error
}

Store defines all database operations.

type TaskRunLog

type TaskRunLog struct {
	ID           int64     `json:"id"`
	TaskID       int64     `json:"task_id"`
	Status       RunStatus `json:"status"`
	ResponseText string    `json:"response_text"`
	ErrorText    string    `json:"error_text"`
	StartedAt    time.Time `json:"started_at"`
	FinishedAt   time.Time `json:"finished_at"`
}

TaskRunLog records the execution history of a scheduled task.

type TaskType

type TaskType string

TaskType represents the type of scheduled task.

const (
	TaskTypeCron     TaskType = "cron"
	TaskTypeInterval TaskType = "interval"
	TaskTypeOnce     TaskType = "once"
)

Jump to

Keyboard shortcuts

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