mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-17 04:20:59 +01:00
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:
26
app/db.go
26
app/db.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user