Download this file
| 1 | package store |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "database/sql" |
| 6 | "fmt" |
| 7 | ) |
| 8 | |
| 9 | // SetTheme keeps the member's Appearance: "" (the device's), "light" or |
| 10 | // "dark". The caller checks the value. |
| 11 | func SetTheme(ctx context.Context, db *sql.DB, memberID, theme string) error { |
| 12 | res, err := db.ExecContext(ctx, `UPDATE members SET theme = ? WHERE id = ?`, theme, memberID) |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | if n, err := res.RowsAffected(); err != nil { |
| 17 | return err |
| 18 | } else if n != 1 { |
| 19 | return fmt.Errorf("store: no member %s", memberID) |
| 20 | } |
| 21 | return nil |
| 22 | } |
| 23 | |