Skip to content

Commit

Permalink
Add Routing queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Sep 10, 2024
1 parent e216f39 commit b479701
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
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 = ?;

0 comments on commit b479701

Please sign in to comment.