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,28 +1,16 @@
1
1
  {
2
2
  "agencies": [
3
3
  {
4
- "url": "http://www.bart.gov/dev/schedules/google_transit.zip",
5
- "exclude": ["shapes"],
4
+ "url": "https://marintransit.org/data/google_transit.zip",
6
5
  "realtimeUrls": [
7
- "https://opendata.samtrafiken.se/gtfs-rt/sl/TripUpdates.pb?key=yourkey",
8
- "https://opendata.samtrafiken.se/gtfs-rt/sl/VehiclePositions.pb?key=yourkey",
9
- "https://opendata.samtrafiken.se/gtfs-rt/sl/ServiceAlerts.pb?key=yourkey"
10
- ],
11
- "realtimeHeaders": {
12
- "X-CustomHeader": "MyCustomHeader"
13
- },
14
- "headers": {
15
- "X-CustomHeader": "MyCustomHeader"
16
- }
17
- },
18
- {
19
- "path": "/path/to/gtfs.zip",
20
- "exclude": ["stop_times", "shapes"]
6
+ "https://marintransit.net/gtfs-rt/alerts",
7
+ "https://marintransit.net/gtfs-rt/tripupdates",
8
+ "https://marintransit.net/gtfs-rt/vehiclepositions"
9
+ ]
21
10
  }
22
11
  ],
23
12
  "csvOptions": {
24
13
  "skip_lines_with_error": true
25
14
  },
26
- "sqlitePath": "/tmp/gtfs",
27
- "exportPath": "~/path/to/export/gtfs"
15
+ "sqlitePath": "/tmp/gtfs"
28
16
  }
@@ -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,7 +12,7 @@ import {
12
12
  /*
13
13
  * Returns an array of all agencies that match the query parameters.
14
14
  */
15
- export async function advancedQuery(table, advancedQueryOptions) {
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 ?? (await getDb());
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
- const sqlStatement = `${selectClause} FROM ${tableName} ${joinClause} ${whereClause} ${orderByClause};`;
32
- return db.all(sqlStatement).catch((error) => {
33
- console.log(error);
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,49 @@
1
- import sqlite3 from 'sqlite3';
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
- export async function openDb(initialConfig) {
8
- const config = setDefaultConfig(initialConfig);
9
- if (!dbs[config.sqlitePath]) {
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
- return dbs[config.sqlitePath];
17
- }
12
+ const db = new Database(untildify(sqlitePath));
13
+ setupDb(db);
18
14
 
19
- export async function setupDb(db) {
20
- if (Object.keys(dbs).length === 0) {
21
- throw new Error(
22
- 'No database connection. Call `openDb(config)` before using any methods.'
23
- );
24
- }
15
+ dbs[sqlitePath] = db;
16
+ return db;
17
+ };
25
18
 
26
- if (!db) {
27
- if (Object.keys(dbs).length > 1) {
28
- throw new Error(
29
- 'Multiple database connections. Pass the db you want to setup as a parameter to `setupDb`.'
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
- db = dbs[filename];
27
+ return dbs[filename];
28
+ }
29
+
30
+ if (Object.keys(dbs).length > 1) {
31
+ throw new Error(
32
+ 'Multiple databases open, please specify which one to use.'
33
+ );
35
34
  }
36
35
 
37
- await db.run('PRAGMA journal_mode = OFF;');
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;');
36
+ throw new Error('Unable to find database connection.');
37
+ }
38
+
39
+ export function setupDb(db) {
40
+ db.pragma('journal_mode = WAL');
41
+ db.pragma('synchronous = OFF');
42
+ db.pragma('locking_mode = EXCLUSIVE');
43
+ db.pragma('temp_store = MEMORY');
42
44
  }
43
45
 
44
- export async function closeDb(db) {
46
+ export function closeDb(db) {
45
47
  if (Object.keys(dbs).length === 0) {
46
48
  throw new Error(
47
49
  'No database connection. Call `openDb(config)` before using any methods.'
@@ -58,32 +60,6 @@ export async function closeDb(db) {
58
60
  db = dbs[Object.keys(dbs)[0]];
59
61
  }
60
62
 
61
- const { filename } = db.config;
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.');
63
+ db.close();
64
+ delete dbs[db.name];
89
65
  }
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 exportGtfs = async (initialConfig) => {
18
- const config = setDefaultConfig(initialConfig);
19
- const log = _log(config);
20
- const logWarning = _logWarning(config);
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 = await db.all(`SELECT * FROM ${tableName};`);
71
+ const lines = db.prepare(`SELECT * FROM ${tableName};`).all();
66
72
 
67
73
  if (!lines || lines.length === 0) {
68
74
  if (!model.nonstandard) {
@@ -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 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 async function getAgencies(
15
+ export function getAgencies(
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(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.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/areas.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 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 async function getAreas(
16
- query = {},
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.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 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 async function getAttributions(
15
+ export function getAttributions(
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(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.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 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 async function getCalendarDates(
15
+ export function getCalendarDates(
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(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.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 calendars from '../../models/gtfs/calendar.js';
12
12
  /*
13
13
  * Returns an array of calendars that match the query parameters.
14
14
  */
15
- export async function getCalendars(
15
+ export function getCalendars(
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(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.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 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 async function getFareAttributes(
15
+ export function getFareAttributes(
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(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.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 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 async function getFareLegRules(
15
+ export function getFareLegRules(
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(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.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 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 async function getFareProducts(
15
+ export function getFareProducts(
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(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.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 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 async function getFareRules(
15
+ export function getFareRules(
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(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.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 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 async function getFareTransferRules(
15
+ export function getFareTransferRules(
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(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.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 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 async function getFeedInfo(
15
+ export function getFeedInfo(
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(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.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 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 async function getFrequencies(
15
+ export function getFrequencies(
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(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.all(
28
- `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
- );
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
30
32
  }