-- name: UpsertDeviceMetrics :exec
INSERT INTO public.stats(
  device_id,
  inc_traffic,
  out_traffic,
  inc_rps,
  write_rps,
  read_rps,
  updated_at
) VALUES (
  @device_id,
  @inc_traffic,
  @out_traffic,
  @inc_rps,
  @write_rps,
  @read_rps,
  NOW()
) ON CONFLICT(device_id) DO UPDATE SET
device_id = EXCLUDED.device_id,
inc_traffic = EXCLUDED.inc_traffic,
out_traffic = EXCLUDED.out_traffic,
inc_rps = EXCLUDED.inc_rps,
write_rps = EXCLUDED.write_rps,
read_rps = EXCLUDED.read_rps,
updated_at = NOW();

-- name: ListDeviceStats :many
SELECT * FROM public.stats;
