- Add CLI entry point with urfave/cli/v2 (serve, index, list, search commands) - Add database interface and implementations for PostgreSQL and SQLite - Add schema versioning with automatic recreation on version mismatch - Add MCP protocol types and server scaffold - Add NixOS option types - Configure flake.nix with devShell and buildGoModule package Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
// Package database provides database abstraction for storing NixOS options.
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Revision represents an indexed nixpkgs revision.
|
|
type Revision struct {
|
|
ID int64
|
|
GitHash string
|
|
ChannelName string
|
|
CommitDate time.Time
|
|
IndexedAt time.Time
|
|
OptionCount int
|
|
}
|
|
|
|
// Option represents a NixOS configuration option.
|
|
type Option struct {
|
|
ID int64
|
|
RevisionID int64
|
|
Name string
|
|
ParentPath string
|
|
Type string
|
|
DefaultValue string // JSON text
|
|
Example string // JSON text
|
|
Description string
|
|
ReadOnly bool
|
|
}
|
|
|
|
// Declaration represents a file where an option is declared.
|
|
type Declaration struct {
|
|
ID int64
|
|
OptionID int64
|
|
FilePath string
|
|
Line int
|
|
}
|
|
|
|
// File represents a cached file from nixpkgs.
|
|
type File struct {
|
|
ID int64
|
|
RevisionID int64
|
|
FilePath string
|
|
Extension string
|
|
Content string
|
|
}
|
|
|
|
// SearchFilters contains optional filters for option search.
|
|
type SearchFilters struct {
|
|
Type string
|
|
Namespace string
|
|
HasDefault *bool
|
|
Limit int
|
|
Offset int
|
|
}
|
|
|
|
// Store defines the interface for database operations.
|
|
type Store interface {
|
|
// Schema operations
|
|
Initialize(ctx context.Context) error
|
|
Close() error
|
|
|
|
// Revision operations
|
|
CreateRevision(ctx context.Context, rev *Revision) error
|
|
GetRevision(ctx context.Context, gitHash string) (*Revision, error)
|
|
GetRevisionByChannel(ctx context.Context, channel string) (*Revision, error)
|
|
ListRevisions(ctx context.Context) ([]*Revision, error)
|
|
DeleteRevision(ctx context.Context, id int64) error
|
|
UpdateRevisionOptionCount(ctx context.Context, id int64, count int) error
|
|
|
|
// Option operations
|
|
CreateOption(ctx context.Context, opt *Option) error
|
|
CreateOptionsBatch(ctx context.Context, opts []*Option) error
|
|
GetOption(ctx context.Context, revisionID int64, name string) (*Option, error)
|
|
GetChildren(ctx context.Context, revisionID int64, parentPath string) ([]*Option, error)
|
|
SearchOptions(ctx context.Context, revisionID int64, query string, filters SearchFilters) ([]*Option, error)
|
|
|
|
// Declaration operations
|
|
CreateDeclaration(ctx context.Context, decl *Declaration) error
|
|
CreateDeclarationsBatch(ctx context.Context, decls []*Declaration) error
|
|
GetDeclarations(ctx context.Context, optionID int64) ([]*Declaration, error)
|
|
|
|
// File operations
|
|
CreateFile(ctx context.Context, file *File) error
|
|
CreateFilesBatch(ctx context.Context, files []*File) error
|
|
GetFile(ctx context.Context, revisionID int64, path string) (*File, error)
|
|
}
|