@@ -3,47 +3,65 @@ package questdb
33import (
44 "context"
55 "fmt"
6+ "strconv"
7+ "time"
68
9+ "github.com/jackc/pgx/v5/pgtype"
710 "github.com/ojparkinson/telemetryService/internal/db/generated"
811 "github.com/ojparkinson/telemetryService/internal/domain"
912)
1013
1114func (r * Repository ) ListSessions (ctx context.Context ) ([]domain.Session , error ) {
1215 rows , err := r .queries .ListSessions (ctx )
1316 if err != nil {
14- return nil , fmt .Errorf ("list sessions: %W " , err )
17+ return nil , fmt .Errorf ("list sessions: %w " , err )
1518 }
1619
1720 sessions := make ([]domain.Session , len (rows ))
1821 for i , row := range rows {
22+ var maxLapID string
23+ if v , ok := row .MaxLapID .(string ); ok {
24+ maxLapID = v
25+ } else if v , ok := row .MaxLapID .(pgtype.Text ); ok {
26+ maxLapID = v .String
27+ }
28+
29+ var lastUpdated time.Time
30+ if v , ok := row .LastUpdated .(time.Time ); ok {
31+ lastUpdated = v
32+ } else if v , ok := row .LastUpdated .(pgtype.Timestamp ); ok && v .Valid {
33+ lastUpdated = v .Time
34+ }
35+
1936 sessions [i ] = domain.Session {
20- SessionID : row .SessionID ,
21- TrackName : row .TrackName ,
22- SessionName : row .SessionName ,
23- MaxLapID : row . MaxLapID ,
24- LastUpdated : row . LastUpdated ,
37+ SessionID : row .SessionID . String ,
38+ TrackName : row .TrackName . String ,
39+ SessionName : row .SessionName . String ,
40+ MaxLapID : maxLapID ,
41+ LastUpdated : lastUpdated ,
2542 }
2643 }
2744 return sessions , nil
2845}
2946
3047func (r * Repository ) ListLaps (ctx context.Context , sessionsID string ) ([]domain.Lap , error ) {
31- rows , err := r .queries .ListLaps (ctx , sessionsID )
48+ rows , err := r .queries .ListLaps (ctx , pgtype. Text { String : sessionsID , Valid : true } )
3249 if err != nil {
3350 return nil , fmt .Errorf ("list laps: %w" , err )
3451 }
3552
3653 laps := make ([]domain.Lap , len (rows ))
3754 for i , row := range rows {
38- laps [i ] = domain.Lap {LapID : row .LapID }
55+ lapID , _ := strconv .Atoi (row .String )
56+ laps [i ] = domain.Lap {LapID : lapID }
3957 }
4058 return laps , nil
4159}
4260
4361func (r * Repository ) GetLapTelemetry (ctx context.Context , sessionID , lapID string ) ([]domain.TelemetryPoint , error ) {
4462 rows , err := r .queries .GetLapTelemetry (ctx , generated.GetLapTelemetryParams {
45- SessionID : sessionID ,
46- LapID : lapID ,
63+ SessionID : pgtype. Text { String : sessionID , Valid : true } ,
64+ LapID : pgtype. Text { String : lapID , Valid : true } ,
4765 })
4866 if err != nil {
4967 return nil , fmt .Errorf ("get lap telemetry: %w" , err )
@@ -58,11 +76,31 @@ func (r *Repository) GetLapTelemetry(ctx context.Context, sessionID, lapID strin
5876
5977func telemetryPointFromRow (row generated.Telemetrytick ) domain.TelemetryPoint {
6078 return domain.TelemetryPoint {
61- Speed : row .Speed ,
62- Throttle : row .Throttle ,
63- Brake : row .Brake ,
64- RPM : row .Rpm ,
65- Gear : row .Gear ,
66- // ... all fields, but now it's typed — no getString/getFloat64 helpers
79+ Speed : row .Speed .Float64 ,
80+ Throttle : row .Throttle .Float64 ,
81+ Brake : row .Brake .Float64 ,
82+ RPM : row .Rpm .Float64 ,
83+ Gear : uint32 (row .Gear .Int32 ),
84+ LapDistPct : row .LapDistPct .Float64 ,
85+ SteeringWheelAngle : row .SteeringWheelAngle .Float64 ,
86+ Lat : row .Lat .Float64 ,
87+ Lon : row .Lon .Float64 ,
88+ Alt : row .Alt .Float64 ,
89+ VelocityX : row .VelocityX .Float64 ,
90+ VelocityY : row .VelocityY .Float64 ,
91+ VelocityZ : row .VelocityZ .Float64 ,
92+ LatAccel : row .LatAccel .Float64 ,
93+ LongAccel : row .LongAccel .Float64 ,
94+ VertAccel : row .VertAccel .Float64 ,
95+ Pitch : row .Pitch .Float64 ,
96+ Roll : row .Roll .Float64 ,
97+ Yaw : row .Yaw .Float64 ,
98+ YawNorth : row .YawNorth .Float64 ,
99+ FuelLevel : row .FuelLevel .Float64 ,
100+ LapCurrentLapTime : row .LapCurrentLapTime .Float64 ,
101+ PlayerCarPosition : uint32 (row .PlayerCarPosition .Int32 ),
102+ TrackName : row .TrackName .String ,
103+ SessionNum : row .SessionNum .String ,
104+ SessionTime : row .SessionTime .Float64 ,
67105 }
68106}
0 commit comments