Yimaru-BackEnd/gen/db/video_engagement.sql.go
Yared Yemane 3f73afb4bf Add video engagement tracking and analytics metrics.
Record playback heartbeats via POST /api/v1/videos/engagement/heartbeat and expose completion, replay, and drop-off rates on the analytics dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 02:59:46 -07:00

206 lines
4.9 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: video_engagement.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const GetActiveVideoWatchSession = `-- name: GetActiveVideoWatchSession :one
SELECT
id,
user_id,
content_kind,
content_id,
session_number,
video_duration_sec,
max_position_sec,
started_at,
last_heartbeat_at,
ended_at,
completed_at
FROM user_video_watch_sessions
WHERE user_id = $1
AND content_kind = $2
AND content_id = $3
AND ended_at IS NULL
AND last_heartbeat_at >= $4
ORDER BY session_number DESC
LIMIT 1
`
type GetActiveVideoWatchSessionParams struct {
UserID int64 `json:"user_id"`
ContentKind string `json:"content_kind"`
ContentID int64 `json:"content_id"`
LastHeartbeatAt pgtype.Timestamptz `json:"last_heartbeat_at"`
}
func (q *Queries) GetActiveVideoWatchSession(ctx context.Context, arg GetActiveVideoWatchSessionParams) (UserVideoWatchSession, error) {
row := q.db.QueryRow(ctx, GetActiveVideoWatchSession,
arg.UserID,
arg.ContentKind,
arg.ContentID,
arg.LastHeartbeatAt,
)
var i UserVideoWatchSession
err := row.Scan(
&i.ID,
&i.UserID,
&i.ContentKind,
&i.ContentID,
&i.SessionNumber,
&i.VideoDurationSec,
&i.MaxPositionSec,
&i.StartedAt,
&i.LastHeartbeatAt,
&i.EndedAt,
&i.CompletedAt,
)
return i, err
}
const GetMaxVideoWatchSessionNumber = `-- name: GetMaxVideoWatchSessionNumber :one
SELECT
coalesce(max(session_number), 0)::int AS max_session_number
FROM user_video_watch_sessions
WHERE user_id = $1
AND content_kind = $2
AND content_id = $3
`
type GetMaxVideoWatchSessionNumberParams struct {
UserID int64 `json:"user_id"`
ContentKind string `json:"content_kind"`
ContentID int64 `json:"content_id"`
}
func (q *Queries) GetMaxVideoWatchSessionNumber(ctx context.Context, arg GetMaxVideoWatchSessionNumberParams) (int32, error) {
row := q.db.QueryRow(ctx, GetMaxVideoWatchSessionNumber, arg.UserID, arg.ContentKind, arg.ContentID)
var max_session_number int32
err := row.Scan(&max_session_number)
return max_session_number, err
}
const InsertVideoWatchSession = `-- name: InsertVideoWatchSession :one
INSERT INTO user_video_watch_sessions (
user_id,
content_kind,
content_id,
session_number,
video_duration_sec,
max_position_sec
)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING
id,
user_id,
content_kind,
content_id,
session_number,
video_duration_sec,
max_position_sec,
started_at,
last_heartbeat_at,
ended_at,
completed_at
`
type InsertVideoWatchSessionParams struct {
UserID int64 `json:"user_id"`
ContentKind string `json:"content_kind"`
ContentID int64 `json:"content_id"`
SessionNumber int32 `json:"session_number"`
VideoDurationSec pgtype.Int4 `json:"video_duration_sec"`
MaxPositionSec int32 `json:"max_position_sec"`
}
func (q *Queries) InsertVideoWatchSession(ctx context.Context, arg InsertVideoWatchSessionParams) (UserVideoWatchSession, error) {
row := q.db.QueryRow(ctx, InsertVideoWatchSession,
arg.UserID,
arg.ContentKind,
arg.ContentID,
arg.SessionNumber,
arg.VideoDurationSec,
arg.MaxPositionSec,
)
var i UserVideoWatchSession
err := row.Scan(
&i.ID,
&i.UserID,
&i.ContentKind,
&i.ContentID,
&i.SessionNumber,
&i.VideoDurationSec,
&i.MaxPositionSec,
&i.StartedAt,
&i.LastHeartbeatAt,
&i.EndedAt,
&i.CompletedAt,
)
return i, err
}
const UpdateVideoWatchSession = `-- name: UpdateVideoWatchSession :one
UPDATE user_video_watch_sessions
SET
max_position_sec = $2,
video_duration_sec = $3,
last_heartbeat_at = $4,
completed_at = $5,
ended_at = $6
WHERE id = $1
RETURNING
id,
user_id,
content_kind,
content_id,
session_number,
video_duration_sec,
max_position_sec,
started_at,
last_heartbeat_at,
ended_at,
completed_at
`
type UpdateVideoWatchSessionParams struct {
ID int64 `json:"id"`
MaxPositionSec int32 `json:"max_position_sec"`
VideoDurationSec pgtype.Int4 `json:"video_duration_sec"`
LastHeartbeatAt pgtype.Timestamptz `json:"last_heartbeat_at"`
CompletedAt pgtype.Timestamptz `json:"completed_at"`
EndedAt pgtype.Timestamptz `json:"ended_at"`
}
func (q *Queries) UpdateVideoWatchSession(ctx context.Context, arg UpdateVideoWatchSessionParams) (UserVideoWatchSession, error) {
row := q.db.QueryRow(ctx, UpdateVideoWatchSession,
arg.ID,
arg.MaxPositionSec,
arg.VideoDurationSec,
arg.LastHeartbeatAt,
arg.CompletedAt,
arg.EndedAt,
)
var i UserVideoWatchSession
err := row.Scan(
&i.ID,
&i.UserID,
&i.ContentKind,
&i.ContentID,
&i.SessionNumber,
&i.VideoDurationSec,
&i.MaxPositionSec,
&i.StartedAt,
&i.LastHeartbeatAt,
&i.EndedAt,
&i.CompletedAt,
)
return i, err
}