package db

func (s *Store) GetSetting(key string) (string, error) {
	var value string
	err := s.queryRow("SELECT value FROM system_settings WHERE `key` = ?", sanitize(key)).Scan(&value)
	return value, err
}

func (s *Store) UpsertSetting(key, value string) error {
	columns := []string{"key", "value", "updated_at"}
	conn, d := s.active()
	_, err := conn.Exec(d.rebind(d.upsert("system_settings", columns, []string{"key"})), sanitize(key), value, Now())
	if err != nil {
		s.markFailover(err)
	}
	return err
}
