UpdateUsageData updates the entry for a given userID/deviceID pair with the lastUsed and lastIP values
(ctx context.Context, userId, deviceId string, lastUsed time.Time, lastIP string)
| 43 | |
| 44 | // UpdateUsageData updates the entry for a given userID/deviceID pair with the lastUsed and lastIP values |
| 45 | func (db *DB) UpdateUsageData(ctx context.Context, userId, deviceId string, lastUsed time.Time, lastIP string) error { |
| 46 | tx := db.DB.WithContext(ctx).Model(&UsageData{}). |
| 47 | Where("user_id = ? AND device_id = ?", userId, deviceId). |
| 48 | Update("last_used", lastUsed). |
| 49 | Update("last_ip", lastIP) |
| 50 | |
| 51 | if tx.Error != nil { |
| 52 | return fmt.Errorf("db.WithContext.Model.Where.Update: %w", tx.Error) |
| 53 | } |
| 54 | |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | func (db *DB) UpdateUsageDataForNumEntriesHandled(ctx context.Context, userId, deviceId string, numEntriesHandled int) error { |
| 59 | tx := db.DB.WithContext(ctx).Exec("UPDATE usage_data SET num_entries_handled = COALESCE(num_entries_handled, 0) + ? WHERE user_id = ? AND device_id = ?", numEntriesHandled, userId, deviceId) |