f-8: code: add func to control db #8
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
a1f7c43888
commit
b8796d0810
2 changed files with 22 additions and 0 deletions
11
pkg/db/kv/addInDB.go
Normal file
11
pkg/db/kv/addInDB.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package kv
|
||||
|
||||
import (
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
func AddInDB(db *badger.DB, key string, value string) error {
|
||||
return db.Update(func(txn *badger.Txn) error {
|
||||
return txn.Set([]byte(key), []byte(value))
|
||||
})
|
||||
}
|
||||
11
pkg/db/kv/deleteInDB.go
Normal file
11
pkg/db/kv/deleteInDB.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package kv
|
||||
|
||||
import (
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
func DeleteInDB(db *badger.DB, key string) error {
|
||||
return db.Update(func(txn *badger.Txn) error {
|
||||
return txn.Delete([]byte(key))
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue