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
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,16 @@ import levels from '../../models/gtfs/levels.js';
12
12
  /*
13
13
  * Returns an array of all levels that match the query parameters.
14
14
  */
15
- export async function getLevels(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {}
20
- ) {
21
- const db = options.db ?? (await getDb());
15
+ export function getLevels(query = {}, fields = [], orderBy = [], options = {}) {
16
+ const db = options.db ?? openDb();
22
17
  const tableName = sqlString.escapeId(levels.filenameBase);
23
18
  const selectClause = formatSelectClause(fields);
24
19
  const whereClause = formatWhereClauses(query);
25
20
  const orderByClause = formatOrderByClause(orderBy);
26
21
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
22
+ return db
23
+ .prepare(
24
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
25
+ )
26
+ .all();
30
27
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,21 @@ import pathways from '../../models/gtfs/pathways.js';
12
12
  /*
13
13
  * Returns an array of all pathways that match the query parameters.
14
14
  */
15
- export async function getPathways(
15
+ export function getPathways(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(pathways.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
@@ -1,7 +1,7 @@
1
1
  import { omit, pick } from 'lodash-es';
2
2
  import sqlString from 'sqlstring-sqlite';
3
3
 
4
- import { getDb } from '../db.js';
4
+ import { openDb } from '../db.js';
5
5
 
6
6
  import {
7
7
  formatOrderByClause,
@@ -26,13 +26,8 @@ function buildTripSubquery(query) {
26
26
  * Returns an array of routes that match the query parameters. A `stop_id`
27
27
  * query parameter may be passed to find all routes that contain that stop.
28
28
  */
29
- export async function getRoutes(
30
- query = {},
31
- fields = [],
32
- orderBy = [],
33
- options = {}
34
- ) {
35
- const db = options.db ?? (await getDb());
29
+ export function getRoutes(query = {}, fields = [], orderBy = [], options = {}) {
30
+ const db = options.db ?? openDb();
36
31
  const tableName = sqlString.escapeId(routes.filenameBase);
37
32
  const selectClause = formatSelectClause(fields);
38
33
  let whereClause = '';
@@ -53,7 +48,9 @@ export async function getRoutes(
53
48
  whereClause = `WHERE ${whereClauses.join(' AND ')}`;
54
49
  }
55
50
 
56
- return db.all(
57
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
58
- );
51
+ return db
52
+ .prepare(
53
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
54
+ )
55
+ .all();
59
56
  }
@@ -2,7 +2,7 @@ import { omit, pick } from 'lodash-es';
2
2
  import sqlString from 'sqlstring-sqlite';
3
3
  import { featureCollection } from '@turf/helpers';
4
4
 
5
- import { getDb } from '../db.js';
5
+ import { openDb } from '../db.js';
6
6
 
7
7
  import {
8
8
  formatOrderByClause,
@@ -26,13 +26,8 @@ function buildTripSubquery(query) {
26
26
  * query parameter may be passed to find all shapes for a trip. A
27
27
  * `direction_id` query parameter may be passed to find all shapes for a direction.
28
28
  */
29
- export async function getShapes(
30
- query = {},
31
- fields = [],
32
- orderBy = [],
33
- options = {}
34
- ) {
35
- const db = options.db ?? (await getDb());
29
+ export function getShapes(query = {}, fields = [], orderBy = [], options = {}) {
30
+ const db = options.db ?? openDb();
36
31
  const tableName = sqlString.escapeId(shapes.filenameBase);
37
32
  const selectClause = formatSelectClause(fields);
38
33
  let whereClause = '';
@@ -63,17 +58,19 @@ export async function getShapes(
63
58
  whereClause = `WHERE ${whereClauses.join(' AND ')}`;
64
59
  }
65
60
 
66
- return db.all(
67
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
68
- );
61
+ return db
62
+ .prepare(
63
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
64
+ )
65
+ .all();
69
66
  }
70
67
 
71
68
  /*
72
69
  * Returns geoJSON of the shapes that match the query parameters. A `route_id`
73
70
  * query parameter may be passed to find all shapes for a route.
74
71
  */
75
- export async function getShapesAsGeoJSON(query = {}, options = {}) {
76
- const agencies = await getAgencies({}, [], [], options);
72
+ export function getShapesAsGeoJSON(query = {}, options = {}) {
73
+ const agencies = getAgencies({}, [], [], options);
77
74
 
78
75
  const routeQuery = {};
79
76
 
@@ -81,34 +78,32 @@ export async function getShapesAsGeoJSON(query = {}, options = {}) {
81
78
  routeQuery.route_id = query.route_id;
82
79
  }
83
80
 
84
- const routes = await getRoutes(routeQuery, [], [], options);
81
+ const routes = getRoutes(routeQuery, [], [], options);
85
82
  const features = [];
86
83
 
87
- await Promise.all(
88
- routes.map(async (route) => {
89
- const shapeQuery = {
90
- route_id: route.route_id,
91
- ...omit(query, 'route_id'),
92
- };
93
- const shapes = await getShapes(
94
- shapeQuery,
95
- ['shape_id', 'shape_pt_sequence', 'shape_pt_lon', 'shape_pt_lat'],
96
- [],
97
- options
98
- );
99
-
100
- const agency = agencies.find(
101
- (agency) => agency.agency_id === route.agency_id
102
- );
103
-
104
- const geojsonProperties = {
105
- agency_name: agency ? agency.agency_name : undefined,
106
- shape_id: query.shape_id,
107
- ...route,
108
- };
109
- features.push(...shapesToGeoJSONFeatures(shapes, geojsonProperties));
110
- })
111
- );
84
+ for (const route of routes) {
85
+ const shapeQuery = {
86
+ route_id: route.route_id,
87
+ ...omit(query, 'route_id'),
88
+ };
89
+ const shapes = getShapes(
90
+ shapeQuery,
91
+ ['shape_id', 'shape_pt_sequence', 'shape_pt_lon', 'shape_pt_lat'],
92
+ [],
93
+ options
94
+ );
95
+
96
+ const agency = agencies.find(
97
+ (agency) => agency.agency_id === route.agency_id
98
+ );
99
+
100
+ const geojsonProperties = {
101
+ agency_name: agency ? agency.agency_name : undefined,
102
+ shape_id: query.shape_id,
103
+ ...route,
104
+ };
105
+ features.push(...shapesToGeoJSONFeatures(shapes, geojsonProperties));
106
+ }
112
107
 
113
108
  return featureCollection(features);
114
109
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,21 @@ import stopAreas from '../../models/gtfs/stop-areas.js';
12
12
  /*
13
13
  * Returns an array of all stop areas that match the query parameters.
14
14
  */
15
- export async function getStopAreas(
15
+ export function getStopAreas(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(stopAreas.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,21 @@ import stopTimes from '../../models/gtfs/stop-times.js';
12
12
  /*
13
13
  * Returns an array of stoptimes that match the query parameters.
14
14
  */
15
- export async function getStoptimes(
15
+ export function getStoptimes(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(stopTimes.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
package/lib/gtfs/stops.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { omit, orderBy, pick } from 'lodash-es';
2
2
  import sqlString from 'sqlstring-sqlite';
3
3
 
4
- import { getDb } from '../db.js';
4
+ import { openDb } from '../db.js';
5
5
 
6
6
  import {
7
7
  formatOrderByClause,
@@ -30,13 +30,8 @@ function buildStoptimeSubquery(query) {
30
30
  * query parameter may be passed to find all shapes for a trip. A
31
31
  * `direction_id` query parameter may be passed to find all shapes for a direction.
32
32
  */
33
- export async function getStops(
34
- query = {},
35
- fields = [],
36
- orderBy = [],
37
- options = {}
38
- ) {
39
- const db = options.db ?? (await getDb());
33
+ export function getStops(query = {}, fields = [], orderBy = [], options = {}) {
34
+ const db = options.db ?? openDb();
40
35
  const tableName = sqlString.escapeId(stops.filenameBase);
41
36
  const selectClause = formatSelectClause(fields);
42
37
  let whereClause = '';
@@ -69,39 +64,38 @@ export async function getStops(
69
64
  whereClause = `WHERE ${whereClauses.join(' AND ')}`;
70
65
  }
71
66
 
72
- return db.all(
73
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
74
- );
67
+ return db
68
+ .prepare(
69
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
70
+ )
71
+ .all();
75
72
  }
76
73
 
77
74
  /*
78
75
  * Returns geoJSON with stops for the `agencyKey` specified, optionally limited
79
76
  * to the `stopIds` specified
80
77
  */
81
- export async function getStopsAsGeoJSON(query = {}, options = {}) {
82
- const db = options.db ?? (await getDb());
83
- const stops = await getStops(query, [], [], options);
78
+ export function getStopsAsGeoJSON(query = {}, options = {}) {
79
+ const db = options.db ?? openDb();
80
+ const stops = getStops(query, [], [], options);
84
81
 
85
82
  // Get all agencies for reference
86
- const agencies = await getAgencies({}, [], [], options);
87
-
88
- const preparedStops = await Promise.all(
89
- stops.map(async (stop) => {
90
- const routeSubquery =
91
- 'SELECT DISTINCT route_id FROM trips WHERE trip_id IN (SELECT DISTINCT trip_id FROM stop_times WHERE stop_id = ?)';
92
- const routes = await db.all(
93
- `SELECT * FROM routes WHERE route_id IN (${routeSubquery})`,
94
- [stop.stop_id]
95
- );
96
-
97
- stop.routes = orderBy(routes, (route) =>
98
- Number.parseInt(route.route_short_name, 10)
99
- );
100
- stop.agency_name = agencies[0].agency_name;
101
-
102
- return stop;
103
- })
104
- );
83
+ const agencies = getAgencies({}, [], [], options);
84
+
85
+ const preparedStops = stops.map((stop) => {
86
+ const routeSubquery =
87
+ 'SELECT DISTINCT route_id FROM trips WHERE trip_id IN (SELECT DISTINCT trip_id FROM stop_times WHERE stop_id = ?)';
88
+ const routes = db
89
+ .prepare(`SELECT * FROM routes WHERE route_id IN (${routeSubquery})`)
90
+ .all(stop.stop_id);
91
+
92
+ stop.routes = orderBy(routes, (route) =>
93
+ Number.parseInt(route.route_short_name, 10)
94
+ );
95
+ stop.agency_name = agencies[0].agency_name;
96
+
97
+ return stop;
98
+ });
105
99
 
106
100
  return stopsToGeoJSON(preparedStops);
107
101
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,21 @@ import transfers from '../../models/gtfs/transfers.js';
12
12
  /*
13
13
  * Returns an array of all transfers that match the query parameters.
14
14
  */
15
- export async function getTransfers(
15
+ export function getTransfers(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(transfers.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,21 @@ import translations from '../../models/gtfs/translations.js';
12
12
  /*
13
13
  * Returns an array of all translations that match the query parameters.
14
14
  */
15
- export async function getTranslations(
15
+ export function getTranslations(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(translations.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
package/lib/gtfs/trips.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,16 @@ import trips from '../../models/gtfs/trips.js';
12
12
  /*
13
13
  * Returns an array of all trips that match the query parameters.
14
14
  */
15
- export async function getTrips(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {}
20
- ) {
21
- const db = options.db ?? (await getDb());
15
+ export function getTrips(query = {}, fields = [], orderBy = [], options = {}) {
16
+ const db = options.db ?? openDb();
22
17
  const tableName = sqlString.escapeId(trips.filenameBase);
23
18
  const selectClause = formatSelectClause(fields);
24
19
  const whereClause = formatWhereClauses(query);
25
20
  const orderByClause = formatOrderByClause(orderBy);
26
21
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
22
+ return db
23
+ .prepare(
24
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
25
+ )
26
+ .all();
30
27
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -11,22 +11,24 @@ import serviceAlerts from '../../models/gtfs-realtime/service-alerts.js';
11
11
  import serviceAlertTargets from '../../models/gtfs-realtime/service-alert-targets.js';
12
12
 
13
13
  /*
14
- * Returns an array of all agencies that match the query parameters.
14
+ * Returns an array of all serivce alerts that match the query parameters.
15
15
  */
16
- export async function getServiceAlerts(
16
+ export function getServiceAlerts(
17
17
  query = {},
18
18
  fields = [],
19
19
  orderBy = [],
20
20
  options = {}
21
21
  ) {
22
- const db = options.db ?? (await getDb());
22
+ const db = options.db ?? openDb();
23
23
  const tableName = sqlString.escapeId(serviceAlerts.filenameBase);
24
24
  const joinTable = sqlString.escapeId(serviceAlertTargets.filenameBase);
25
25
  const selectClause = formatSelectClause(fields);
26
26
  const whereClause = formatWhereClauses(query);
27
27
  const orderByClause = formatOrderByClause(orderBy);
28
28
 
29
- return db.all(
30
- `${selectClause} FROM ${tableName} INNER JOIN ${joinTable} ON ${tableName}.id=${joinTable}.alert_id ${whereClause} ${orderByClause};`
31
- );
29
+ return db
30
+ .prepare(
31
+ `${selectClause} FROM ${tableName} INNER JOIN ${joinTable} ON ${tableName}.id=${joinTable}.alert_id ${whereClause} ${orderByClause};`
32
+ )
33
+ .all();
32
34
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -10,21 +10,23 @@ import {
10
10
  import stopTimeUpdates from '../../models/gtfs-realtime/stop-times-updates.js';
11
11
 
12
12
  /*
13
- * Returns an array of all agencies that match the query parameters.
13
+ * Returns an array of all stop times updates that match the query parameters.
14
14
  */
15
- export async function getStopTimesUpdates(
15
+ export function getStopTimesUpdates(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(stopTimeUpdates.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -10,21 +10,23 @@ import {
10
10
  import tripUpdates from '../../models/gtfs-realtime/trip-updates.js';
11
11
 
12
12
  /*
13
- * Returns an array of all agencies that match the query parameters.
13
+ * Returns an array of all trip updates that match the query parameters.
14
14
  */
15
- export async function getTripUpdates(
15
+ export function getTripUpdates(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(tripUpdates.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -10,21 +10,23 @@ import {
10
10
  import vehiclePositions from '../../models/gtfs-realtime/vehicle-positions.js';
11
11
 
12
12
  /*
13
- * Returns an array of all agencies that match the query parameters.
13
+ * Returns an array of all vehicle positions that match the query parameters.
14
14
  */
15
- export async function getVehiclePositions(
15
+ export function getVehiclePositions(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(vehiclePositions.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }
@@ -1,6 +1,6 @@
1
1
  import sqlString from 'sqlstring-sqlite';
2
2
 
3
- import { getDb } from '../db.js';
3
+ import { openDb } from '../db.js';
4
4
 
5
5
  import {
6
6
  formatOrderByClause,
@@ -12,19 +12,21 @@ import boardAlights from '../../models/gtfs-ride/board-alight.js';
12
12
  /*
13
13
  * Returns an array of all board-alights that match the query parameters.
14
14
  */
15
- export async function getBoardAlights(
15
+ export function getBoardAlights(
16
16
  query = {},
17
17
  fields = [],
18
18
  orderBy = [],
19
19
  options = {}
20
20
  ) {
21
- const db = options.db ?? (await getDb());
21
+ const db = options.db ?? openDb();
22
22
  const tableName = sqlString.escapeId(boardAlights.filenameBase);
23
23
  const selectClause = formatSelectClause(fields);
24
24
  const whereClause = formatWhereClauses(query);
25
25
  const orderByClause = formatOrderByClause(orderBy);
26
26
 
27
- return db.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }