Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Routing queries #40

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ SELECT * FROM routes;

routesCount:
SELECT COUNT(*) FROM routes;

selectRouteById:
SELECT * FROM routes
WHERE route_id = ?;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
WITH trips_serving_stops AS (
SELECT st1.trip_id, st1.stop_id AS start_stop_id, st2.stop_id AS end_stop_id
FROM stopTimes AS st1
JOIN stopTimes AS st2 ON st1.trip_id = st2.trip_id
WHERE st1.stop_id = :start_stop_id
AND st2.stop_id = :end_stop_id
AND st1.stop_sequence < st2.stop_sequence
),
route_details AS (
SELECT t.trip_id, r.route_id, r.route_short_name, r.route_long_name
FROM trips_serving_stops AS tss
JOIN trip AS t ON tss.trip_id = t.trip_id
JOIN routes AS r ON t.route_id = r.route_id
)
SELECT * FROM route_details;
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ SELECT * FROM stop;

stopsCount:
SELECT COUNT(*) FROM stop;

selectStopIdByName:
SELECT stop_id
FROM stop
WHERE stop_name = ?;

selectStopById:
SELECT * FROM stop
WHERE stop_id = ?;
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ SELECT * FROM stopTimes;

sizeOfStopTimes:
SELECT COUNT(*) FROM stopTimes;

selectTripBetweenStops:
SELECT st1.trip_id, st1.stop_id AS start_stop_id, st2.stop_id AS end_stop_id
FROM stopTimes AS st1
JOIN stopTimes AS st2 ON st1.trip_id = st2.trip_id
WHERE st1.stop_id = ?
AND st2.stop_id = ?
AND st1.stop_sequence < st2.stop_sequence;
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ SELECT * FROM trip;

tripsCount:
SELECT COUNT(*) FROM trip;

selectTripById:
SELECT * FROM trip
WHERE trip_id = ?;

selectTripsByRoute:
SELECT * FROM trip
WHERE route_id = ?;