storage

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package storage provides database persistence for pulse data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DB

func DB(ctx context.Context) (*sqlx.DB, error)

DB will return the sqlx.DB in use for the pulse module. This enables reuse of the storage package from outside the app without exposing implementation detail.

func Migrate

func Migrate(ctx context.Context, db *sqlx.DB, schema fs.FS) error

Migrate runs SQL migrations for the pulse database.

Types

type DailyHostCount

type DailyHostCount struct {
	Hostname string `db:"hostname" json:"hostname"`
	Stamp    string `db:"stamp" json:"stamp"`
	Count    int64  `db:"count" json:"count"`
}

DailyHostCount holds daily keystroke data per host.

type HourlyCount

type HourlyCount struct {
	Hour  int   `db:"hour" json:"hour"`
	Count int64 `db:"count" json:"count"`
}

HourlyCount holds hourly keystroke data.

type Storage

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

Storage provides pulse data persistence.

func NewStorage

func NewStorage(db *sqlx.DB) *Storage

NewStorage creates a new storage backed by the given database.

func (*Storage) GetUserDaily

func (s *Storage) GetUserDaily(ctx context.Context, userID string) ([]DailyHostCount, error)

GetUserDaily returns daily keystroke counts per host for a user over the last 30 days.

func (*Storage) GetUserHosts

func (s *Storage) GetUserHosts(ctx context.Context, userID string) ([]string, error)

GetUserHosts returns all hostnames for a user.

func (*Storage) GetUserHourly

func (s *Storage) GetUserHourly(ctx context.Context, userID string) ([]HourlyCount, error)

GetUserHourly returns hourly keystroke distribution for a user (aggregated across all days).

func (*Storage) GetUserHourlyAll

func (s *Storage) GetUserHourlyAll(ctx context.Context, userID string) ([]DailyHostCount, error)

GetUserHourlyAll returns hourly keystroke counts per host for a user over the last 30 days.

func (*Storage) GetUserHourlyByHost

func (s *Storage) GetUserHourlyByHost(ctx context.Context, userID string, hostname string) ([]DailyHostCount, error)

GetUserHourlyByHost returns hourly keystroke counts per host for a user over the last 48 hours.

func (*Storage) ListUserCounts

func (s *Storage) ListUserCounts(ctx context.Context) ([]UserCount, error)

ListUserCounts returns the total keystroke count per user for the last 30 days.

func (*Storage) Pulse

func (s *Storage) Pulse(ctx context.Context, count int64, hostname string) error

Pulse records keystroke activity for the authenticated user.

type UserCount

type UserCount struct {
	UserID string `db:"user_id"`
	Count  int64  `db:"count"`
}

UserCount holds a user's total keystroke count.

Jump to

Keyboard shortcuts

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