Skip to content

phisakel/gtfs-db-swift

Repository files navigation

gtfs-db-swift

This library will allow you to query and update GTFS data from an SQLite database in Swift.

Swift Build

Installation

Swift Package Manager

Add the following dependency to your Package.swift file:

dependencies: [.package(url: "https://github.com/phisakel/gtfs-db-swift.git", from: "0.1.0")]

and to the target:

dependencies: [.product(name: "GtfsDb", package: "gtfs-db-swift")]

Create the sqlite database

You can create the sqlite database using the gtfs-import command line tool. You can install it from the node-GTFS library. First, download the GTFS zip and then run the import command, for example:

gtfs-import --gtfsPath ./9_google_transit.zip --sqlitePath ./9_google_transit.sqlite

Usage

Read the GTFS data from the sqlite database, using the excellent GRDB library, which is included as a dependency to this library. The following code will read the stops from the database:

    import GtfsDb
    import GRDB

    func fetchStops() async throws -> [Stop] {
        let dbPath = "path/to/your/database.sqlite"
        var config = Configuration()
        config.readonly = true
        dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
        let stops = try await dbQueue.read { db in try Stop.fetchAll(db) }
        return stops
    }

About

GTFS sqlite database swift package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages