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.
- package/@types/index.d.ts +130 -137
- package/@types/tests.ts +18 -13
- package/CHANGELOG.md +18 -0
- package/README.md +233 -212
- package/config-sample-rtupdates.json +6 -18
- package/lib/advancedQuery.js +8 -17
- package/lib/db.js +35 -59
- package/lib/export.js +16 -10
- package/lib/gtfs/agencies.js +8 -6
- package/lib/gtfs/areas.js +8 -11
- package/lib/gtfs/attributions.js +8 -6
- package/lib/gtfs/calendar-dates.js +8 -6
- package/lib/gtfs/calendars.js +8 -6
- package/lib/gtfs/fare-attributes.js +8 -6
- package/lib/gtfs/fare-leg-rules.js +8 -6
- package/lib/gtfs/fare-products.js +8 -6
- package/lib/gtfs/fare-rules.js +8 -6
- package/lib/gtfs/fare-transfer-rules.js +8 -6
- package/lib/gtfs/feed-info.js +8 -6
- package/lib/gtfs/frequencies.js +8 -6
- package/lib/gtfs/levels.js +8 -11
- package/lib/gtfs/pathways.js +8 -6
- package/lib/gtfs/routes.js +8 -11
- package/lib/gtfs/shapes.js +34 -39
- package/lib/gtfs/stop-areas.js +8 -6
- package/lib/gtfs/stop-times.js +8 -6
- package/lib/gtfs/stops.js +27 -33
- package/lib/gtfs/transfers.js +8 -6
- package/lib/gtfs/translations.js +8 -6
- package/lib/gtfs/trips.js +8 -11
- package/lib/gtfs-realtime/service-alerts.js +9 -7
- package/lib/gtfs-realtime/stop-times-updates.js +9 -7
- package/lib/gtfs-realtime/trip-updates.js +9 -7
- package/lib/gtfs-realtime/vehicle-positions.js +9 -7
- package/lib/gtfs-ride/board-alights.js +8 -6
- package/lib/gtfs-ride/ride-feed-infos.js +8 -6
- package/lib/gtfs-ride/rider-trips.js +8 -6
- package/lib/gtfs-ride/riderships.js +8 -6
- package/lib/gtfs-ride/trip-capacities.js +8 -6
- package/lib/gtfs.js +3 -9
- package/lib/import.js +213 -273
- package/lib/non-standard/directions.js +8 -6
- package/lib/non-standard/stop-attributes.js +8 -6
- package/lib/non-standard/timetable-notes-references.js +8 -6
- package/lib/non-standard/timetable-notes.js +8 -6
- package/lib/non-standard/timetable-pages.js +8 -6
- package/lib/non-standard/timetable-stop-order.js +8 -6
- package/lib/non-standard/timetables.js +8 -6
- package/lib/non-standard/trips-dated-vehicle-journey.js +9 -7
- package/package.json +4 -4
- package/test/mocha/advanced-query.js +9 -15
- package/test/mocha/export-gtfs.js +5 -6
- package/test/mocha/fare-transfer-rules.js +32 -0
- package/test/mocha/get-agencies.js +13 -19
- package/test/mocha/get-areas.js +27 -0
- package/test/mocha/get-attributions.js +7 -13
- package/test/mocha/get-board-alights.js +7 -13
- package/test/mocha/get-calendar-dates.js +11 -17
- package/test/mocha/get-calendars.js +11 -17
- package/test/mocha/get-directions.js +7 -13
- package/test/mocha/get-fare-attributes.js +9 -15
- package/test/mocha/get-fare-leg-rules.js +27 -0
- package/test/mocha/get-fare-products.js +27 -0
- package/test/mocha/get-fare-rules.js +9 -15
- package/test/mocha/get-feed-info.js +7 -13
- package/test/mocha/get-frequencies.js +7 -13
- package/test/mocha/get-levels.js +7 -7
- package/test/mocha/get-pathways.js +7 -13
- package/test/mocha/get-ride-feed-infos.js +7 -13
- package/test/mocha/get-rider-trips.js +7 -13
- package/test/mocha/get-riderships.js +7 -13
- package/test/mocha/get-routes.js +13 -13
- package/test/mocha/get-shapes-as-geojson.js +14 -15
- package/test/mocha/get-shapes.js +25 -25
- package/test/mocha/get-stop-attributes.js +7 -13
- package/test/mocha/get-stops-as-geojson.js +13 -19
- package/test/mocha/get-stops.js +19 -19
- package/test/mocha/get-stoptimes.js +11 -17
- package/test/mocha/get-timetable-pages.js +7 -13
- package/test/mocha/get-timetable-stop-orders.js +6 -7
- package/test/mocha/get-timetables.js +7 -13
- package/test/mocha/get-transfers.js +7 -13
- package/test/mocha/get-translations.js +7 -13
- package/test/mocha/get-trip-capacities.js +7 -13
- package/test/mocha/get-trips.js +9 -9
- package/test/mocha/import-gtfs.js +11 -11
- package/test/mocha/{get-db.js → open-db.js} +37 -29
- package/test/mocha/raw-query.js +34 -0
- package/test/mocha/exec-raw-query.js +0 -39
- package/test/mocha/run-raw-query.js +0 -54
package/lib/gtfs/levels.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlString from 'sqlstring-sqlite';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
16
|
-
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
return db
|
|
23
|
+
.prepare(
|
|
24
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
25
|
+
)
|
|
26
|
+
.all();
|
|
30
27
|
}
|
package/lib/gtfs/pathways.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlString from 'sqlstring-sqlite';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
15
|
+
export function getPathways(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
30
32
|
}
|
package/lib/gtfs/routes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { omit, pick } from 'lodash-es';
|
|
2
2
|
import sqlString from 'sqlstring-sqlite';
|
|
3
3
|
|
|
4
|
-
import {
|
|
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
|
|
30
|
-
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
return db
|
|
52
|
+
.prepare(
|
|
53
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
54
|
+
)
|
|
55
|
+
.all();
|
|
59
56
|
}
|
package/lib/gtfs/shapes.js
CHANGED
|
@@ -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 {
|
|
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
|
|
30
|
-
|
|
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
|
|
67
|
-
|
|
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
|
|
76
|
-
const agencies =
|
|
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 =
|
|
81
|
+
const routes = getRoutes(routeQuery, [], [], options);
|
|
85
82
|
const features = [];
|
|
86
83
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
}
|
package/lib/gtfs/stop-areas.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlString from 'sqlstring-sqlite';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
15
|
+
export function getStopAreas(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
30
32
|
}
|
package/lib/gtfs/stop-times.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlString from 'sqlstring-sqlite';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
15
|
+
export function getStoptimes(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
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 {
|
|
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
|
|
34
|
-
|
|
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
|
|
73
|
-
|
|
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
|
|
82
|
-
const db = options.db ?? (
|
|
83
|
-
const stops =
|
|
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 =
|
|
87
|
-
|
|
88
|
-
const preparedStops =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
}
|
package/lib/gtfs/transfers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlString from 'sqlstring-sqlite';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
15
|
+
export function getTransfers(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
30
32
|
}
|
package/lib/gtfs/translations.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlString from 'sqlstring-sqlite';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
15
|
+
export function getTranslations(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
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 {
|
|
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
|
|
16
|
-
|
|
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
|
|
28
|
-
|
|
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 {
|
|
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
|
|
14
|
+
* Returns an array of all serivce alerts that match the query parameters.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export function getServiceAlerts(
|
|
17
17
|
query = {},
|
|
18
18
|
fields = [],
|
|
19
19
|
orderBy = [],
|
|
20
20
|
options = {}
|
|
21
21
|
) {
|
|
22
|
-
const db = options.db ?? (
|
|
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
|
|
30
|
-
|
|
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 {
|
|
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
|
|
13
|
+
* Returns an array of all stop times updates that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getStopTimesUpdates(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
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 {
|
|
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
|
|
13
|
+
* Returns an array of all trip updates that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getTripUpdates(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
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 {
|
|
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
|
|
13
|
+
* Returns an array of all vehicle positions that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getVehiclePositions(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
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 {
|
|
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
|
|
15
|
+
export function getBoardAlights(
|
|
16
16
|
query = {},
|
|
17
17
|
fields = [],
|
|
18
18
|
orderBy = [],
|
|
19
19
|
options = {}
|
|
20
20
|
) {
|
|
21
|
-
const db = options.db ?? (
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
30
32
|
}
|