database

package
v0.0.0-...-9f81530 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package database provides database access, migration management, and storage operations for the MurailoBot Telegram bot. It uses SQLite for persistent storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseDB

func CloseDB(db *sqlx.DB)

CloseDB safely closes the database connection, logging any errors.

func NewDB

func NewDB(dbPath string) (*sqlx.DB, error)

NewDB initializes and returns a new database connection with migrations applied. It connects to the SQLite database at the given path and runs any pending migrations.

Types

type Message

type Message struct {
	ID          uint         `db:"id"`
	ChatID      int64        `db:"chat_id"`
	UserID      int64        `db:"user_id"`
	Content     string       `db:"content"`
	Timestamp   time.Time    `db:"timestamp"`
	CreatedAt   time.Time    `db:"created_at"`
	UpdatedAt   time.Time    `db:"updated_at"`
	ProcessedAt sql.NullTime `db:"processed_at"`
}

Message represents a chat message stored in the database. It contains both the message content and metadata.

type Store

type Store interface {
	Ping(ctx context.Context) error

	SaveMessage(ctx context.Context, message *Message) error

	RunSQLMaintenance(ctx context.Context) error

	GetUserProfile(ctx context.Context, userID int64) (*UserProfile, error)

	GetAllUserProfiles(ctx context.Context) (map[int64]*UserProfile, error)

	SaveUserProfile(ctx context.Context, profile *UserProfile) error

	GetUnprocessedMessages(ctx context.Context) ([]*Message, error)

	MarkMessagesAsProcessed(ctx context.Context, messageIDs []uint) error

	GetRecentMessages(ctx context.Context, chatID int64, limit int, beforeID uint) ([]*Message, error)

	DeleteAllMessagesAndProfiles(ctx context.Context) error
}

Store defines the interface for database operations used throughout the application. It provides methods for message and user profile management.

func NewStore

func NewStore(db *sqlx.DB, logger *slog.Logger) Store

NewStore creates a new implementation of the Store interface using sqlx. It takes a database connection and logger as dependencies.

type UserProfile

type UserProfile struct {
	ID              uint      `db:"id"`
	UserID          int64     `db:"user_id"`
	Aliases         string    `db:"aliases"`
	OriginLocation  string    `db:"origin_location"`
	CurrentLocation string    `db:"current_location"`
	AgeRange        string    `db:"age_range"`
	Traits          string    `db:"traits"`
	CreatedAt       time.Time `db:"created_at"`
	UpdatedAt       time.Time `db:"updated_at"`
}

UserProfile stores information about a Telegram user based on their messages. It's populated through AI analysis of user interactions and can be edited by admins.

Jump to

Keyboard shortcuts

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