gtfs 3.8.0 → 4.0.0
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 +35 -60
- package/@types/tests.ts +18 -13
- package/CHANGELOG.md +10 -0
- package/README.md +227 -207
- package/lib/advancedQuery.js +8 -17
- package/lib/db.js +29 -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 +195 -202
- 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 +2 -3
- 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/advancedQuery.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,7 +12,7 @@ import {
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all agencies that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function advancedQuery(table, advancedQueryOptions) {
|
|
16
16
|
const defaultOptions = {
|
|
17
17
|
query: {},
|
|
18
18
|
fields: [],
|
|
@@ -22,24 +22,15 @@ export async function advancedQuery(table, advancedQueryOptions) {
|
|
|
22
22
|
};
|
|
23
23
|
const queryOptions = { ...defaultOptions, ...advancedQueryOptions };
|
|
24
24
|
|
|
25
|
-
const db = queryOptions.options.db ?? (
|
|
25
|
+
const db = queryOptions.options.db ?? openDb();
|
|
26
26
|
const tableName = sqlString.escapeId(table);
|
|
27
27
|
const selectClause = formatSelectClause(queryOptions.fields);
|
|
28
28
|
const whereClause = formatWhereClauses(queryOptions.query);
|
|
29
29
|
const joinClause = formatJoinClause(queryOptions.join);
|
|
30
30
|
const orderByClause = formatOrderByClause(queryOptions.orderBy);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export async function runRawQuery(sql, options = {}) {
|
|
38
|
-
const db = options.db ?? (await getDb());
|
|
39
|
-
return db.all(sql);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function execRawQuery(sql, options = {}) {
|
|
43
|
-
const db = options.db ?? (await getDb());
|
|
44
|
-
return db.exec(sql);
|
|
31
|
+
return db
|
|
32
|
+
.prepare(
|
|
33
|
+
`${selectClause} FROM ${tableName} ${joinClause} ${whereClause} ${orderByClause};`
|
|
34
|
+
)
|
|
35
|
+
.all();
|
|
45
36
|
}
|
package/lib/db.js
CHANGED
|
@@ -1,47 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { open } from 'sqlite';
|
|
3
|
-
import { setDefaultConfig } from './utils.js';
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
4
2
|
import untildify from 'untildify';
|
|
3
|
+
|
|
4
|
+
import { setDefaultConfig } from './utils.js';
|
|
5
5
|
const dbs = {};
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
dbs[config.sqlitePath] = await open({
|
|
11
|
-
filename: untildify(config.sqlitePath),
|
|
12
|
-
driver: sqlite3.Database,
|
|
13
|
-
});
|
|
7
|
+
const getOrCreateDbConnection = (sqlitePath) => {
|
|
8
|
+
if (dbs[sqlitePath]) {
|
|
9
|
+
return dbs[sqlitePath];
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const db = new Database(untildify(sqlitePath));
|
|
13
|
+
setupDb(db);
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'No database connection. Call `openDb(config)` before using any methods.'
|
|
23
|
-
);
|
|
24
|
-
}
|
|
15
|
+
dbs[sqlitePath] = db;
|
|
16
|
+
return db;
|
|
17
|
+
};
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
}
|
|
19
|
+
export function openDb(config) {
|
|
20
|
+
if (config) {
|
|
21
|
+
return getOrCreateDbConnection(setDefaultConfig(config).sqlitePath);
|
|
22
|
+
}
|
|
32
23
|
|
|
24
|
+
// If only one db connection already exists, use it
|
|
25
|
+
if (Object.keys(dbs).length === 1) {
|
|
33
26
|
const filename = Object.keys(dbs)[0];
|
|
34
|
-
|
|
27
|
+
return dbs[filename];
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
await db.run('PRAGMA synchronous = 0;');
|
|
39
|
-
await db.run('PRAGMA locking_mode = EXCLUSIVE;');
|
|
40
|
-
await db.run('PRAGMA temp_store = MEMORY;');
|
|
41
|
-
await db.run('VACUUM;');
|
|
30
|
+
throw new Error('Unable to find database connection.');
|
|
42
31
|
}
|
|
43
32
|
|
|
44
|
-
export
|
|
33
|
+
export function setupDb(db) {
|
|
34
|
+
db.pragma('journal_mode = WAL');
|
|
35
|
+
db.pragma('synchronous = OFF');
|
|
36
|
+
db.pragma('locking_mode = EXCLUSIVE');
|
|
37
|
+
db.pragma('temp_store = MEMORY');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function closeDb(db) {
|
|
45
41
|
if (Object.keys(dbs).length === 0) {
|
|
46
42
|
throw new Error(
|
|
47
43
|
'No database connection. Call `openDb(config)` before using any methods.'
|
|
@@ -58,32 +54,6 @@ export async function closeDb(db) {
|
|
|
58
54
|
db = dbs[Object.keys(dbs)[0]];
|
|
59
55
|
}
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await db.close();
|
|
64
|
-
delete dbs[filename];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function getDb(initialConfig) {
|
|
68
|
-
if (Object.keys(dbs).length === 0) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
'No database connection. Call `openDb(config)` before using any methods.'
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const config = setDefaultConfig(initialConfig);
|
|
75
|
-
if (dbs[config.sqlitePath]) {
|
|
76
|
-
return dbs[config.sqlitePath];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/*
|
|
80
|
-
* Fall back to using the only open database connection if only
|
|
81
|
-
* one exists for backwards compatibility
|
|
82
|
-
*/
|
|
83
|
-
if (Object.keys(dbs).length === 1) {
|
|
84
|
-
const filename = Object.keys(dbs)[0];
|
|
85
|
-
return dbs[filename];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
throw new Error('Unable to find database connection.');
|
|
57
|
+
db.close();
|
|
58
|
+
delete dbs[db.name];
|
|
89
59
|
}
|
package/lib/export.js
CHANGED
|
@@ -14,14 +14,10 @@ import { prepDirectory, generateFolderName } from './file-utils.js';
|
|
|
14
14
|
import { log as _log, logWarning as _logWarning } from './log-utils.js';
|
|
15
15
|
import { setDefaultConfig } from './utils.js';
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const db = await openDb(config);
|
|
22
|
-
|
|
23
|
-
// Get agency name for export folder from first line of agency.txt
|
|
24
|
-
const agencies = await db.all('SELECT agency_name FROM agency;').catch(() => {
|
|
17
|
+
const getAgencies = (db, config) => {
|
|
18
|
+
try {
|
|
19
|
+
return db.prepare('SELECT agency_name FROM agency;').all();
|
|
20
|
+
} catch (error) {
|
|
25
21
|
if (config.sqlitePath === ':memory:') {
|
|
26
22
|
throw new Error(
|
|
27
23
|
'No agencies found in SQLite. You are using an in-memory database - if running this from command line be sure to specify a value for `sqlitePath` in config.json other than ":memory:".'
|
|
@@ -31,8 +27,18 @@ const exportGtfs = async (initialConfig) => {
|
|
|
31
27
|
throw new Error(
|
|
32
28
|
'No agencies found in SQLite. Be sure to first import data into SQLite using `gtfs-import` or `importGtfs(config);`'
|
|
33
29
|
);
|
|
34
|
-
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const exportGtfs = async (initialConfig) => {
|
|
34
|
+
const config = setDefaultConfig(initialConfig);
|
|
35
|
+
const log = _log(config);
|
|
36
|
+
const logWarning = _logWarning(config);
|
|
37
|
+
const db = openDb(config);
|
|
38
|
+
|
|
39
|
+
// Get agency name for export folder from first line of agency.txt
|
|
35
40
|
|
|
41
|
+
const agencies = getAgencies(db, config);
|
|
36
42
|
const agencyCount = agencies.length;
|
|
37
43
|
if (agencyCount === 0) {
|
|
38
44
|
throw new Error(
|
|
@@ -62,7 +68,7 @@ const exportGtfs = async (initialConfig) => {
|
|
|
62
68
|
const exportedFiles = await mapSeries(models, async (model) => {
|
|
63
69
|
const filepath = path.join(exportPath, `${model.filenameBase}.txt`);
|
|
64
70
|
const tableName = sqlString.escapeId(model.filenameBase);
|
|
65
|
-
const lines =
|
|
71
|
+
const lines = db.prepare(`SELECT * FROM ${tableName};`).all();
|
|
66
72
|
|
|
67
73
|
if (!lines || lines.length === 0) {
|
|
68
74
|
if (!model.nonstandard) {
|
package/lib/gtfs/agencies.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 agency from '../../models/gtfs/agency.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all agencies that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getAgencies(
|
|
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(agency.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/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,16 @@ import areas from '../../models/gtfs/areas.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all areas 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 getAreas(query = {}, fields = [], orderBy = [], options = {}) {
|
|
16
|
+
const db = options.db ?? openDb();
|
|
22
17
|
const tableName = sqlString.escapeId(areas.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/attributions.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 attributions from '../../models/gtfs/attributions.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all attributions that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getAttributions(
|
|
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(attributions.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 calendarDates from '../../models/gtfs/calendar-dates.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of calendarDates that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getCalendarDates(
|
|
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(calendarDates.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/calendars.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 calendars from '../../models/gtfs/calendar.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of calendars that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getCalendars(
|
|
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(calendars.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 fareAttributes from '../../models/gtfs/fare-attributes.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all fare attributes that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getFareAttributes(
|
|
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(fareAttributes.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 fareLegRules from '../../models/gtfs/fare-leg-rules.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all fare leg rules that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getFareLegRules(
|
|
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(fareLegRules.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 fareProducts from '../../models/gtfs/fare-products.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all fare products that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getFareProducts(
|
|
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(fareProducts.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/fare-rules.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 fareRules from '../../models/gtfs/fare-rules.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all fare rules that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getFareRules(
|
|
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(fareRules.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 fareTransferRules from '../../models/gtfs/fare-transfer-rules.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all fare transfer rules that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getFareTransferRules(
|
|
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(fareTransferRules.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/feed-info.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 feedInfo from '../../models/gtfs/feed-info.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all feed info that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getFeedInfo(
|
|
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(feedInfo.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/frequencies.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 frequencies from '../../models/gtfs/frequencies.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all frequencies that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function getFrequencies(
|
|
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(frequencies.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/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
|
}
|