267 lines
8.7 KiB
Go
267 lines
8.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: query.sql
|
|
|
|
package bahndb_rest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const getDeparturesById = `-- name: GetDeparturesById :many
|
|
SELECT DISTINCT (t.id) as "id",
|
|
t.line_name as "lineName",
|
|
t.line_productname as "lineProductName",
|
|
so.departuredelay as "departureDelay",
|
|
jsonb_build_object('id', sd.id, 'name', sd.name) as "direction",
|
|
ARRAY((SELECT jsonb_build_object('stop', row('id', sd.id, 'name', sd.name),
|
|
'arrival', so2.arrival,
|
|
'plannedArrival', so2.plannedarrival,
|
|
'arrivalDelay', so2.arrivaldelay,
|
|
'arrivalPlatform', so2.arrivalplatform,
|
|
'plannedArrivalPlatform', so2.plannedarrivalplatform,
|
|
'cancelled', so2.cancelled)
|
|
FROM stopovers so2
|
|
JOIN public.stops s2
|
|
ON so2.stop = s2.id
|
|
WHERE so2.id = t.id
|
|
AND so2.plannedarrival > so.planneddeparture
|
|
AND (so2.stop, so2.realtimedataupdatedat) IN (SELECT DISTINCT (stop), max(realtimedataupdatedat)
|
|
FROM stopovers so3
|
|
WHERE (so3.id = t.id
|
|
AND so3.realtimedataupdatedat <= $1)
|
|
GROUP BY so3.stop)))
|
|
AS "stopovers",
|
|
so.departure as "departure",
|
|
so.planneddeparture as "plannedDeparture",
|
|
so.departureplatform as "departurePlatform",
|
|
so.planneddepartureplatform as "plannedDeparturePlatform",
|
|
so.cancelled as "cancelled",
|
|
so.realtimedataupdatedat as "realtimeDataUpdatedAt"
|
|
FROM stopovers so
|
|
JOIN trips t ON so.id = t.id
|
|
JOIN public.trip_meta tm on t.id = tm.id
|
|
JOIN public.stops sd on t.destination = sd.id
|
|
WHERE so.stop = $2
|
|
AND (so.id, so.realtimedataupdatedat) IN (SELECT DISTINCT (id), max(realtimedataupdatedat)
|
|
FROM stopovers so3
|
|
WHERE so3.stop = $2
|
|
AND (so3.departure > $3)
|
|
AND (so3.departure < $4)
|
|
AND (so3.realtimedataupdatedat <= $1)
|
|
GROUP BY so3.id)
|
|
ORDER BY so.departure ASC
|
|
`
|
|
|
|
type GetDeparturesByIdParams struct {
|
|
RtUpdatedAt pgtype.Timestamptz `json:"rt_updated_at"`
|
|
StopID pgtype.Text `json:"stop_id"`
|
|
DepartureFrom pgtype.Timestamptz `json:"departure_from"`
|
|
DepartureTo pgtype.Timestamptz `json:"departure_to"`
|
|
}
|
|
|
|
type GetDeparturesByIdRow struct {
|
|
ID string `json:"id"`
|
|
LineName pgtype.Text `json:"lineName"`
|
|
LineProductName pgtype.Text `json:"lineProductName"`
|
|
DepartureDelay pgtype.Int4 `json:"departureDelay"`
|
|
Direction []byte `json:"direction"`
|
|
Stopovers interface{} `json:"stopovers"`
|
|
Departure pgtype.Timestamptz `json:"departure"`
|
|
PlannedDeparture pgtype.Timestamptz `json:"plannedDeparture"`
|
|
DeparturePlatform pgtype.Text `json:"departurePlatform"`
|
|
PlannedDeparturePlatform pgtype.Text `json:"plannedDeparturePlatform"`
|
|
Cancelled pgtype.Text `json:"cancelled"`
|
|
RealtimeDataUpdatedAt pgtype.Timestamptz `json:"realtimeDataUpdatedAt"`
|
|
}
|
|
|
|
func (q *Queries) GetDeparturesById(ctx context.Context, arg GetDeparturesByIdParams) ([]GetDeparturesByIdRow, error) {
|
|
rows, err := q.db.Query(ctx, getDeparturesById,
|
|
arg.RtUpdatedAt,
|
|
arg.StopID,
|
|
arg.DepartureFrom,
|
|
arg.DepartureTo,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetDeparturesByIdRow
|
|
for rows.Next() {
|
|
var i GetDeparturesByIdRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.LineName,
|
|
&i.LineProductName,
|
|
&i.DepartureDelay,
|
|
&i.Direction,
|
|
&i.Stopovers,
|
|
&i.Departure,
|
|
&i.PlannedDeparture,
|
|
&i.DeparturePlatform,
|
|
&i.PlannedDeparturePlatform,
|
|
&i.Cancelled,
|
|
&i.RealtimeDataUpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getStationById = `-- name: GetStationById :one
|
|
SELECT s.id as "id",
|
|
s.name as "name",
|
|
sl.latitude as "latitude",
|
|
sl.longitude as "longitude",
|
|
bus,
|
|
taxi,
|
|
tram,
|
|
ferry,
|
|
subway,
|
|
national,
|
|
regional,
|
|
suburban,
|
|
regionalexp,
|
|
nationalexp
|
|
FROM stops s
|
|
JOIN public.stat_locations sl
|
|
on sl.id = s.location_id
|
|
JOIN public.stat_services ss
|
|
on ss.id = s.service_id
|
|
WHERE s.id = $1
|
|
`
|
|
|
|
type GetStationByIdRow struct {
|
|
ID string `json:"id"`
|
|
Name pgtype.Text `json:"name"`
|
|
Latitude pgtype.Float8 `json:"latitude"`
|
|
Longitude pgtype.Float8 `json:"longitude"`
|
|
Bus pgtype.Bool `json:"bus"`
|
|
Taxi pgtype.Bool `json:"taxi"`
|
|
Tram pgtype.Bool `json:"tram"`
|
|
Ferry pgtype.Bool `json:"ferry"`
|
|
Subway pgtype.Bool `json:"subway"`
|
|
National pgtype.Bool `json:"national"`
|
|
Regional pgtype.Bool `json:"regional"`
|
|
Suburban pgtype.Bool `json:"suburban"`
|
|
Regionalexp pgtype.Bool `json:"regionalexp"`
|
|
Nationalexp pgtype.Bool `json:"nationalexp"`
|
|
}
|
|
|
|
func (q *Queries) GetStationById(ctx context.Context, stopID string) (GetStationByIdRow, error) {
|
|
row := q.db.QueryRow(ctx, getStationById, stopID)
|
|
var i GetStationByIdRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Latitude,
|
|
&i.Longitude,
|
|
&i.Bus,
|
|
&i.Taxi,
|
|
&i.Tram,
|
|
&i.Ferry,
|
|
&i.Subway,
|
|
&i.National,
|
|
&i.Regional,
|
|
&i.Suburban,
|
|
&i.Regionalexp,
|
|
&i.Nationalexp,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getStationsByName = `-- name: GetStationsByName :many
|
|
SELECT s.id as "id",
|
|
s.name as "name",
|
|
sl.latitude as "latitude",
|
|
sl.longitude as "longitude",
|
|
bus as "bus",
|
|
taxi as "taxi",
|
|
tram as "tram",
|
|
ferry as "ferry",
|
|
subway as "subway",
|
|
national as "national",
|
|
regional as "regional",
|
|
suburban as "suburban",
|
|
regionalexp as "regionalexp",
|
|
nationalexp as "nationalexp"
|
|
FROM stops s
|
|
JOIN public.stat_locations sl
|
|
on sl.id = s.location_id
|
|
JOIN public.stat_services ss
|
|
on ss.id = s.service_id
|
|
JOIN public.station_rank sr
|
|
on sr.stop = s.id
|
|
WHERE s.id
|
|
in (SELECT id
|
|
FROM stops s2
|
|
WHERE s2.name ILIKE ALL ($1::text[])
|
|
)
|
|
AND CASE WHEN $2::bool THEN (ss.national = $2::bool OR ss.nationalexp = $2::bool) ELSE TRUE END
|
|
ORDER BY sr.count DESC
|
|
`
|
|
|
|
type GetStationsByNameParams struct {
|
|
SearchParams []string `json:"search_params"`
|
|
LongDistance pgtype.Bool `json:"long_distance"`
|
|
}
|
|
|
|
type GetStationsByNameRow struct {
|
|
ID string `json:"id"`
|
|
Name pgtype.Text `json:"name"`
|
|
Latitude pgtype.Float8 `json:"latitude"`
|
|
Longitude pgtype.Float8 `json:"longitude"`
|
|
Bus pgtype.Bool `json:"bus"`
|
|
Taxi pgtype.Bool `json:"taxi"`
|
|
Tram pgtype.Bool `json:"tram"`
|
|
Ferry pgtype.Bool `json:"ferry"`
|
|
Subway pgtype.Bool `json:"subway"`
|
|
National pgtype.Bool `json:"national"`
|
|
Regional pgtype.Bool `json:"regional"`
|
|
Suburban pgtype.Bool `json:"suburban"`
|
|
Regionalexp pgtype.Bool `json:"regionalexp"`
|
|
Nationalexp pgtype.Bool `json:"nationalexp"`
|
|
}
|
|
|
|
func (q *Queries) GetStationsByName(ctx context.Context, arg GetStationsByNameParams) ([]GetStationsByNameRow, error) {
|
|
rows, err := q.db.Query(ctx, getStationsByName, arg.SearchParams, arg.LongDistance)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetStationsByNameRow
|
|
for rows.Next() {
|
|
var i GetStationsByNameRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Latitude,
|
|
&i.Longitude,
|
|
&i.Bus,
|
|
&i.Taxi,
|
|
&i.Tram,
|
|
&i.Ferry,
|
|
&i.Subway,
|
|
&i.National,
|
|
&i.Regional,
|
|
&i.Suburban,
|
|
&i.Regionalexp,
|
|
&i.Nationalexp,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|