gtfs 3.8.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/@types/index.d.ts +130 -137
  2. package/@types/tests.ts +18 -13
  3. package/CHANGELOG.md +18 -0
  4. package/README.md +233 -212
  5. package/config-sample-rtupdates.json +6 -18
  6. package/lib/advancedQuery.js +8 -17
  7. package/lib/db.js +35 -59
  8. package/lib/export.js +16 -10
  9. package/lib/gtfs/agencies.js +8 -6
  10. package/lib/gtfs/areas.js +8 -11
  11. package/lib/gtfs/attributions.js +8 -6
  12. package/lib/gtfs/calendar-dates.js +8 -6
  13. package/lib/gtfs/calendars.js +8 -6
  14. package/lib/gtfs/fare-attributes.js +8 -6
  15. package/lib/gtfs/fare-leg-rules.js +8 -6
  16. package/lib/gtfs/fare-products.js +8 -6
  17. package/lib/gtfs/fare-rules.js +8 -6
  18. package/lib/gtfs/fare-transfer-rules.js +8 -6
  19. package/lib/gtfs/feed-info.js +8 -6
  20. package/lib/gtfs/frequencies.js +8 -6
  21. package/lib/gtfs/levels.js +8 -11
  22. package/lib/gtfs/pathways.js +8 -6
  23. package/lib/gtfs/routes.js +8 -11
  24. package/lib/gtfs/shapes.js +34 -39
  25. package/lib/gtfs/stop-areas.js +8 -6
  26. package/lib/gtfs/stop-times.js +8 -6
  27. package/lib/gtfs/stops.js +27 -33
  28. package/lib/gtfs/transfers.js +8 -6
  29. package/lib/gtfs/translations.js +8 -6
  30. package/lib/gtfs/trips.js +8 -11
  31. package/lib/gtfs-realtime/service-alerts.js +9 -7
  32. package/lib/gtfs-realtime/stop-times-updates.js +9 -7
  33. package/lib/gtfs-realtime/trip-updates.js +9 -7
  34. package/lib/gtfs-realtime/vehicle-positions.js +9 -7
  35. package/lib/gtfs-ride/board-alights.js +8 -6
  36. package/lib/gtfs-ride/ride-feed-infos.js +8 -6
  37. package/lib/gtfs-ride/rider-trips.js +8 -6
  38. package/lib/gtfs-ride/riderships.js +8 -6
  39. package/lib/gtfs-ride/trip-capacities.js +8 -6
  40. package/lib/gtfs.js +3 -9
  41. package/lib/import.js +213 -273
  42. package/lib/non-standard/directions.js +8 -6
  43. package/lib/non-standard/stop-attributes.js +8 -6
  44. package/lib/non-standard/timetable-notes-references.js +8 -6
  45. package/lib/non-standard/timetable-notes.js +8 -6
  46. package/lib/non-standard/timetable-pages.js +8 -6
  47. package/lib/non-standard/timetable-stop-order.js +8 -6
  48. package/lib/non-standard/timetables.js +8 -6
  49. package/lib/non-standard/trips-dated-vehicle-journey.js +9 -7
  50. package/package.json +4 -4
  51. package/test/mocha/advanced-query.js +9 -15
  52. package/test/mocha/export-gtfs.js +5 -6
  53. package/test/mocha/fare-transfer-rules.js +32 -0
  54. package/test/mocha/get-agencies.js +13 -19
  55. package/test/mocha/get-areas.js +27 -0
  56. package/test/mocha/get-attributions.js +7 -13
  57. package/test/mocha/get-board-alights.js +7 -13
  58. package/test/mocha/get-calendar-dates.js +11 -17
  59. package/test/mocha/get-calendars.js +11 -17
  60. package/test/mocha/get-directions.js +7 -13
  61. package/test/mocha/get-fare-attributes.js +9 -15
  62. package/test/mocha/get-fare-leg-rules.js +27 -0
  63. package/test/mocha/get-fare-products.js +27 -0
  64. package/test/mocha/get-fare-rules.js +9 -15
  65. package/test/mocha/get-feed-info.js +7 -13
  66. package/test/mocha/get-frequencies.js +7 -13
  67. package/test/mocha/get-levels.js +7 -7
  68. package/test/mocha/get-pathways.js +7 -13
  69. package/test/mocha/get-ride-feed-infos.js +7 -13
  70. package/test/mocha/get-rider-trips.js +7 -13
  71. package/test/mocha/get-riderships.js +7 -13
  72. package/test/mocha/get-routes.js +13 -13
  73. package/test/mocha/get-shapes-as-geojson.js +14 -15
  74. package/test/mocha/get-shapes.js +25 -25
  75. package/test/mocha/get-stop-attributes.js +7 -13
  76. package/test/mocha/get-stops-as-geojson.js +13 -19
  77. package/test/mocha/get-stops.js +19 -19
  78. package/test/mocha/get-stoptimes.js +11 -17
  79. package/test/mocha/get-timetable-pages.js +7 -13
  80. package/test/mocha/get-timetable-stop-orders.js +6 -7
  81. package/test/mocha/get-timetables.js +7 -13
  82. package/test/mocha/get-transfers.js +7 -13
  83. package/test/mocha/get-translations.js +7 -13
  84. package/test/mocha/get-trip-capacities.js +7 -13
  85. package/test/mocha/get-trips.js +9 -9
  86. package/test/mocha/import-gtfs.js +11 -11
  87. package/test/mocha/{get-db.js → open-db.js} +37 -29
  88. package/test/mocha/raw-query.js +34 -0
  89. package/test/mocha/exec-raw-query.js +0 -39
  90. package/test/mocha/run-raw-query.js +0 -54
