ussd/internal/storage/db.go

52 lines
945 B
Go
Raw Normal View History

2024-09-27 22:10:03 +02:00
package storage
import (
"context"
"git.defalsify.org/vise.git/db"
)
const (
DATATYPE_USERSUB = 64
)
2024-10-02 23:06:43 +02:00
const (
SUBPREFIX_TIME = uint16(1)
)
2024-09-27 22:10:03 +02:00
type SubPrefixDb struct {
store db.Db
pfx []byte
}
func NewSubPrefixDb(store db.Db, pfx []byte) *SubPrefixDb {
return &SubPrefixDb{
store: store,
pfx: pfx,
}
}
2024-10-03 00:57:55 +02:00
func(s *SubPrefixDb) SetSession(sessionId string) {
s.store.SetSession(sessionId)
}
2024-09-27 22:10:03 +02:00
func(s *SubPrefixDb) toKey(k []byte) []byte {
return append(s.pfx, k...)
}
func(s *SubPrefixDb) Get(ctx context.Context, key []byte) ([]byte, error) {
s.store.SetPrefix(DATATYPE_USERSUB)
key = s.toKey(key)
v, err := s.store.Get(ctx, key)
if err != nil {
return nil, err
}
return v, nil
}
func(s *SubPrefixDb) Put(ctx context.Context, key []byte, val []byte) error {
s.store.SetPrefix(DATATYPE_USERSUB)
key = s.toKey(key)
return s.store.Put(ctx, key, val)
}