state

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkRow

type ChunkRow struct {
	URL    string
	Dest   string
	Index  int
	Start  int64
	End    int64
	Size   int64
	SHA256 string
	Status string // pending | running | complete | dirty
}

type DB

type DB struct {
	SQL  *sql.DB
	Path string
	// contains filtered or unexported fields
}

func NewDB added in v0.6.1

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

NewDB opens a database at the specified path (for testing)

func Open

func Open(cfg *config.Config) (*DB, error)

func (*DB) ClearHostCaps

func (db *DB) ClearHostCaps() error

ClearHostCaps deletes all host capabilities from the cache.

func (*DB) Close added in v0.6.1

func (db *DB) Close() error

Close closes the database connection

func (*DB) DeleteChunks

func (db *DB) DeleteChunks(url, dest string) error

DeleteChunks removes all chunk rows for a given url+dest pair.

func (*DB) DeleteChunksTx

func (db *DB) DeleteChunksTx(tx *sql.Tx, url, dest string) error

func (*DB) DeleteDownload

func (db *DB) DeleteDownload(url, dest string) error

DeleteDownload removes a download row for the given url+dest.

func (*DB) DeleteHostCaps

func (db *DB) DeleteHostCaps(host string) error

DeleteHostCaps deletes a single host from the cache.

func (*DB) DeleteMetadata added in v0.6.1

func (db *DB) DeleteMetadata(downloadURL string) error

DeleteMetadata removes metadata for a specific download URL

func (*DB) GetHostCaps

func (db *DB) GetHostCaps(host string) (HostCaps, bool, error)

func (*DB) GetMetadata added in v0.6.1

func (db *DB) GetMetadata(downloadURL string) (*ModelMetadata, error)

GetMetadata retrieves metadata for a specific download URL

func (*DB) GetMetadataByDest added in v0.6.1

func (db *DB) GetMetadataByDest(dest string) (*ModelMetadata, error)

GetMetadataByDest retrieves metadata for a specific destination path This is optimized with an index for fast lookups by file path

func (*DB) IncDownloadRetries

func (db *DB) IncDownloadRetries(url, dest string, delta int64) error

IncDownloadRetries increments the retries counter for a download row.

func (*DB) InitChunksTable

func (db *DB) InitChunksTable() error

func (*DB) InitHostCapsTable

func (db *DB) InitHostCapsTable() error

func (*DB) InitMetadataTable added in v0.6.1

func (db *DB) InitMetadataTable() error

InitMetadataTable creates the model_metadata table

func (*DB) ListChunks

func (db *DB) ListChunks(url, dest string) ([]ChunkRow, error)

func (*DB) ListDownloads

func (db *DB) ListDownloads() ([]DownloadRow, error)

ListDownloads returns a snapshot of the downloads table

func (*DB) ListHostCaps

func (db *DB) ListHostCaps() ([]HostCaps, error)

ListHostCaps returns all cached host capabilities.

func (*DB) ListMetadata added in v0.6.1

func (db *DB) ListMetadata(filters MetadataFilters) ([]ModelMetadata, error)

ListMetadata retrieves metadata with optional filters

func (*DB) SearchMetadata added in v0.6.1

func (db *DB) SearchMetadata(query string) ([]ModelMetadata, error)

SearchMetadata performs a full-text search across model metadata

func (*DB) UpdateChunkSHA

func (db *DB) UpdateChunkSHA(url, dest string, idx int, sha string) error

func (*DB) UpdateChunkSHATx

func (db *DB) UpdateChunkSHATx(tx *sql.Tx, url, dest string, idx int, sha string) error

func (*DB) UpdateChunkStatus

func (db *DB) UpdateChunkStatus(url, dest string, idx int, status string) error

func (*DB) UpdateChunkStatusTx

func (db *DB) UpdateChunkStatusTx(tx *sql.Tx, url, dest string, idx int, status string) error

func (*DB) UpdateDownloadStatus

func (db *DB) UpdateDownloadStatus(url, dest, status, lastError string) error

UpdateDownloadStatus updates only status and last_error, preserving other fields.

func (*DB) UpdateMetadataUsage added in v0.6.1

func (db *DB) UpdateMetadataUsage(downloadURL string) error

UpdateMetadataUsage increments usage stats and updates last_used timestamp

