Module: NJTransit::GTFS::Database
- Defined in:
- lib/njtransit/gtfs/database.rb
Overview
Database module for managing GTFS SQLite storage
Class Method Summary collapse
- .clear! ⇒ Object
- .connection(path = nil) ⇒ Object
- .disconnect ⇒ Object
- .exists?(path) ⇒ Boolean
- .setup_schema! ⇒ Object
Class Method Details
.clear! ⇒ Object
46 47 48 49 50 51 |
# File 'lib/njtransit/gtfs/database.rb', line 46 def clear! db = connection %i[agencies routes stops trips stop_times calendar_dates shapes import_metadata].each do |table| db.drop_table?(table) end end |
.connection(path = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/njtransit/gtfs/database.rb', line 11 def connection(path = nil) @path = path if path @connection ||= begin FileUtils.mkdir_p(File.dirname(@path)) Sequel.sqlite(@path) end end |
.disconnect ⇒ Object
19 20 21 22 |
# File 'lib/njtransit/gtfs/database.rb', line 19 def disconnect @connection&.disconnect @connection = nil end |
.exists?(path) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/njtransit/gtfs/database.rb', line 24 def exists?(path) return false unless File.exist?(path) db = Sequel.sqlite(path) db.table_exists?(:agencies) && db.table_exists?(:stops) rescue StandardError false ensure db&.disconnect end |
.setup_schema! ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/njtransit/gtfs/database.rb', line 35 def setup_schema! create_agencies_table create_routes_table create_stops_table create_trips_table create_stop_times_table create_calendar_dates_table create_shapes_table end |