store

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentHash

func ContentHash(data string) string

ContentHash returns the hex-encoded SHA-256 hash of the given data.

func DefaultDataDir

func DefaultDataDir() (string, error)

DefaultDataDir returns ~/.local/share/nebi/ on Linux, platform equivalent elsewhere.

func MigrateServerDB

func MigrateServerDB(db *gorm.DB) error

MigrateServerDB creates store tables on an external DB (used by local-mode server).

func TomlContentHash

func TomlContentHash(data string) (string, error)

TomlContentHash parses data as TOML, canonicalizes it via sorted-key JSON, and returns the hex-encoded SHA-256 hash. This makes the hash insensitive to whitespace and formatting differences in the TOML source.

Types

type Config

type Config struct {
	ID        int    `gorm:"primarykey"`
	ServerURL string `gorm:"not null;default:''"`
}

Config is a singleton table for store configuration (server URL).

func (Config) TableName

func (Config) TableName() string

type Credentials

type Credentials struct {
	ID       int    `gorm:"primarykey"`
	Token    string `gorm:"not null;default:''"`
	Username string `gorm:"not null;default:''"`
}

Credentials stores auth info for the configured nebi server.

func (Credentials) TableName

func (Credentials) TableName() string

type LocalWorkspace

type LocalWorkspace struct {
	ID             uuid.UUID      `gorm:"type:text;primary_key" json:"id"`
	Name           string         `gorm:"not null" json:"name"`
	Status         string         `gorm:"not null;default:'ready'" json:"status"`
	PackageManager string         `gorm:"not null" json:"package_manager"`
	Path           string         `gorm:"" json:"path,omitempty"`
	Source         string         `gorm:"default:'managed'" json:"source"`
	OriginID       string         `json:"origin_id,omitempty"`
	OriginName     string         `json:"origin_name,omitempty"`
	OriginTag      string         `json:"origin_tag,omitempty"`
	OriginAction   string         `json:"origin_action,omitempty"`
	OriginTomlHash string         `json:"origin_toml_hash,omitempty"`
	OriginLockHash string         `json:"origin_lock_hash,omitempty"`
	CreatedAt      time.Time      `json:"created_at"`
	UpdatedAt      time.Time      `json:"updated_at"`
	DeletedAt      gorm.DeletedAt `gorm:"index" json:"-"`
}

LocalWorkspace represents a workspace tracked by the CLI in its local SQLite database. This is separate from models.Workspace which is used by the server.

func (*LocalWorkspace) BeforeCreate

func (w *LocalWorkspace) BeforeCreate(tx *gorm.DB) error

BeforeCreate hook to generate UUID.

func (LocalWorkspace) TableName

func (LocalWorkspace) TableName() string

TableName ensures GORM uses the "workspaces" table.

type Store

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

Store manages the local nebi SQLite database via GORM.

func New

func New() (*Store, error)

New creates a Store using the default platform data directory.

func Open

func Open(dataDir string) (*Store, error)

Open creates a Store with a specific data directory.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) CreateWorkspace

func (s *Store) CreateWorkspace(ws *LocalWorkspace) error

CreateWorkspace creates a new workspace record.

func (*Store) DB

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

DB returns the underlying GORM DB for advanced queries.

func (*Store) DataDir

func (s *Store) DataDir() string

DataDir returns the store's data directory.

func (*Store) DeleteWorkspace

func (s *Store) DeleteWorkspace(id uuid.UUID) error

DeleteWorkspace removes a workspace by ID (hard delete).

func (*Store) FindWorkspaceByName

func (s *Store) FindWorkspaceByName(name string) (*LocalWorkspace, error)

FindWorkspaceByName returns the first workspace with the given name, or nil if not found.

func (*Store) FindWorkspaceByPath

func (s *Store) FindWorkspaceByPath(path string) (*LocalWorkspace, error)

FindWorkspaceByPath returns the workspace at the given path, or nil if not found.

func (*Store) FindWorkspacesByName

func (s *Store) FindWorkspacesByName(name string) ([]LocalWorkspace, error)

FindWorkspacesByName returns all workspaces with the given name. Multiple workspaces can share the same name since path is the unique identifier.

func (*Store) GetWorkspace

func (s *Store) GetWorkspace(id uuid.UUID) (*LocalWorkspace, error)

GetWorkspace returns a workspace by ID.

func (*Store) ListWorkspaces

func (s *Store) ListWorkspaces() ([]LocalWorkspace, error)

ListWorkspaces returns all workspaces.

func (*Store) LoadCredentials

func (s *Store) LoadCredentials() (*Credentials, error)

LoadCredentials reads stored credentials.

func (*Store) LoadServerURL

func (s *Store) LoadServerURL() (string, error)

LoadServerURL returns the configured server URL.

func (*Store) SaveCredentials

func (s *Store) SaveCredentials(creds *Credentials) error

SaveCredentials writes credentials.

func (*Store) SaveServerURL

func (s *Store) SaveServerURL(url string) error

SaveServerURL stores the server URL.

func (*Store) SaveWorkspace

func (s *Store) SaveWorkspace(ws *LocalWorkspace) error

SaveWorkspace updates an existing workspace record.

Jump to

Keyboard shortcuts

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