GetConfig gets a configuration.
(ctx context.Context, userID string)
| 143 | |
| 144 | // GetConfig gets a configuration. |
| 145 | func (d DB) GetConfig(ctx context.Context, userID string) (userconfig.View, error) { |
| 146 | var cfgView userconfig.View |
| 147 | var cfgBytes []byte |
| 148 | var deletedAt sql.NullTime |
| 149 | err := d.Select("id", "config", "deleted_at"). |
| 150 | From("configs"). |
| 151 | Where(squirrel.And{allConfigs, squirrel.Eq{"owner_id": userID}}). |
| 152 | OrderBy("id DESC"). |
| 153 | Limit(1). |
| 154 | QueryRow().Scan(&cfgView.ID, &cfgBytes, &deletedAt) |
| 155 | if err != nil { |
| 156 | return cfgView, err |
| 157 | } |
| 158 | cfgView.DeletedAt = deletedAt.Time |
| 159 | err = json.Unmarshal(cfgBytes, &cfgView.Config) |
| 160 | return cfgView, err |
| 161 | } |
| 162 | |
| 163 | // SetConfig sets a configuration. |
| 164 | func (d DB) SetConfig(ctx context.Context, userID string, cfg userconfig.Config) error { |
no test coverage detected