2024-09-09 16:16:08 +02:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"git.defalsify.org/vise.git/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DataStore interface {
|
2024-09-10 10:24:09 +02:00
|
|
|
db.Db
|
2024-09-09 16:16:08 +02:00
|
|
|
ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error)
|
|
|
|
WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserDataStore struct {
|
2024-09-10 10:24:09 +02:00
|
|
|
db.Db
|
2024-09-09 16:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadEntry retrieves an entry from the store based on the provided parameters.
|
2024-09-10 10:24:09 +02:00
|
|
|
func (store *UserDataStore) ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error) {
|
|
|
|
store.SetPrefix(db.DATATYPE_USERDATA)
|
|
|
|
store.SetSession(sessionId)
|
2024-09-09 16:16:08 +02:00
|
|
|
k := PackKey(typ, []byte(sessionId))
|
|
|
|
return store.Get(ctx, k)
|
|
|
|
}
|
|
|
|
|
2024-09-10 10:24:09 +02:00
|
|
|
func (store *UserDataStore) WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error {
|
|
|
|
store.SetPrefix(db.DATATYPE_USERDATA)
|
|
|
|
store.SetSession(sessionId)
|
2024-09-09 16:16:08 +02:00
|
|
|
k := PackKey(typ, []byte(sessionId))
|
2024-09-10 10:24:09 +02:00
|
|
|
return store.Put(ctx, k, value)
|
2024-09-09 16:16:08 +02:00
|
|
|
}
|