Live video on the AT Protocol
1package statedb
2
3import (
4 "errors"
5 "time"
6
7 "gorm.io/gorm"
8)
9
10type Config struct {
11 Key string `gorm:"column:key;primarykey"`
12 Value []byte `gorm:"column:value"`
13 CreatedAt time.Time `gorm:"column:created_at"`
14 UpdatedAt time.Time `gorm:"column:updated_at"`
15}
16
17func (state *StatefulDB) GetConfig(key string) (*Config, error) {
18 var config Config
19 if err := state.DB.Where("key = ?", key).First(&config).Error; err != nil {
20 if errors.Is(err, gorm.ErrRecordNotFound) {
21 return nil, nil
22 }
23 return nil, err
24 }
25 return &config, nil
26}
27
28func (state *StatefulDB) PutConfig(key string, value []byte) error {
29 config := Config{
30 Key: key,
31 Value: value,
32 }
33 return state.DB.Save(&config).Error
34}