change db path

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2025-12-13 00:15:44 +01:00
commit 2e6dccceaa
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632

View file

@ -13,8 +13,8 @@ import (
var DB *badger.DB var DB *badger.DB
func CheckInDB(dbName, id string) int { func CheckInDB(dbName, id string) int {
prefix := []byte(dbName + "/bash/") prefix := []byte(dbName + "/")
key := []byte(dbName + "/bash/" + id) key := []byte(dbName + "/" + id)
// vérifier si DB contient au moins une entrée avec ce préfixe // vérifier si DB contient au moins une entrée avec ce préfixe
hasPrefix := false hasPrefix := false
@ -48,8 +48,8 @@ func CheckInDB(dbName, id string) int {
func AddInDB(dbName string, line string) error { func AddInDB(dbName string, line string) error {
// ID = partie avant le premier ';' // ID = partie avant le premier ';'
id := strings.Split(line, ";")[0] id := strings.Split(line, ";")[0] + "/bash"
key := []byte(dbName + "/bash/" + id) key := []byte(dbName + "/" + id)
return DB.Update(func(txn *badger.Txn) error { return DB.Update(func(txn *badger.Txn) error {
return txn.Set(key, []byte(line)) return txn.Set(key, []byte(line))
@ -57,7 +57,7 @@ func AddInDB(dbName string, line string) error {
} }
func DeleteInDB(dbName, id string) error { func DeleteInDB(dbName, id string) error {
key := []byte(dbName + "/bash/" + id) key := []byte(dbName + "/" + id + "/bash")
return DB.Update(func(txn *badger.Txn) error { return DB.Update(func(txn *badger.Txn) error {
return txn.Delete(key) return txn.Delete(key)
@ -65,7 +65,7 @@ func DeleteInDB(dbName, id string) error {
} }
func CountInDB(dbName, id string) int { func CountInDB(dbName, id string) int {
prefix := []byte(dbName + "/bash/" + id) prefix := []byte(dbName + "/" + id + "/bash")
count := 0 count := 0
DB.View(func(txn *badger.Txn) error { DB.View(func(txn *badger.Txn) error {
@ -82,7 +82,7 @@ func CountInDB(dbName, id string) int {
} }
func GetFromDB(dbName, id string) (string, error) { func GetFromDB(dbName, id string) (string, error) {
key := []byte(dbName + "/bash/" + id) key := []byte(dbName + "/" + id + "/bash")
var result string var result string