store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a requested record does not exist.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID        string
	KeyHash   string
	TenantID  string
	Name      string
	CreatedAt time.Time
	RevokedAt *time.Time
}

APIKey represents a row in the sandbox.api_keys table.

type Execution

type Execution struct {
	ID           string          `json:"execution_id"`
	SkillName    string          `json:"skill_name"`
	SkillVersion string          `json:"skill_version"`
	TenantID     string          `json:"tenant_id"`
	Status       string          `json:"status"`
	Input        json.RawMessage `json:"input,omitempty"`
	Output       json.RawMessage `json:"output,omitempty"`
	Logs         string          `json:"logs,omitempty"`
	FilesURL     string          `json:"files_url,omitempty"`
	FilesList    []string        `json:"files_list,omitempty"`
	DurationMs   int64           `json:"duration_ms"`
	Error        *string         `json:"error"`
	CreatedAt    time.Time       `json:"created_at"`
	FinishedAt   *time.Time      `json:"finished_at,omitempty"`
}

Execution represents a row in the sandbox.executions table.

type SkillRecord

type SkillRecord struct {
	TenantID    string    `json:"tenant_id"`
	Name        string    `json:"name"`
	Version     string    `json:"version"`
	Description string    `json:"description"`
	Lang        string    `json:"lang"`
	UploadedAt  time.Time `json:"uploaded_at"`
}

SkillRecord represents a row in the sandbox.skills metadata table.

type Store

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

Store wraps a PostgreSQL connection pool and provides data-access methods for the Skillbox runtime.

func New

func New(dsn string) (*Store, error)

New opens a connection pool to PostgreSQL using the provided DSN, verifies connectivity, and runs all embedded migrations. It returns a ready-to-use Store or an error if any step fails.

func NewWithDB

func NewWithDB(db *sql.DB) *Store

NewWithDB creates a Store that wraps the given *sql.DB without running migrations. This is intended for use in tests that provide a mock or in-memory database.

func (*Store) Close

func (s *Store) Close() error

Close releases the database connection pool.

func (*Store) CreateExecution

func (s *Store) CreateExecution(ctx context.Context, e *Execution) (*Execution, error)

CreateExecution inserts a new execution record with status "running". The Execution is mutated in place with the server-generated ID and timestamp.

func (*Store) CreateKey

func (s *Store) CreateKey(ctx context.Context, tenantID, name, keyHash string) (*APIKey, error)

CreateKey inserts a new API key record and returns the populated APIKey (including the server-generated UUID and timestamp).

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns the underlying *sql.DB for use in tests or advanced queries.

func (*Store) DeleteSkill

func (s *Store) DeleteSkill(ctx context.Context, tenantID, name, version string) error

DeleteSkill removes a skill metadata record.

func (*Store) GetAPIKeyByHash

func (s *Store) GetAPIKeyByHash(ctx context.Context, hash string) (*APIKey, error)

GetAPIKeyByHash looks up an API key by its SHA-256 hex hash. It returns ErrNotFound if no matching key exists.

func (*Store) GetExecution

func (s *Store) GetExecution(ctx context.Context, id string) (*Execution, error)

GetExecution retrieves a single execution by its UUID. Returns ErrNotFound if the execution does not exist.

func (*Store) GetSkill

func (s *Store) GetSkill(ctx context.Context, tenantID, name, version string) (*SkillRecord, error)

GetSkill retrieves a single skill metadata record by tenant, name, and version.

func (*Store) InsertExecution

func (s *Store) InsertExecution(ctx context.Context, e *Execution) error

InsertExecution creates a new execution record. This is an alias kept for compatibility with callers that set status before calling.

func (*Store) ListExecutions

func (s *Store) ListExecutions(ctx context.Context, tenantID string, limit, offset int) ([]Execution, error)

ListExecutions returns executions for a tenant ordered by creation time (newest first), with pagination via limit and offset.

func (*Store) ListKeys

func (s *Store) ListKeys(ctx context.Context, tenantID string) ([]APIKey, error)

ListKeys returns all API keys belonging to the given tenant, ordered by creation time (newest first). Revoked keys are included so the caller can display their status.

func (*Store) ListSkills

func (s *Store) ListSkills(ctx context.Context, tenantID string) ([]SkillRecord, error)

ListSkills returns all skill metadata for a tenant, ordered by name then version.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping verifies the database connection is alive.

func (*Store) RevokeKey

func (s *Store) RevokeKey(ctx context.Context, keyID string) error

RevokeKey soft-deletes an API key by setting its revoked_at timestamp. It returns an error if the key does not exist or is already revoked.

func (*Store) UpdateExecution

func (s *Store) UpdateExecution(ctx context.Context, e *Execution) error

UpdateExecution writes back mutable fields for an existing execution. Typically called once the execution has completed (or timed out).

func (*Store) UpsertSkill

func (s *Store) UpsertSkill(ctx context.Context, rec *SkillRecord) error

UpsertSkill inserts or updates a skill metadata record. On conflict (same tenant, name, version) it updates the description and lang.

func (*Store) ValidateKey

func (s *Store) ValidateKey(ctx context.Context, keyHash string) (*APIKey, error)

ValidateKey looks up an API key by its SHA-256 hash. It returns the matching APIKey if the hash exists and the key has not been revoked. A nil APIKey (with nil error) is returned when the key is not found or has been revoked.

Jump to

Keyboard shortcuts

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