package/README.md CHANGED
@@ -29,13 +29,35 @@ You can use it as a [command-line tool](#command-line-examples) or as a [node.js
29
29
 
30
30
  This library has four parts: the [GTFS import script](#gtfs-import-script), [GTFS export script](#gtfs-export-script) and [GTFS-Realtime update script](#gtfsrealtime-update-script) and the [query methods](#query-methods)
31
31
 
32
+ ## Breaking changes in Version 4
33
+
34
+ Version 4 of node-gtfs switched to using the better-sqlite3 library. This allowed all query methods to become synchronous and speeds up import and export.
35
+
36
+ - All query methods are now synchronous.
37
+
38
+ ```js
39
+ // Version 3
40
+ const routes = await getRoutes();
41
+
42
+ // Version 4
43
+ const routes = getRoutes();
44
+ ```
45
+
46
+ - `runRawQuery` has been removed. Use [Raw SQLite Query](#raw-sqlite-query) instead.
47
+ - `execRawQuery` has been removed. Use [Raw SQLite Query](#raw-sqlite-query) instead.
48
+ - `getDb` has been removed. Use `openDb` instead.
49
+
32
50
  ## Installation
33
51
 
34
- If you would like to use this library as a command-line utility, you can install it globally directly from [npm](https://npmjs.org):
52
+ To use this library as a command-line utility, install it globally [npm](https://npmjs.org):
35
53
 
36
54
  npm install gtfs -g
37
55
 
38
- If you are using this as a node module as part of an application, you can include it in your project's `package.json` file.
56
+ This will add the `gtfs-import` and `gtfs-export` scripts to your path.
57
+
58
+ If you are using this as a node module as part of an application, include it in your project's `package.json` file.
59
+
60
+ npm install gtfs
39
61
 
40
62
  ## Quick Start
41
63
 
@@ -471,11 +493,13 @@ await exportGtfs(config);
471
493
 
472
494
  ## Query Methods
473
495
 
474
- This library includes many methods you can use in your project to query GTFS data. These methods return promises.
496
+ This library includes many methods you can use in your project to query GTFS data.
475
497
 
476
- Most methods accept three optional arguments: `query`, `fields` and `sortBy`.
498
+ Most methods accept three optional arguments: `query`, `fields`, `sortBy` and `options`.
477
499
 
478
- More advanced methods include `advancedQuery`, `runRawQuery` and `execRawQuery`.
500
+ For more advanced queries, you can use `advancedQuery` or any query method from [better-sqlite3](#raw-sqlite-query).
501
+
502
+ You need to run `openDb(config)` before using any query methods.
479
503
 
480
504
  #### Query
481
505
 
@@ -488,11 +512,12 @@ const config = JSON.parse(
488
512
  await readFile(new URL('./config.json', import.meta.url))
489
513
  );
490
514
 
491
- const db = await openDb(config);
492
- const routes = await getRoutes(
493
- {},
494
- ['route_id', 'route_short_name', 'route_color'],
495
- [['route_short_name', 'ASC']]
515
+ const db = openDb(config);
516
+ const routes = getRoutes(
517
+ {}, // No query filters
518
+ ['route_id', 'route_short_name', 'route_color'], // Only return these fields
519
+ [['route_short_name', 'ASC']], // Sort by this field and direction
520
+ { db: db } // Options for the query. Can specify which database to use if more than one are open
496
521
  );
497
522
  ```
498
523
 
@@ -505,8 +530,8 @@ const config = JSON.parse(
505
530
  await readFile(new URL('./config.json', import.meta.url))
506
531
  );
507
532
 
508
- const db = await openDb(config);
509
- const trips = await getTrips(
533
+ const db = openDb(config);
534
+ const trips = getTrips(
510
535
  {
511
536
  route_id: '123',
512
537
  },
@@ -521,8 +546,8 @@ import { openDb, getStops } from 'gtfs';
521
546
  import { readFile } from 'fs/promises';
522
547
  const config = JSON.parse(await readFile(new URL('./config.json', import.meta.url)));
523
548
 
524
- const db = await openDb(config);
525
- const stops = await getStops(
549
+ const db = openDb(config);
550
+ const stops = getStops(
526
551
  {
527
552
  stop_id: [
528
553
  '123',
@@ -544,80 +569,77 @@ import { openDb } from 'gtfs';
544
569
  Open database before making any queries
545
570
 
546
571
  ```js
547
- const db = await openDb(config);
572
+ const db = openDb(config);
548
573
  ```
549
574
 
550
- ### getAgencies(query, fields, sortBy)
575
+ ### getAgencies(query, fields, sortBy, options)
551
576
 
552
- Queries agencies and returns a promise. The result of the promise is an array of agencies.
577
+ Returns an array of agencies that match query parameters. [Details on agency.txt](https://gtfs.org/schedule/reference/#agencytxt)
553
578
 
554
579
  ```js
555
580
  import { getAgencies } from 'gtfs';
556
581
 
557
582
  // Get all agencies
558
- const agencies = await getAgencies();
583
+ const agencies = getAgencies();
559
584
 
560
585
  // Get a specific agency
561
- const agencies = await getAgencies({
586
+ const agencies = getAgencies({
562
587
  agency_id: 'caltrain',
563
588
  });
564
589
  ```
565
590
 
566
- ### getAreas(query, fields, sortBy)
591
+ ### getAreas(query, fields, sortBy, options)
567
592
 
568
- Queries areas and returns a promise. The result of the promise is an array of areas.
593
+ Returns an array of areas that match query parameters. [Details on areas.txt](https://gtfs.org/schedule/reference/#areastxt)
569
594
 
570
595
  ```js
571
596
  import { getAreas } from 'gtfs';
572
597
 
573
598
  // Get all areas
574
- const areas = await getAreas();
599
+ const areas = getAreas();
575
600
 
576
601
  // Get a specific area
577
- const areas = await getAreas({
602
+ const areas = getAreas({
578
603
  area_id: 'area1',
579
604
  });
580
605
  ```
581
606
 
582
- ### getAttributions(query, fields, sortBy)
607
+ ### getAttributions(query, fields, sortBy, options)
583
608
 
584
- Queries attributions and returns a promise. The result of the promise is an array of attributions.
609
+ Returns an array of attributions that match query parameters. [Details on attributions.txt](https://gtfs.org/schedule/reference/#attributionstxt)
585
610
 
586
611
  ```js
587
612
  import { getAttributions } from 'gtfs';
588
613
 
589
614
  // Get all attributions
590
- const attributions = await getAttributions();
615
+ const attributions = getAttributions();
591
616
 
592
617
  // Get a specific attribution
593
- const attributions = await getAttributions({
618
+ const attributions = getAttributions({
594
619
  attribution_id: '123',
595
620
  });
596
621
  ```
597
622
 
598
- ### getRoutes(query, fields, sortBy)
623
+ ### getRoutes(query, fields, sortBy, options)
599
624
 
600
- Queries routes and returns a promise. The result of the promise is an array of routes.
625
+ Returns an array of routes that match query parameters. [Details on routes.txt](https://gtfs.org/schedule/reference/#routestxt)
601
626
 
602
627
  ```js
603
628
  import { getRoutes } from 'gtfs';
604
629
 
605
630
  // Get all routes, sorted by route_short_name
606
- const routes = await getRoutes({}, [], [['route_short_name', 'ASC']]);
631
+ const routes = getRoutes({}, [], [['route_short_name', 'ASC']]);
607
632
 
608
633
  // Get a specific route
609
- const routes = await getRoutes({
634
+ const routes = getRoutes({
610
635
  route_id: 'Lo-16APR',
611
636
  });
612
- ```
613
-
614
- `getRoutes` allows passing a `stop_id` in the query and it will query stoptimes and trips to find all routes that serve that `stop_id`.
615
637
 
616
- ```js
617
- import { getRoutes } from 'gtfs';
618
-
619
- // Get routes that serve a specific stop, sorted by `stop_name`.
620
- const routes = await getRoutes(
638
+ /*
639
+ * `getRoutes` allows passing a `stop_id` as part of the query. This will
640
+ * query stoptimes and trips to find all routes that serve that `stop_id`.
641
+ */
642
+ const routes = getRoutes(
621
643
  {
622
644
  stop_id: '70011',
623
645
  },
@@ -626,18 +648,18 @@ const routes = await getRoutes(
626
648
  );
627
649
  ```
628
650
 
629
- ### getStops(query, fields, sortBy)
651
+ ### getStops(query, fields, sortBy, options)
630
652
 
631
- Queries stops and returns a promise. The result of the promise is an array of stops.
653
+ Returns an array of stops that match query parameters. [Details on stops.txt](https://gtfs.org/schedule/reference/#stopstxt)
632
654
 
633
655
  ```js
634
656
  import { getStops } from 'gtfs';
635
657
 
636
658
  // Get all stops
637
- const stops = await getStops();
659
+ const stops = getStops();
638
660
 
639
661
  // Get a specific stop by stop_id
640
- const stops = await getStops({
662
+ const stops = getStops({
641
663
  stop_id: '70011',
642
664
  });
643
665
 
@@ -645,7 +667,7 @@ const stops = await getStops({
645
667
  * `getStops` allows passing a `route_id` in the query and it will
646
668
  * query trips and stoptimes to find all stops served by that `route_id`.
647
669
  */
648
- const stops = await getStops({
670
+ const stops = getStops({
649
671
  route_id: 'Lo-16APR',
650
672
  });
651
673
 
@@ -653,7 +675,7 @@ const stops = await getStops({
653
675
  * `getStops` allows passing a `trip_id` in the query and it will query
654
676
  * stoptimes to find all stops on that `trip_id`.
655
677
  */
656
- const stops = await getStops({
678
+ const stops = getStops({
657
679
  trip_id: '37a',
658
680
  });
659
681
 
@@ -661,44 +683,44 @@ const stops = await getStops({
661
683
  * `getStops` allows passing a `shape_id` in the query and it will query
662
684
  * trips and stoptimes to find all stops that use that `shape_id`.
663
685
  */
664
- const stops = await getStops({
686
+ const stops = getStops({
665
687
  shape_id: 'cal_sf_tam',
666
688
  });
667
689
  ```
668
690
 
669
- ### getStopsAsGeoJSON(query)
691
+ ### getStopsAsGeoJSON(query, options)
670
692
 
671
- Queries stops and returns a promise. The result of the promise is an geoJSON object of stops. All valid queries for `getStops()` work for `getStopsAsGeoJSON()`.
693
+ Returns geoJSON object of stops that match query parameters. All valid queries for `getStops()` work for `getStopsAsGeoJSON()`.
672
694
 
673
695
  ```js
674
696
  import { getStopsAsGeoJSON } from 'gtfs';
675
697
 
676
698
  // Get all stops for an agency as geoJSON
677
- const stopsGeojson = await getStopsAsGeoJSON();
699
+ const stopsGeojson = getStopsAsGeoJSON();
678
700
 
679
701
  // Get all stops for a specific route as geoJSON
680
- const stopsGeojson = await getStopsAsGeoJSON({
702
+ const stopsGeojson = getStopsAsGeoJSON({
681
703
  route_id: 'Lo-16APR',
682
704
  });
683
705
  ```
684
706
 
685
- ### getStoptimes(query, fields, sortBy)
707
+ ### getStoptimes(query, fields, sortBy, options)
686
708
 
687
- Queries `stop_times` and returns a promise. The result of the promise is an array of `stop_times`.
709
+ Returns an array of stop_times that match query parameters. [Details on stop_times.txt](https://gtfs.org/schedule/reference/#stop_timestxt)
688
710
 
689
711
  ```js
690
712
  import { getStoptimes } from 'gtfs';
691
713
 
692
714
  // Get all stoptimes
693
- const stoptimes = await getStoptimes();
715
+ const stoptimes = getStoptimes();
694
716
 
695
717
  // Get all stoptimes for a specific stop
696
- const stoptimes = await getStoptimes({
718
+ const stoptimes = getStoptimes({
697
719
  stop_id: '70011',
698
720
  });
699
721
 
700
722
  // Get all stoptimes for a specific trip, sorted by stop_sequence
701
- const stoptimes = await getStoptimes(
723
+ const stoptimes = getStoptimes(
702
724
  {
703
725
  trip_id: '37a',
704
726
  },
@@ -707,60 +729,57 @@ const stoptimes = await getStoptimes(
707
729
  );
708
730
 
709
731
  // Get all stoptimes for a specific stop and service_id
710
- const stoptimes = await getStoptimes({
732
+ const stoptimes = getStoptimes({
711
733
  stop_id: '70011',
712
734
  service_id: 'CT-16APR-Caltrain-Weekday-01',
713
735
  });
714
736
  ```
715
737
 
716
- ### getTrips(query, fields, sortBy)
738
+ ### getTrips(query, fields, sortBy, options)
717
739
 
718
- Queries trips and returns a promise. The result of the promise is an array of trips.
740
+ Returns an array of trips that match query parameters. [Details on trips.txt](https://gtfs.org/schedule/reference/#tripstxt)
719
741
 
720
742
  ```js
721
743
  import { getTrips } from 'gtfs';
722
744
 
723
745
  // Get all trips
724
- const trips = await getTrips();
746
+ const trips = getTrips();
725
747
 
726
748
  // Get trips for a specific route and direction
727
- const trips = await getTrips({
749
+ const trips = getTrips({
728
750
  route_id: 'Lo-16APR',
729
751
  direction_id: 0
730
752
  });
731
753
 
732
754
  // Get trips for direction '' or null
733
- const trips = await getTrips({
755
+ const trips = getTrips({
734
756
  route_id: 'Lo-16APR',
735
757
  direction_id: null
736
758
  });
737
759
 
738
760
  // Get trips for a specific route and direction limited by a service_id
739
- const trips = await getTrips({
761
+ const trips = getTrips({
740
762
  route_id: 'Lo-16APR',
741
763
  direction_id: 0,
742
764
  service_id: '
743
765
  });
744
766
  ```
745
767
 
746
- ### getShapes(query, fields, sortBy)
768
+ ### getShapes(query, fields, sortBy, options)
747
769
 
748
- Queries shapes and returns a promise. The result of the promise is an array of shapes.
770
+ Returns an array of shapes that match query parameters. [Details on shapes.txt](https://gtfs.org/schedule/reference/#shapestxt)
749
771
 
750
772
  ```js
751
773
  import { getShapes } from 'gtfs';
752
774
 
753
775
  // Get all shapes for an agency
754
- const shapes = await getShapes();
755
- ```
776
+ const shapes = getShapes();
756
777
 
757
- `getShapes` allows passing a `route_id` in the query and it will query trips to find all shapes served by that `route_id`.
758
-
759
- ```js
760
- import { getShapes } from 'gtfs';
761
-
762
- // Get all shapes for a specific route and direction
763
- const shapes = await getShapes({
778
+ /*
779
+ * `getShapes` allows passing a `route_id` in the query and it will query
780
+ * trips to find all shapes served by that `route_id`.
781
+ */
782
+ const shapes = getShapes({
764
783
  route_id: 'Lo-16APR',
765
784
  });
766
785
 
@@ -768,7 +787,7 @@ const shapes = await getShapes({
768
787
  * `getShapes` allows passing a `trip_id` in the query and it will query
769
788
  * trips to find all shapes served by that `trip_id`.
770
789
  */
771
- const shapes = await getShapes({
790
+ const shapes = getShapes({
772
791
  trip_id: '37a',
773
792
  });
774
793
 
@@ -776,427 +795,422 @@ const shapes = await getShapes({
776
795
  * `getShapes` allows passing a `service_id` in the query and it will query
777
796
  * trips to find all shapes served by that `service_id`.
778
797
  */
779
- const shapes = await getShapes({
798
+ const shapes = getShapes({
780
799
  service_id: 'CT-16APR-Caltrain-Sunday-02',
781
800
  });
782
801
  ```
783
802
 
784
- ### getShapesAsGeoJSON(query)
803
+ ### getShapesAsGeoJSON(query, options)
785
804
 
786
- Queries shapes and returns a promise. The result of the promise is an geoJSON object of shapes. All valid queries for `getShapes()` work for `getShapesAsGeoJSON()`.
805
+ Returns a geoJSON object of shapes that match query parameters. All valid queries for `getShapes()` work for `getShapesAsGeoJSON()`.
787
806
 
788
807
  ```js
789
808
  import { getShapesAsGeoJSON } from 'gtfs';
790
809
 
791
810
  // Get geoJSON of all routes in an agency
792
- const shapesGeojson = await getShapesAsGeoJSON();
811
+ const shapesGeojson = getShapesAsGeoJSON();
793
812
 
794
813
  // Get geoJSON of shapes for a specific route
795
- const shapesGeojson = await getShapesAsGeoJSON({
814
+ const shapesGeojson = getShapesAsGeoJSON({
796
815
  route_id: 'Lo-16APR',
797
816
  });
798
817
 
799
818
  // Get geoJSON of shapes for a specific trip
800
- const shapesGeojson = await getShapesAsGeoJSON({
819
+ const shapesGeojson = getShapesAsGeoJSON({
801
820
  trip_id: '37a',
802
821
  });
803
822
 
804
823
  // Get geoJSON of shapes for a specific `service_id`
805
- const shapesGeojson = await getShapesAsGeoJSON({
824
+ const shapesGeojson = getShapesAsGeoJSON({
806
825
  service_id: 'CT-16APR-Caltrain-Sunday-02',
807
826
  });
808
827
 
809
828
  // Get geoJSON of shapes for a specific `shape_id`
810
- const shapesGeojson = await getShapesAsGeoJSON({
829
+ const shapesGeojson = getShapesAsGeoJSON({
811
830
  shape_id: 'cal_sf_tam',
812
831
  });
813
832
  ```
814
833
 
815
- ### getCalendars(query, fields, sortBy)
834
+ ### getCalendars(query, fields, sortBy, options)
816
835
 
817
- Queries calendars and returns a promise. The result of the promise is an array of calendars.
836
+ Returns an array of calendars that match query parameters. [Details on calendar.txt](https://gtfs.org/schedule/reference/#calendartxt)
818
837
 
819
838
  ```js
820
839
  import { getCalendars } from 'gtfs';
821
840
 
822
841
  // Get all calendars for an agency
823
- const calendars = await getCalendars();
842
+ const calendars = getCalendars();
824
843
 
825
844
  // Get calendars for a specific `service_id`
826
- const calendars = await getCalendars({
845
+ const calendars = getCalendars({
827
846
  service_id: 'CT-16APR-Caltrain-Sunday-02',
828
847
  });
829
848
  ```
830
849
 
831
- ### getCalendarDates(query, fields, sortBy)
850
+ ### getCalendarDates(query, fields, sortBy, options)
832
851
 
833
- Queries calendar_dates and returns a promise. The result of the promise is an array of calendar_dates.
852
+ Returns an array of calendar_dates that match query parameters. [Details on calendar_dates.txt](https://gtfs.org/schedule/reference/#calendar_datestxt)
834
853
 
835
854
  ```js
836
855
  import { getCalendarDates } from 'gtfs';
837
856
 
838
857
  // Get all calendar_dates for an agency
839
- const calendarDates = await getCalendarDates();
858
+ const calendarDates = getCalendarDates();
840
859
 
841
860
  // Get calendar_dates for a specific `service_id`
842
- const calendarDates = await getCalendarDates({
861
+ const calendarDates = getCalendarDates({
843
862
  service_id: 'CT-16APR-Caltrain-Sunday-02',
844
863
  });
845
864
  ```
846
865
 
847
- ### getFareAttributes(query, fields, sortBy)
866
+ ### getFareAttributes(query, fields, sortBy, options)
848
867
 
849
- Queries fare_attributes and returns a promise. The result of the promise is an array of fare_attributes.
868
+ Returns an array of fare_attributes that match query parameters. [Details on fare_attributes.txt](https://gtfs.org/schedule/reference/#fare_attributestxt)
850
869
 
851
870
  ```js
852
871
  import { getFareAttributes } from 'gtfs';
853
872
 
854
873
  // Get all `fare_attributes` for an agency
855
- const fareAttributes = await getFareAttributes();
874
+ const fareAttributes = getFareAttributes();
856
875
 
857
876
  // Get `fare_attributes` for a specific `fare_id`
858
- const fareAttributes = await getFareAttributes({
877
+ const fareAttributes = getFareAttributes({
859
878
  fare_id: '123',
860
879
  });
861
880
  ```
862
881
 
863
- ### getFareLegRules(query, fields, sortBy)
882
+ ### getFareLegRules(query, fields, sortBy, options)
864
883
 
865
- Queries fare leg rules and returns a promise. The result of the promise is an array of fare leg rules.
884
+ Returns an array of fare_leg_rules that match query parameters. [Details on fare_leg_rules.txt](https://gtfs.org/schedule/reference/#fare_leg_rulestxt)
866
885
 
867
886
  ```js
868
887
  import { getFareLegRules } from 'gtfs';
869
888
 
870
889
  // Get all fare leg rules
871
- const fareLegRules = await getFareLegRules();
890
+ const fareLegRules = getFareLegRules();
872
891
 
873
892
  // Get fare leg rules for a specific fare product
874
- const fareLegRules = await getFareLegRules({
893
+ const fareLegRules = getFareLegRules({
875
894
  fare_product_id: 'product1',
876
895
  });
877
896
  ```
878
897
 
879
- ### getFareProducts(query, fields, sortBy)
898
+ ### getFareProducts(query, fields, sortBy, options)
880
899
 
881
- Queries fare products and returns a promise. The result of the promise is an array of fare products.
900
+ Returns an array of fare_products that match query parameters. [Details on fare_products.txt](https://gtfs.org/schedule/reference/#fare_productstxt)
882
901
 
883
902
  ```js
884
903
  import { getFareProducts } from 'gtfs';
885
904
 
886
905
  // Get all fare products
887
- const fareProducts = await getFareProducts();
906
+ const fareProducts = getFareProducts();
888
907
 
889
908
  // Get a specific fare product
890
- const fareProducts = await getFareProducts({
909
+ const fareProducts = getFareProducts({
891
910
  fare_product_id: 'product1',
892
911
  });
893
912
  ```
894
913
 
895
- ### getFareRules(query, fields, sortBy)
914
+ ### getFareRules(query, fields, sortBy, options)
896
915
 
897
- Queries fare_rules and returns a promise. The result of the promise is an array of fare_rules.
916
+ Returns an array of fare_rules that match query parameters. [Details on fare_rules.txt](https://gtfs.org/schedule/reference/#fare_rulestxt)
898
917
 
899
918
  ```js
900
919
  import { getFareRules } from 'gtfs';
901
920
 
902
921
  // Get all `fare_rules` for an agency
903
- const fareRules = await getFareRules();
922
+ const fareRules = getFareRules();
904
923
 
905
924
  // Get fare_rules for a specific route
906
- const fareRules = await getFareRules({
925
+ const fareRules = getFareRules({
907
926
  route_id: 'Lo-16APR',
908
927
  });
909
928
  ```
910
929
 
911
- ### getFareTransferRules(query, fields, sortBy)
930
+ ### getFareTransferRules(query, fields, sortBy, options)
912
931
 
913
- Queries fare transfer rules and returns a promise. The result of the promise is an array of fare transfer rules.
932
+ Returns an array of fare_transfer_rules that match query parameters. [Details on fare_transfer_rules.txt](https://gtfs.org/schedule/reference/#fare_transfer_rulestxt)
914
933
 
915
934
  ```js
916
935
  import { getFareTransferRules } from 'gtfs';
917
936
 
918
937
  // Get all fare transfer rules
919
- const fareTransferRules = await getFareTransferRules();
938
+ const fareTransferRules = getFareTransferRules();
920
939
 
921
940
  // Get a all fare transfer rules for a specific fare product
922
- const fareTransferRules = await getFareTransferRules({
941
+ const fareTransferRules = getFareTransferRules({
923
942
  fare_product_id: 'product1',
924
943
  });
925
944
  ```
926
945
 
927
- ### getFeedInfo(query, fields, sortBy)
946
+ ### getFeedInfo(query, fields, sortBy, options)
928
947
 
929
- Queries feed_info and returns a promise. The result of the promise is an array of feed_infos.
948
+ Returns an array of feed_info that match query parameters. [Details on feed_info.txt](https://gtfs.org/schedule/reference/#feed_infotxt)
930
949
 
931
950
  ```js
932
951
  import { getFeedInfo } from 'gtfs';
933
952
 
934
953
  // Get feed_info
935
- const feedInfo = await getFeedInfo();
954
+ const feedInfo = getFeedInfo();
936
955
  ```
937
956
 
938
- ### getFrequencies(query, fields, sortBy)
957
+ ### getFrequencies(query, fields, sortBy, options)
939
958
 
940
- Queries frequencies and returns a promise. The result of the promise is an array of frequencies.
959
+ Returns an array of frequencies that match query parameters. [Details on frequencies.txt](https://gtfs.org/schedule/reference/#frequenciestxt)
941
960
 
942
961
  ```js
943
962
  import { getFrequencies } from 'gtfs';
944
963
 
945
964
  // Get all frequencies
946
- const frequencies = await getFrequencies();
965
+ const frequencies = getFrequencies();
947
966
 
948
967
  // Get frequencies for a specific trip
949
- const frequencies = await getFrequencies({
968
+ const frequencies = getFrequencies({
950
969
  trip_id: '1234',
951
970
  });
952
971
  ```
953
972
 
954
- ### getLevels(query, fields, sortBy)
973
+ ### getLevels(query, fields, sortBy, options)
955
974
 
956
- Queries levels and returns a promise. The result of the promise is an array of levels.
975
+ Returns an array of levels that match query parameters. [Details on levels.txt](https://gtfs.org/schedule/reference/#levelstxt)
957
976
 
958
977
  ```js
959
978
  import { getLevels } from 'gtfs';
960
979
 
961
980
  // Get all levels
962
- const levels = await getLevels();
981
+ const levels = getLevels();
963
982
  ```
964
983
 
965
- ### getPathways(query, fields, sortBy)
984
+ ### getPathways(query, fields, sortBy, options)
966
985
 
967
- Queries pathways and returns a promise. The result of the promise is an array of pathways.
986
+ Returns an array of pathways that match query parameters. [Details on pathways.txt](https://gtfs.org/schedule/reference/#pathwaystxt)
968
987
 
969
988
  ```js
970
989
  import { getPathways } from 'gtfs';
971
990
 
972
991
  // Get all pathways
973
- const pathways = await getPathways();
992
+ const pathways = getPathways();
974
993
  ```
975
994
 
976
- ### getTransfers(query, fields, sortBy)
995
+ ### getTransfers(query, fields, sortBy, options)
977
996
 
978
- Queries transfers and returns a promise. The result of the promise is an array of transfers.
997
+ Returns an array of transfers that match query parameters. [Details on transfers.txt](https://gtfs.org/schedule/reference/#transferstxt)
979
998
 
980
999
  ```js
981
1000
  import { getTransfers } from 'gtfs';
982
1001
 
983
1002
  // Get all transfers
984
- const transfers = await getTransfers();
1003
+ const transfers = getTransfers();
985
1004
 
986
1005
  // Get transfers for a specific stop
987
- const transfers = await getTransfers({
1006
+ const transfers = getTransfers({
988
1007
  from_stop_id: '1234',
989
1008
  });
990
1009
  ```
991
1010
 
992
- ### getTranslations(query, fields, sortBy)
1011
+ ### getTranslations(query, fields, sortBy, options)
993
1012
 
994
- Queries translations and returns a promise. The result of the promise is an array of translations.
1013
+ Returns an array of translations that match query parameters. [Details on translations.txt](https://gtfs.org/schedule/reference/#translationstxt)
995
1014
 
996
1015
  ```js
997
1016
  import { getTranslations } from 'gtfs';
998
1017
 
999
1018
  // Get all translations
1000
- const translations = await getTranslations();
1019
+ const translations = getTranslations();
1001
1020
  ```
1002
1021
 
1003
- ### getDirections(query, fields, sortBy)
1022
+ ### getStopAreas(query, fields, sortBy, options)
1004
1023
 
1005
- Queries directions and returns a promise. The result of the promise is an array of directions. These are from the non-standard `directions.txt` file. See [documentation and examples of this file](https://trilliumtransit.com/gtfs/reference/#directions).
1024
+ Returns an array of stop_areas that match query parameters. [Details on stop_areas.txt](https://gtfs.org/schedule/reference/#stop_areastxt)
1025
+
1026
+ ```js
1027
+ import { getStopAreas } from 'gtfs';
1028
+
1029
+ // Get all stop areas
1030
+ const stopAreas = getStopAreas();
1031
+ ```
1032
+
1033
+ ### getDirections(query, fields, sortBy, options)
1034
+
1035
+ Returns an array of directions that match query parameters. This is for the non-standard `directions.txt` file. [Details on directions.txt](https://trilliumtransit.com/gtfs/reference/#directions)
1006
1036
 
1007
1037
  ```js
1008
1038
  import { getDirections } from 'gtfs';
1009
1039
 
1010
1040
  // Get all directions
1011
- const directions = await getDirections();
1041
+ const directions = getDirections();
1012
1042
 
1013
1043
  // Get directions for a specific route
1014
- const directions = await getDirections({
1044
+ const directions = getDirections({
1015
1045
  route_id: '1234',
1016
1046
  });
1017
1047
 
1018
1048
  // Get directions for a specific route and direction
1019
- const directions = await getDirections({
1049
+ const directions = getDirections({
1020
1050
  route_id: '1234',
1021
1051
  direction_id: 1,
1022
1052
  });
1023
1053
  ```
1024
1054
 
1025
- ### getStopAreas(query, fields, sortBy)
1026
-
1027
- Queries stop areas and returns a promise. The result of the promise is an array of stop areas.
1028
-
1029
- ```js
1030
- import { getStopAreas } from 'gtfs';
1031
-
1032
- // Get all stop areas
1033
- const stopAreas = await getStopAreas();
1034
- ```
1035
-
1036
- ### getStopAttributes(query, fields, sortBy)
1055
+ ### getStopAttributes(query, fields, sortBy, options)
1037
1056
 
1038
- Queries stop_attributes and returns a promise. The result of the promise is an array of stop_attributes. These are from the non-standard `stop_attributes.txt` file. See [documentation and examples of this file](https://gtfstohtml.com/docs/stop-attributes).
1057
+ Returns an array of stop_attributes that match query parameters. This is for the non-standard `stop_attributes.txt` file. [Details on stop_attributes.txt](https://trilliumtransit.com/gtfs/reference/#stop_attributes)
1039
1058
 
1040
1059
  ```js
1041
1060
  import { getStopAttributes } from 'gtfs';
1042
1061
 
1043
1062
  // Get all stop attributes
1044
- const stopAttributes = await getStopAttributes();
1063
+ const stopAttributes = getStopAttributes();
1045
1064
 
1046
1065
  // Get stop attributes for specific stop
1047
- const stopAttributes = await getStopAttributes({
1066
+ const stopAttributes = getStopAttributes({
1048
1067
  stop_id: '1234',
1049
1068
  });
1050
1069
  ```
1051
1070
 
1052
- ### getTimetables(query, fields, sortBy)
1071
+ ### getTimetables(query, fields, sortBy, options)
1053
1072
 
1054
- Queries timetables and returns a promise. The result of the promise is an array of timetables. These are from the non-standard `timetables.txt` file. See [documentation and examples of this file](https://gtfstohtml.com/docs/timetables.
1073
+ Returns an array of timetables that match query parameters. This is for the non-standard `timetables.txt` file used in GTFS-to-HTML. [Details on timetables.txt](https://gtfstohtml.com/docs/timetables)
1055
1074
 
1056
1075
  ```js
1057
1076
  import { getTimetables } from 'gtfs';
1058
1077
 
1059
1078
  // Get all timetables for an agency
1060
- const timetables = await getTimetables();
1079
+ const timetables = getTimetables();
1061
1080
 
1062
1081
  // Get a specific timetable
1063
- const timetables = await getTimetables({
1082
+ const timetables = getTimetables({
1064
1083
  timetable_id: '1',
1065
1084
  });
1066
1085
  ```
1067
1086
 
1068
- ### getTimetableStopOrders(query, fields, sortBy)
1087
+ ### getTimetableStopOrders(query, fields, sortBy, options)
1069
1088
 
1070
- Queries timetable_stop_orders and returns a promise. The result of the promise is an array of timetable_stop_orders. These are from the non-standard `timetable_stop_order.txt` file. See [documentation and examples of this file](https://gtfstohtml.com/docs/timetable-stop-order).
1089
+ Returns an array of timetable_stop_orders that match query parameters. This is for the non-standard `timetable_stop_order.txt` file used in GTFS-to-HTML. [Details on timetable_stop_order.txt](https://gtfstohtml.com/docs/timetable-stop-order)
1071
1090
 
1072
1091
  ```js
1073
1092
  import { getTimetableStopOrders } from 'gtfs';
1074
1093
 
1075
1094
  // Get all timetable_stop_orders
1076
- const timetableStopOrders = await getTimetableStopOrders();
1095
+ const timetableStopOrders = getTimetableStopOrders();
1077
1096
 
1078
1097
  // Get timetable_stop_orders for a specific timetable
1079
- const timetableStopOrders = await getTimetableStopOrders({
1098
+ const timetableStopOrders = getTimetableStopOrders({
1080
1099
  timetable_id: '1',
1081
1100
  });
1082
1101
  ```
1083
1102
 
1084
- ### getTimetablePages(query, fields, sortBy)
1103
+ ### getTimetablePages(query, fields, sortBy, options)
1085
1104
 
1086
- Queries timetable_pages and returns a promise. The result of the promise is an array of timetable_pages. These are from the non-standard `timetable_pages.txt` file. See [documentation and examples of this file](https://gtfstohtml.com/docs/timetable-pages).
1105
+ Returns an array of timetable_pages that match query parameters. This is for the non-standard `timetable_pages.txt` file used in GTFS-to-HTML. [Details on timetable_pages.txt](https://gtfstohtml.com/docs/timetable-pages)
1087
1106
 
1088
1107
  ```js
1089
1108
  import { getTimetablePages } from 'gtfs';
1090
1109
 
1091
1110
  // Get all timetable_pages for an agency
1092
- const timetablePages = await getTimetablePages();
1111
+ const timetablePages = getTimetablePages();
1093
1112
 
1094
1113
  // Get a specific timetable_page
1095
- const timetablePages = await getTimetablePages({
1114
+ const timetablePages = getTimetablePages({
1096
1115
  timetable_page_id: '2',
1097
1116
  });
1098
1117
  ```
1099
1118
 
1100
- ### getTimetableNotes(query, fields, sortBy)
1119
+ ### getTimetableNotes(query, fields, sortBy, options)
1101
1120
 
1102
- Queries timetable_notes and returns a promise. The result of the promise is an array of timetable_notes. These are from the non-standard `timetable_notes.txt` file. See [documentation and examples of this file](https://gtfstohtml.com/docs/timetable-notes).
1121
+ Returns an array of timetable_notes that match query parameters. This is for the non-standard `timetable_notes.txt` file used in GTFS-to-HTML. [Details on timetable_notes.txt](https://gtfstohtml.com/docs/timetable-notes)
1103
1122
 
1104
1123
  ```js
1105
1124
  import { getTimetableNotes } from 'gtfs';
1106
1125
 
1107
1126
  // Get all timetable_notes for an agency
1108
- const timetableNotes = await getTimetableNotes();
1127
+ const timetableNotes = getTimetableNotes();
1109
1128
 
1110
1129
  // Get a specific timetable_note
1111
- const timetableNotes = await getTimetableNotes({
1130
+ const timetableNotes = getTimetableNotes({
1112
1131
  note_id: '1',
1113
1132
  });
1114
1133
  ```
1115
1134
 
1116
- ### getTimetableNotesReferences(query, fields, sortBy)
1135
+ ### getTimetableNotesReferences(query, fields, sortBy, options)
1117
1136
 
1118
- Queries timetable_notes_references and returns a promise. The result of the promise is an array of timetable_notes_references. These are from the non-standard `timetable_notes_references.txt` file. See [documentation and examples of this file](https://gtfstohtml.com/docs/timetable-notes-references).
1137
+ Returns an array of timetable_notes_references that match query parameters. This is for the non-standard `timetable_notes_references.txt` file used in GTFS-to-HTML. [Details on timetable_notes_references.txt](https://gtfstohtml.com/docs/timetable-notes-references)
1119
1138
 
1120
1139
  ```js
1121
1140
  import { getTimetableNotesReferences } from 'gtfs';
1122
1141
 
1123
1142
  // Get all timetable_notes_references for an agency
1124
- const timetableNotesReferences = await getTimetableNotesReferences();
1143
+ const timetableNotesReferences = getTimetableNotesReferences();
1125
1144
 
1126
1145
  // Get all timetable_notes_references for a specific timetable
1127
- const timetableNotesReferences = await getTimetableNotesReferences({
1146
+ const timetableNotesReferences = getTimetableNotesReferences({
1128
1147
  timetable_id: '4',
1129
1148
  });
1130
1149
  ```
1131
1150
 
1132
- ### getTripsDatedVehicleJourneys(query, fields, sortBy)
1151
+ ### getTripsDatedVehicleJourneys(query, fields, sortBy, options)
1133
1152
 
1134
- Queries trips_dated_vehicle_journey and returns a promise. The result of the promise is an array of trips_dated_vehicle_journey. These are from the non-standard `trips-dated-vehicle-journey.txt` file. See [documentation and examples of this file](https://www.trafiklab.se/api/trafiklab-apis/gtfs-regional/extra-files/).
1153
+ Returns an array of trips_dated_vehicle_journey that match query parameters. This is for the non-standard `trips_dated_vehicle_journey.txt` file. [Details on trips_dated_vehicle_journey.txt](https://www.trafiklab.se/api/trafiklab-apis/gtfs-regional/extra-files/)
1135
1154
 
1136
1155
  ```js
1137
1156
  import { getTripsDatedVehicleJourneys } from 'gtfs';
1138
1157
 
1139
1158
  // Get all timetable_stop_orders
1140
- const tripsDatedVehicleJourneys = await getTripsDatedVehicleJourneys();
1159
+ const tripsDatedVehicleJourneys = getTripsDatedVehicleJourneys();
1141
1160
  ```
1142
1161
 
1143
- ### getServiceAlerts(query, fields, sortBy)
1162
+ ### getServiceAlerts(query, fields, sortBy, options)
1144
1163
 
1145
- Queries service alerts and returns a promise. The result of the promise is an array of service alerts.
1146
- These are only valid if you use GTFS-Realtime and have imported Service Alert data.
1164
+ Returns an array of GTFS Realtime service alerts that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Service Alerts](https://gtfs.org/realtime/feed-entities/service-alerts/)
1147
1165
 
1148
1166
  ```js
1149
1167
  import { getServiceAlerts } from 'gtfs';
1150
1168
 
1151
1169
  // Get service alerts
1152
- const serviceAlerts = await getServiceAlerts();
1170
+ const serviceAlerts = getServiceAlerts();
1153
1171
  ```
1154
1172
 
1155
- ### getTripUpdates(query, fields, sortBy)
1173
+ ### getTripUpdates(query, fields, sortBy, options)
1156
1174
 
1157
- Queries trip alerts and returns a promise. The result of the promise is an array of trip updates.
1158
- These are only valid if you use GTFS-Realtime and have imported Trip Update data.
1175
+ Returns an array of GTFS Realtime trip updates that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Trip Updates](https://gtfs.org/realtime/feed-entities/trip-updates/)
1159
1176
 
1160
1177
  ```js
1161
1178
  import { getTripUpdates } from 'gtfs';
1162
1179
 
1163
1180
  // Get all trip updates
1164
- const tripUpdates = await getTripUpdates();
1181
+ const tripUpdates = getTripUpdates();
1165
1182
  ```
1166
1183
 
1167
- ### getStopTimesUpdates(query, fields, sortBy)
1184
+ ### getStopTimesUpdates(query, fields, sortBy, options)
1168
1185
 
1169
- Queries stop times updates and returns a promise. The result of the promise is an array of stop times updates.
1170
- These are only valid if you use GTFS-Realtime and have imported Trip Update data.
1186
+ Returns an array of GTFS Realtime stop time updates that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Stop Time Updates](https://gtfs.org/realtime/feed-entities/trip-updates/#stoptimeupdate)
1171
1187
 
1172
1188
  ```js
1173
1189
  import { getStopTimesUpdates } from 'gtfs';
1174
1190
 
1175
1191
  // Get all stop times updates
1176
- const stopTimesUpdates = await getStopTimesUpdates();
1192
+ const stopTimesUpdates = getStopTimesUpdates();
1177
1193
  ```
1178
1194
 
1179
- ### getVehiclePositions(query, fields, sortBy)
1195
+ ### getVehiclePositions(query, fields, sortBy, options)
1180
1196
 
1181
- Queries vehicle positions and returns a promise. The result of the promise is an array of vehicle location data.
1182
- These are only valid if you use GTFS-Realtime and have imported Vehicle Position data.
1197
+ Returns an array of GTFS Realtime vehicle positions that match query parameters. This only works if you configure GTFS Realtime import in node-gtfs. [Details on Vehicle Positions](https://gtfs.org/realtime/feed-entities/vehicle-positions/)
1183
1198
 
1184
1199
  ```js
1185
1200
  import { getVehiclePositions } from 'gtfs';
1186
1201
 
1187
1202
  // Get all vehicle position data
1188
- const vehiclePositions = await getVehiclePositions();
1203
+ const vehiclePositions = getVehiclePositions();
1189
1204
  ```
1190
1205
 
1191
1206
  ### advancedQuery(table, advancedQueryOptions)
1192
1207
 
1193
- Queries the database in a simple manner with support for table joins and custom tables. Returns a promise.
1194
- The result of the promise is an array the selected data. Example shows joining stop_times with trips.
1195
- Used for advanced scenarios.
1208
+ Queries the database with support for table joins and custom tables and returns an array of data.
1196
1209
 
1197
1210
  ```js
1198
1211
  import { advancedQuery } from 'gtfs';
1199
1212
 
1213
+ // Example `advancedQuery` joining stop_times with trips.
1200
1214
  const advancedQueryOptions = {
1201
1215
  query: {
1202
1216
  'stop_times.trip_id': tripId,
@@ -1211,33 +1225,40 @@ const advancedQueryOptions = {
1211
1225
  ],
1212
1226
  };
1213
1227
 
1214
- // Perform a custom query
1215
- const stoptimes = await advancedQuery('stop_times', advancedQueryOptions);
1228
+ const stoptimes = advancedQuery('stop_times', advancedQueryOptions);
1216
1229
  ```
1217
1230
 
1218
- ### runRawQuery(query)
1231
+ ### Raw SQLite Query
1219
1232
 
1220
- Queries the database using a raw sql statement. Returns a promise.
1221
- The result of the promise is an array the selected data.
1233
+ Use the `openDb` function to get the db object, and then use any query method from [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) to query GTFS data.
1222
1234
 
1223
1235
  ```js
1224
- import { runRawQuery } from 'gtfs';
1225
-
1226
- // Perform a raw query
1227
- const stoptimes = await runRawQuery(
1228
- 'SELECT * FROM stop_times WHERE stop_sequence="1"'
1229
- );
1230
- ```
1231
-
1232
- ### execRawQuery(query)
1233
-
1234
- Executes a statement. Returns a promise containing the result of the execute.
1236
+ import { openDb } from 'gtfs';
1237
+ const db = openDb(config);
1235
1238
 
1236
- ```js
1237
- import { execRawQuery } from 'gtfs';
1239
+ // Get a specific trip
1240
+ const trip = db.prepare('SELECT * FROM trips WHERE trip_id = ?').get('123');
1238
1241
 
1239
- // Purge trips table
1240
- await execRawQuery('DELETE FROM trips');
1242
+ // Get all stops
1243
+ const stops = db.prepare('SELECT * from stops').all();
1244
+
1245
+ // Get all calendar_ids for specific date
1246
+ const calendarIds = db
1247
+ .prepare(
1248
+ 'SELECT service_id from calendar WHERE start_date <= $date AND end_date >= $date'
1249
+ )
1250
+ .all({ date: 20150101 });
1251
+
1252
+ // Find all stops for route_id=18 by joining tables
1253
+ const stopIds = db
1254
+ .prepare(
1255
+ 'SELECT DISTINCT stops.stop_id from stops INNER JOIN stop_times ON stops.stop_id = stop_times.stop_id INNER JOIN trips on trips.trip_id = stop_times.trip_id WHERE trips.route_id = ?'
1256
+ )
1257
+ .all('18');
1258
+
1259
+ // Execute raw SQL
1260
+ const sql = "DELETE FROM trips where trip_id = '329'";
1261
+ db.exec(sql);
1241
1262
  ```
1242
1263
 
1243
1264
  ## Contributing