common

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package common for all common functionality and utilities

Index

Constants

View Source
const (
	MetadataKeyMigrationIndex       = "migration_index"
	MetadataKeyDBMigrated           = "kv_db_migrated"
	MetadataKeyKeysWarningDisplayed = "keys_warning_displayed"
)
View Source
const DefaultDBName = "default"

Variables

View Source
var (
	Stdout = log.New(os.Stdout, "", 0)
	Stderr = log.New(os.Stderr, "", 0)
)
View Source
var (
	Yellow = color.New(color.FgYellow).SprintfFunc()
	Red    = color.New(color.FgRed).SprintfFunc()
	Blue   = color.New(color.FgBlue).SprintfFunc()
	Green  = color.New(color.FgGreen).SprintfFunc()
)
View Source
var CachedDBs = make(map[string]*sql.DB)

Functions

func Assert added in v0.6.0

func Assert(cond bool, message string, args ...any)

func BackupDB added in v0.3.0

func BackupDB(name string, writer io.Writer) error

func BackupDBInPlace added in v0.6.0

func BackupDBInPlace(name string)

func BeginTransaction added in v0.5.1

func BeginTransaction(db *sql.DB) (*sql.Tx, error)

func CloseDBs added in v0.6.0

func CloseDBs()

func CopyFile added in v0.2.0

func CopyFile(src, dst string) error

CopyFile copies content from `src` file into `dst` file

func Decrypt

func Decrypt(encryptedB64 string, password string) (string, error)

func Encrypt

func Encrypt(plaintext string, password string) (string, error)

func EqualStringPtrs

func EqualStringPtrs(s1, s2 *string) bool

func EqualTimePtrs

func EqualTimePtrs(t1, t2 *time.Time) bool

func Fail

func Fail(message string, args ...any)

func FailOn

func FailOn(err error)

func FormatTimePtr

func FormatTimePtr(t *time.Time) *string

func GetConfigPath added in v0.6.0

func GetConfigPath() string

func GetDB added in v0.1.4

func GetDB(name string) (*sql.DB, error)

func GetDataDirectory added in v0.6.0

func GetDataDirectory() string

func GetDefaultBackupPath added in v0.3.0

func GetDefaultBackupPath(name string) string

GetDefaultBackupPath returns the default backup path for the given DB default backup path is {db-directory}/{db-name}.backup

func GetVersion

func GetVersion() string

GetVersion returns the version string. If version was set via SetVersion (goreleaser build), it returns that. Otherwise, it attempts to get the version from git tags.

func NormalizePath added in v0.2.0

func NormalizePath(path string) string

NormalizePath fills in home directory if needed, and make path into absolute path

func ParseKey added in v0.6.0

func ParseKey(key string) (string, string)

ParseKey parses the key and returns key and database parts

func ParseKeys added in v0.6.0

func ParseKeys(keys []string) map[string][]string

func PrintCrossDBWarning added in v0.6.0

func PrintCrossDBWarning()

func Quiet

func Quiet(enable bool)

func ReadMetadata added in v0.6.0

func ReadMetadata[T any](tx *sql.Tx, key string) (T, error)

func SetVersion

func SetVersion(v string)

SetVersion sets the version string (typically injected by goreleaser at build time)

func ValidateDBName added in v0.6.0

func ValidateDBName(db string)

func ValidateSqliteFile added in v0.2.0

func ValidateSqliteFile(path string) error

func Warn

func Warn(msg string, args ...any)

func WriteMetadata added in v0.6.0

func WriteMetadata(tx *sql.Tx, key string, value any) error

Types

type Config

type Config struct {
	PruneHistoryAfterDays int `json:"pruneHistoryAfterDays,omitempty" yaml:"prune-history-after-days,omitempty"`
	HistoryLength         int `json:"historyLength,omitempty" yaml:"history-length,omitempty"`

	DBs map[string]DBConfig `json:"dbs,omitempty" yaml:"dbs,omitempty"`

	CurrentDB string `json:"-" yaml:"-"`
}

func GetConfig added in v0.6.0

func GetConfig() *Config

func (*Config) DeleteDB added in v0.6.0

func (config *Config) DeleteDB(db string)

func (Config) GetCurrentDBPath added in v0.6.0

func (config Config) GetCurrentDBPath() string

func (Config) GetDBPath added in v0.6.0

func (config Config) GetDBPath(name string) string

GetDBPath gets the full path for the DB, if DB is registeres: get it's registered use the registered directory oterwise use XDG data directory. DB path = {db-directory}/{db-name}.db

func (*Config) RegisterDB added in v0.6.0

func (config *Config) RegisterDB(name string)

RegisterDB adds DB if it does not exist, otherwise it's a no-op

func (*Config) RenameDB added in v0.6.0

func (config *Config) RenameDB(db string, newName string)

func (*Config) SetDBDirectory added in v0.6.0

func (config *Config) SetDBDirectory(db string, directory string)

func (Config) String

func (config Config) String() string

type DBConfig added in v0.6.0

type DBConfig struct {
	Directory string `json:"directory" yaml:"directory"`
}

Jump to

Keyboard shortcuts

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