func (*DB) UpsertChunk

func (db *DB) UpsertChunk(c ChunkRow) error

func (*DB) UpsertChunkTx

func (db *DB) UpsertChunkTx(tx *sql.Tx, c ChunkRow) error

Tx variants for grouping operations atomically

func (*DB) UpsertDownload

func (db *DB) UpsertDownload(row DownloadRow) error

func (*DB) UpsertHostCaps

func (db *DB) UpsertHostCaps(host string, headOK, acceptRanges bool) error

func (*DB) UpsertMetadata added in v0.6.1

func (db *DB) UpsertMetadata(meta *ModelMetadata) error

UpsertMetadata inserts or updates model metadata

func (*DB) WithTx

func (db *DB) WithTx(fn func(tx *sql.Tx) error) error

WithTx executes fn inside a transaction. If fn returns an error, the transaction is rolled back.

type DownloadRow

type DownloadRow struct {
	URL            string
	Dest           string
	ExpectedSHA256 string
	ActualSHA256   string
	ETag           string
	LastModified   string
	Size           int64
	Status         string
	Retries        int64
	CreatedAt      int64
	UpdatedAt      int64
	LastError      string
}

type HostCaps

type HostCaps struct {
	Host         string
	HeadOK       bool
	AcceptRanges bool
}

type MetadataFilters added in v0.6.1

type MetadataFilters struct {
	Source    string   // Filter by source: "huggingface", "civitai", etc.
	ModelType string   // Filter by type: "LLM", "LoRA", "Checkpoint", etc.
	Favorite  bool     // Show only favorites
	MinRating int      // Minimum user rating (1-5)
	Tags      []string // Filter by tags
	OrderBy   string   // "last_used", "name", "size", "rating", "created_at"
	Limit     int      // Limit results
}

MetadataFilters provides filtering options for ListMetadata

type ModelMetadata added in v0.6.1

type ModelMetadata struct {
	ID int64 `json:"id"`

	// Link to downloads table
	DownloadURL string `json:"download_url"`
	Dest        string `json:"dest,omitempty"` // Destination file path

	// Basic model info
	ModelName string `json:"model_name,omitempty"`
	ModelID   string `json:"model_id,omitempty"` // e.g., "TheBloke/Llama-2-7B-GGUF"
	Version   string `json:"version,omitempty"`  // e.g., "Q4_K_M", "fp16"
	Source    string `json:"source,omitempty"`   // "huggingface", "civitai", "direct"

	// Metadata
	Description string   `json:"description,omitempty"`
	Author      string   `json:"author,omitempty"`
	AuthorURL   string   `json:"author_url,omitempty"`
	License     string   `json:"license,omitempty"`
	Tags        []string `json:"tags,omitempty"`

	// Model specs
	ModelType      string `json:"model_type,omitempty"`      // "LLM", "LoRA", "Checkpoint", "VAE", "Embedding"
	BaseModel      string `json:"base_model,omitempty"`      // "llama-2", "sdxl", etc.
	Architecture   string `json:"architecture,omitempty"`    // "transformer", "unet", etc.
	ParameterCount string `json:"parameter_count,omitempty"` // "7B", "13B", "70B"
	Quantization   string `json:"quantization,omitempty"`    // "Q4_K_M", "Q5_K_S", "fp16"

	// File info
	FileSize   int64  `json:"file_size,omitempty"`
	FileFormat string `json:"file_format,omitempty"` // "gguf", "safetensors", "ckpt", "bin"

	// Usage stats
	DownloadCount int        `json:"download_count"`
	LastUsed      *time.Time `json:"last_used,omitempty"`
	TimesUsed     int        `json:"times_used"`

	// External links
	HomepageURL      string `json:"homepage_url,omitempty"`
	RepoURL          string `json:"repo_url,omitempty"`
	DocumentationURL string `json:"documentation_url,omitempty"`
	ThumbnailURL     string `json:"thumbnail_url,omitempty"`

	// Timestamps
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	// User data
	UserNotes  string `json:"user_notes,omitempty"`
	UserRating int    `json:"user_rating,omitempty"` // 1-5 stars
	Favorite   bool   `json:"favorite"`
}

ModelMetadata stores rich metadata about downloaded models

Jump to

Keyboard shortcuts

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