Documentation
¶
Overview ¶
Package common for all common functionality and utilities
Index ¶
- Constants
- Variables
- func Assert(cond bool, message string, args ...any)
- func BackupDB(name string, writer io.Writer) error
- func BackupDBInPlace(name string)
- func BeginTransaction(db *sql.DB) (*sql.Tx, error)
- func CloseDBs()
- func CopyFile(src, dst string) error
- func Decrypt(encryptedB64 string, password string) (string, error)
- func Encrypt(plaintext string, password string) (string, error)
- func EqualStringPtrs(s1, s2 *string) bool
- func EqualTimePtrs(t1, t2 *time.Time) bool
- func Fail(message string, args ...any)
- func FailOn(err error)
- func FormatTimePtr(t *time.Time) *string
- func GetConfigPath() string
- func GetDB(name string) (*sql.DB, error)
- func GetDataDirectory() string
- func GetDefaultBackupPath(name string) string
- func GetVersion() string
- func NormalizePath(path string) string
- func ParseKey(key string) (string, string)
- func ParseKeys(keys []string) map[string][]string
- func PrintCrossDBWarning()
- func Quiet(enable bool)
- func ReadMetadata[T any](tx *sql.Tx, key string) (T, error)
- func SetVersion(v string)
- func ValidateDBName(db string)
- func ValidateSqliteFile(path string) error
- func Warn(msg string, args ...any)
- func WriteMetadata(tx *sql.Tx, key string, value any) error
- type Config
- func (config *Config) DeleteDB(db string)
- func (config Config) GetCurrentDBPath() string
- func (config Config) GetDBPath(name string) string
- func (config *Config) RegisterDB(name string)
- func (config *Config) RenameDB(db string, newName string)
- func (config *Config) SetDBDirectory(db string, directory string)
- func (config Config) String() string
- type DBConfig
Constants ¶
const ( MetadataKeyMigrationIndex = "migration_index" MetadataKeyDBMigrated = "kv_db_migrated" MetadataKeyKeysWarningDisplayed = "keys_warning_displayed" )
const DefaultDBName = "default"
Variables ¶
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() )
var CachedDBs = make(map[string]*sql.DB)
Functions ¶
func BackupDBInPlace ¶ added in v0.6.0
func BackupDBInPlace(name string)
func EqualStringPtrs ¶
func EqualTimePtrs ¶
func FormatTimePtr ¶
func GetConfigPath ¶ added in v0.6.0
func GetConfigPath() string
func GetDataDirectory ¶ added in v0.6.0
func GetDataDirectory() string
func GetDefaultBackupPath ¶ added in v0.3.0
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
NormalizePath fills in home directory if needed, and make path into absolute path
func PrintCrossDBWarning ¶ added in v0.6.0
func PrintCrossDBWarning()
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
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 (Config) GetCurrentDBPath ¶ added in v0.6.0
func (Config) GetDBPath ¶ added in v0.6.0
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
RegisterDB adds DB if it does not exist, otherwise it's a no-op