@@ -44,9 +44,6 @@ const {
44
44
'lower-case-lang-codes' : {
45
45
type : 'boolean' ,
46
46
} ,
47
- 'stops-location-index' : {
48
- type : 'boolean' ,
49
- } ,
50
47
'stats-by-route-date' : {
51
48
type : 'string' ,
52
49
} ,
@@ -59,21 +56,6 @@ const {
59
56
'schema' : {
60
57
type : 'string' ,
61
58
} ,
62
- 'postgraphile' : {
63
- type : 'boolean' ,
64
- } ,
65
- 'postgraphile-password' : {
66
- type : 'string' ,
67
- } ,
68
- 'postgrest' : {
69
- type : 'boolean' ,
70
- } ,
71
- 'postgrest-password' : {
72
- type : 'string' ,
73
- } ,
74
- 'postgrest-query-cost-limit' : {
75
- type : 'string' ,
76
- } ,
77
59
'import-metadata' : {
78
60
type : 'boolean' ,
79
61
}
@@ -84,7 +66,7 @@ const {
84
66
if ( flags . help ) {
85
67
process . stdout . write ( `
86
68
Usage:
87
- gtfs-to-sql [options] [--] <gtfs-file> ...
69
+ import- gtfs-into-duckdb [options] [--] <path-to-duckdb> <gtfs-file> ...
88
70
Options:
89
71
--silent -s Don't show files being converted.
90
72
--require-dependencies -d Require files that the specified GTFS files depend
@@ -101,8 +83,6 @@ Options:
101
83
--routes-without-agency-id Don't require routes.txt items to have an agency_id.
102
84
--stops-without-level-id Don't require stops.txt items to have a level_id.
103
85
Default if levels.txt has not been provided.
104
- --stops-location-index Create a spatial index on stops.stop_loc for efficient
105
- queries by geolocation.
106
86
--lower-case-lang-codes Accept Language Codes (e.g. in feed_info.feed_lang)
107
87
with a different casing than the official BCP-47
108
88
language tags (as specified by the GTFS spec),
@@ -123,34 +103,18 @@ Options:
123
103
currently running trips over time, by hour.
124
104
Like --stats-by-route-date, this flag accepts
125
105
none, view & materialized-view.
126
- --schema The schema to use for the database. Default: public
127
- Even when importing into a schema other than \`public\`,
128
- a function \`public.gtfs_via_postgres_import_version()\`
129
- gets created, to ensure that multiple imports into the
130
- same database are all made using the same version. See
131
- also multiple-datasets.md in the docs.
132
- --postgraphile Tweak generated SQL for PostGraphile usage.
133
- https://www.graphile.org/postgraphile/
134
- --postgraphile-password Password for the PostGraphile PostgreSQL user.
135
- Default: $POSTGRAPHILE_PGPASSWORD, fallback random.
136
- --postgrest Tweak generated SQL for PostgREST usage.
137
- Please combine it with --schema.
138
- https://postgrest.org/
139
- --postgrest-password Password for the PostgREST PostgreSQL user \`web_anon\`.
140
- Default: $POSTGREST_PGPASSWORD, fallback random.
141
- --postgrest-query-cost-limit Define a cost limit [1] for queries executed by PostgREST
142
- on behalf of a user. It is only enforced if
143
- pg_plan_filter [2] is installed in the database!
144
- Must be a positive float. Default: none
145
- [1] https://www.postgresql.org/docs/14/using-explain.html
146
- [2] https://github.com/pgexperts/pg_plan_filter
106
+ --schema The schema to use for the database. Default: main
107
+ May not contain \`.\`.
147
108
--import-metadata Create functions returning import metadata:
148
109
- gtfs_data_imported_at (timestamp with time zone)
149
110
- gtfs_via_postgres_version (text)
150
111
- gtfs_via_postgres_options (jsonb)
112
+ Notes:
113
+ If you just want to check if the GTFS data can be imported but don't care about the
114
+ resulting DuckDB database file, you can import into an in-memory database by specifying
115
+ \`:memory:\` as the <path-to-duckdb>.
151
116
Examples:
152
- gtfs-to-sql some-gtfs/*.txt | sponge | psql -b # import into PostgreSQL
153
- gtfs-to-sql -u -- some-gtfs/*.txt | gzip >gtfs.sql.gz # generate a gzipped SQL dump
117
+ import-gtfs-into-duckdb some-gtfs.duckdb some-gtfs/*.txt
154
118
155
119
[1] https://developers.google.com/transit/gtfs/reference/extended-route-types
156
120
[2] https://groups.google.com/g/gtfs-changes/c/keT5rTPS7Y0/m/71uMz2l6ke0J
@@ -164,11 +128,11 @@ if (flags.version) {
164
128
}
165
129
166
130
const { basename, extname} = require ( 'path' )
167
- const { pipeline} = require ( 'stream' )
168
131
const convertGtfsToSql = require ( './index' )
169
- const DataError = require ( './lib/data-error' )
170
132
171
- const files = args . map ( ( file ) => {
133
+ const [ pathToDb ] = args
134
+
135
+ const files = args . slice ( 1 ) . map ( ( file ) => {
172
136
const name = basename ( file , extname ( file ) )
173
137
return { name, file}
174
138
} )
@@ -184,9 +148,7 @@ const opt = {
184
148
statsByRouteIdAndDate : flags [ 'stats-by-route-date' ] || 'none' ,
185
149
statsByAgencyIdAndRouteIdAndStopAndHour : flags [ 'stats-by-agency-route-stop-hour' ] || 'none' ,
186
150
statsActiveTripsByHour : flags [ 'stats-active-trips-by-hour' ] || 'none' ,
187
- schema : flags [ 'schema' ] || 'public' ,
188
- postgraphile : ! ! flags . postgraphile ,
189
- postgrest : ! ! flags . postgrest ,
151
+ schema : flags [ 'schema' ] || 'main' ,
190
152
importMetadata : ! ! flags [ 'import-metadata' ] ,
191
153
}
192
154
if ( 'stops-without-level-id' in flags ) {
@@ -195,31 +157,11 @@ if ('stops-without-level-id' in flags) {
195
157
if ( 'lower-case-lang-codes' in flags ) {
196
158
opt . lowerCaseLanguageCodes = flags [ 'lower-case-lang-codes' ]
197
159
}
198
- if ( 'postgraphile-password' in flags ) {
199
- opt . postgraphilePassword = flags [ 'postgraphile-password' ]
200
- }
201
- if ( 'postgrest-password' in flags ) {
202
- opt . postgrestPassword = flags [ 'postgrest-password' ]
203
- }
204
- if ( 'postgrest-query-cost-limit' in flags ) {
205
- const limit = parseFloat ( flags [ 'postgrest-query-cost-limit' ] )
206
- if ( ! Number . isFinite ( limit ) || limit < 0 ) {
207
- console . error ( 'Invalid --postgrest-query-cost-limit value.' )
208
- process . exit ( 1 )
209
- }
210
- opt . lowerCaseLanguageCodes = limit
211
- }
212
160
213
- pipeline (
214
- convertGtfsToSql ( files , opt ) ,
215
- process . stdout ,
216
- ( err ) => {
217
- if ( ! err ) return ;
218
- if ( err instanceof DataError ) {
219
- console . error ( String ( err ) )
220
- } else if ( err . code !== 'EPIPE' ) {
221
- console . error ( err )
222
- }
223
- process . exit ( 1 )
161
+ convertGtfsToSql ( pathToDb , files , opt )
162
+ . catch ( ( err ) => {
163
+ if ( err . code !== 'EPIPE' ) { // todo: check still necessary? we don't pipe anymore
164
+ console . error ( err )
224
165
}
225
- )
166
+ process . exit ( 1 )
167
+ } )
0 commit comments