database

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DatabaseName is the SQLite database filename
	DatabaseName = "termonaut.db"

	// DefaultTimeout for database operations
	DefaultTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB wraps the SQLite database connection

func New

func New(dataDir string, logger *logrus.Logger) (*DB, error)

New creates a new database connection

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

func (*DB) GetAllCommands

func (db *DB) GetAllCommands() ([]*models.Command, error)

GetAllCommands returns all commands from the database

func (*DB) GetAllSessions

func (db *DB) GetAllSessions() ([]*models.Session, error)

GetAllSessions returns all sessions from the database

func (*DB) GetBasicStats

func (db *DB) GetBasicStats() (map[string]interface{}, error)

GetBasicStats returns basic usage statistics

func (*DB) GetGamificationStats

func (db *DB) GetGamificationStats() (*gamification.UserStats, error)

GetGamificationStats returns stats needed for gamification calculations

func (*DB) GetOrCreateSession

func (db *DB) GetOrCreateSession(pid int, shellType string) (*models.Session, error)

GetOrCreateSession gets an active session or creates a new one

func (*DB) GetRecentCommands

func (db *DB) GetRecentCommands(limit int) ([]*models.Command, error)

GetRecentCommands returns the most recent commands (limited by count)

func (*DB) GetRecentSessions

func (db *DB) GetRecentSessions(limit int) ([]*models.Session, error)

GetRecentSessions returns the most recent sessions (limited by count)

func (*DB) GetTopCommands

func (db *DB) GetTopCommands(limit int) ([]map[string]interface{}, error)

GetTopCommands returns the most frequently used commands

func (*DB) GetUserAchievements

func (db *DB) GetUserAchievements() (map[string]*gamification.UserAchievement, error)

GetUserAchievements returns all earned achievements

func (*DB) GetUserProgress

func (db *DB) GetUserProgress() (*models.UserProgress, error)

GetUserProgress returns current user progress

func (*DB) Health

func (db *DB) Health() error

Health checks database connectivity

func (*DB) StoreCommand

func (db *DB) StoreCommand(cmd *models.Command) error

StoreCommand saves a command to the database

func (*DB) StoreCommandWithXP

func (db *DB) StoreCommandWithXP(cmd *models.Command) error

StoreCommandWithXP stores a command and calculates XP

func (*DB) UpdateStreakAndCommands

func (db *DB) UpdateStreakAndCommands() error

UpdateStreakAndCommands updates streak and command counts

func (*DB) UpdateUserProgress

func (db *DB) UpdateUserProgress(xpGained int, newAchievements []*gamification.UserAchievement) error

UpdateUserProgress updates user progress with XP and achievements

Jump to

Keyboard shortcuts

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