Feature/vhs demo (#15)

* add vhs made demo gif

* add support for ANYDB_DB env var

* left one section

* fixed data type bug, added demo gifs, upgraded dependencies

---------

Co-authored-by: Thomas von Dein <tom@vondein.org>
This commit is contained in:
T.v.Dein
2025-02-02 19:42:12 +01:00
committed by GitHub
parent 359d134d6e
commit d794cc8608
17 changed files with 362 additions and 173 deletions

View File

@@ -61,6 +61,24 @@ type DbTag struct {
const BucketData string = "data"
func GetDbFile(file string) string {
if file != "" {
return file
}
file = os.Getenv("ANYDB_DB")
if file != "" {
return file
}
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
return filepath.Join(home, ".config", "anydb", "default.db")
}
func New(file string, bucket string, debug bool) (*DB, error) {
return &DB{Debug: debug, Dbfile: file, Bucket: bucket}, nil
}
@@ -131,7 +149,7 @@ func (db *DB) List(attr *DbAttr, fulltext bool) (DbEntries, error) {
value := databucket.Get([]byte(entry.Key)) // empty is ok
vc := make([]byte, len(value))
copy(vc, value)
entry.Value = vc
entry.Value = string(vc)
}
var include bool
@@ -326,7 +344,7 @@ func (db *DB) Get(attr *DbAttr) (*DbEntry, error) {
vc := make([]byte, len(value))
copy(vc, value)
entry.Value = vc
entry.Value = string(vc)
return nil
})
@@ -422,7 +440,7 @@ func (db *DB) Import(attr *DbAttr) (string, error) {
}
// write value
err = databucket.Put([]byte(entry.Key), entry.Value)
err = databucket.Put([]byte(entry.Key), []byte(entry.Value))
if err != nil {
return fmt.Errorf("failed to insert data: %w", err)
}
@@ -525,7 +543,7 @@ func (db *DB) Getall(attr *DbAttr) (DbEntries, error) {
vc := make([]byte, len(value))
copy(vc, value)
entry.Value = vc
entry.Value = string(vc)
entries = append(entries, &entry)
return nil