2024-10-30 02:45:38 +01:00
|
|
|
package common
|
2024-09-09 16:16:08 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"git.defalsify.org/vise.git/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DataStore interface {
|
2024-09-10 10:24:09 +02:00
|
|
|
db.Db
|
2024-10-30 02:45:38 +01:00
|
|
|
ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error)
|
|
|
|
WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error
|
2024-09-09 16:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-10-30 02:45:38 +01:00
|
|
|
func (store *UserDataStore) ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error) {
|
2024-09-10 10:24:09 +02:00
|
|
|
store.SetPrefix(db.DATATYPE_USERDATA)
|
|
|
|
store.SetSession(sessionId)
|
2024-10-30 02:45:38 +01:00
|
|
|
k := PackKey(typ, []byte(sessionId))
|
2024-09-09 16:16:08 +02:00
|
|
|
return store.Get(ctx, k)
|
|
|
|
}
|
|
|
|
|
2024-10-30 02:45:38 +01:00
|
|
|
func (store *UserDataStore) WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error {
|
2024-09-10 10:24:09 +02:00
|
|
|
store.SetPrefix(db.DATATYPE_USERDATA)
|
|
|
|
store.SetSession(sessionId)
|
2024-10-30 02:45:38 +01: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
|
|
|
}
|