Expand description
Rust utility library for using Gatelogue data in Rust projects. It will load the database for you to access via ORM or raw SQL.
§Installation
Add to your Cargo.toml:
gatelogue-types = { version = "3", features = [...] }
# To import directly from the repository:
gatelogue-types = { git = "https://github.com/mrt-map/gatelogue", package = "gatelogue-types", features = [...] }Add the bundled feature to bundle SQLite.
Also add an HTTP client (e.g. reqwest, ureq) of your choice.
§Usage
To retrieve the data:
use gatelogue_types::{GD, getter};
// with pre-written getter!() functions:
let gd = GD::get_async_no_sources(getter!(reqwest)).await?; // retrieve data (async)
let gd = GD::get_no_sources(getter!(ureq))?; // retrieve data (blocking)
// or with any HTTP client of your choice (with a callable that takes in a &str and returns an AsRef<[u8]>):
let gd = GD::get_async_no_sources(async |url| reqwest::Result::Ok(reqwest::get(url).await?.bytes().await?.to_vec())); // retrieve data (async)
let gd = GD::get_no_sources(|url| ureq::get(url).call()?.into_body().read_to_vec())?; // retrieve data (blocking)
// similar syntax can be used if you want the sources, with `get_async_with_sources` and `get_with_sources`getter!() accepts the following inputs:
reqwest(async) requiringreqwestreqwest_blocking(blocking) requiringreqwestwithblockingfeaturesurf(async) requiringsurfureq(blocking) requiringureqisahc(blocking) requiringisahcisahc_async(async) requiringisahcattohttpc(blocking) requiringattohttpc(untested)minreq(blocking) requiringminreqwreq(async) requiringwreqehttp(blocking) requiringehttpehttp_async(async) requiringehttpwithnative_asyncfeature
Using the ORM does not require SQL and makes for generally clean code. However, doing this is very inefficient as each attribute access is one SQL query.
use gatelogue_types::AirAirport;
for airport in gd.nodes_of_type::<AirAirport>()? {
for gate in airport.gates(&gd)? {
println!("Airport {:?} has gate {:?}", airport.code(&gd)?, gate.code(&gd)?)
}
}Querying the underlying SQLite database directly with rusqlite is generally more efficient and faster.
It is also the only way to access the *Source tables, if you retrieved the database with those.
gd.0.prepare("SELECT A.code, G.code FROM AirGate G INNER JOIN AirAirport A ON G.airport = A.i")?
.query_map((), |row| {
println!("Airport {:?} has gate {:?}", row.get::<_, String>(0)?, row.get::<_, String>(1)?);
Ok(())
})?;Macros§
Structs§
- AirAirline
- AirAirport
- AirFlight
- AirGate
- Aircraft
- BusBerth
- BusCompany
- BusConnection
- BusLine
- BusStop
- GD
- Proximity
- Rail
Company - Rail
Connection - Rail
Line - Rail
Platform - Rail
Station - SeaCompany
- SeaConnection
- SeaDock
- SeaLine
- SeaStop
- Spawn
Warp - Town