db

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package db provides database operations for storing benchmark results and schedules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB wraps the SQL database connection

func Open

func Open(path string) (*DB, error)

Open creates or opens a SQLite database

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

func (*DB) Conn

func (db *DB) Conn() *sql.DB

Conn returns the underlying database connection

func (*DB) CreateResult

func (db *DB) CreateResult(runID int64, metric string, value float64, unit string) error

CreateResult creates a new result record

func (*DB) CreateResults

func (db *DB) CreateResults(runID int64, metrics map[string]float64, units map[string]string) error

CreateResults creates multiple result records in a transaction

func (*DB) CreateRun

func (db *DB) CreateRun(plugin string, params JSONData) (*Run, error)

CreateRun creates a new test run record

func (*DB) ExportAllCSV

func (db *DB) ExportAllCSV(w io.Writer) error

ExportAllCSV exports all runs and results to CSV format

func (*DB) ExportCSV

func (db *DB) ExportCSV(w io.Writer, runID int64) error

ExportCSV exports results to CSV format

func (*DB) ExportJSON

func (db *DB) ExportJSON(w io.Writer, runID int64) error

ExportJSON exports results to JSON format

func (*DB) GetResults

func (db *DB) GetResults(runID int64) ([]*Result, error)

GetResults retrieves results for a run

func (*DB) GetRun

func (db *DB) GetRun(id int64) (*Run, error)

GetRun retrieves a run by ID

func (*DB) ListResults

func (db *DB) ListResults(filter ResultFilter) ([]*Result, error)

ListResults retrieves results based on filters

func (*DB) ListRuns

func (db *DB) ListRuns(filter RunFilter) ([]*Run, error)

ListRuns retrieves runs based on filters

func (*DB) Migrate

func (db *DB) Migrate() error

Migrate creates or updates the database schema

func (*DB) Path

func (db *DB) Path() string

Path returns the database file path

func (*DB) UpdateRun

func (db *DB) UpdateRun(run *Run) error

UpdateRun updates a test run record

type ExportFormat

type ExportFormat string

ExportFormat represents the format for exporting data

const (
	ExportFormatCSV  ExportFormat = "csv"
	ExportFormatJSON ExportFormat = "json"
)

ExportFormat constants define the available export formats.

type JSONData

type JSONData map[string]interface{}

JSONData is a custom type for storing JSON in SQLite

func (*JSONData) Scan

func (j *JSONData) Scan(value interface{}) error

Scan implements the sql.Scanner interface

func (JSONData) Value

func (j JSONData) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Result

type Result struct {
	ID        int64     `json:"id"`
	RunID     int64     `json:"run_id"`
	Metric    string    `json:"metric"`
	Value     float64   `json:"value"`
	Unit      string    `json:"unit"`
	CreatedAt time.Time `json:"created_at"`
}

Result represents a metric result from a test run

type ResultFilter

type ResultFilter struct {
	RunID  *int64
	Metric string
	Limit  int
	Offset int
}

ResultFilter represents filters for querying results

type Run

type Run struct {
	ID        int64      `json:"id"`
	Plugin    string     `json:"plugin"`
	Params    JSONData   `json:"params"`
	StartTime time.Time  `json:"start_time"`
	EndTime   *time.Time `json:"end_time"`
	ExitCode  int        `json:"exit_code"`
	Success   bool       `json:"success"`
	Error     string     `json:"error,omitempty"`
	Stdout    string     `json:"stdout,omitempty"`
	Stderr    string     `json:"stderr,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
}

Run represents a test execution record

func (*Run) Duration

func (r *Run) Duration() time.Duration

Duration returns the duration of the run

func (*Run) GetStatus

func (r *Run) GetStatus() RunStatus

GetStatus returns the status of a run

type RunFilter

type RunFilter struct {
	Plugin    string
	StartTime *time.Time
	EndTime   *time.Time
	Success   *bool
	Limit     int
	Offset    int
}

RunFilter represents filters for querying runs

type RunStatus

type RunStatus string

RunStatus represents the status of a test run

const (
	RunStatusPending  RunStatus = "pending"
	RunStatusRunning  RunStatus = "running"
	RunStatusComplete RunStatus = "complete"
	RunStatusFailed   RunStatus = "failed"
)

RunStatus constants define the different states of a test run.

Jump to

Keyboard shortcuts

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