Skip to content

Commit

Permalink
Merge pull request #1 from stadiamaps/upgrade-sqlx
Browse files Browse the repository at this point in the history
Upgrade SQLx
  • Loading branch information
Ian Wagner authored Apr 2, 2020
2 parents 72474bc + 92f857a commit 1eb723b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tile_sorcerer"
version = "0.1.0"
version = "0.2.0"
authors = ["Ian Wagner <ian@stadiamaps.com>", "Luke Seelenbinder <luke@stadiamaps.com>"]
license = "BSD-3-Clause"
repository = "https://github.com/stadiamaps/tile_sorcerer"
Expand All @@ -22,7 +22,7 @@ version = "~1.0"
features = ["derive"]

[dependencies.sqlx]
version = "~0.2.5" # Minimum version 0.2.5, as earlier ones had a critical connection leaking issue
version = "~0.3"
default-features = false
features = ["runtime-tokio", "postgres", "chrono", "uuid"]

Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ use sqlx::PgPool;
#[async_trait]
pub trait TileSource: Sized {
/// Renders the Mapbox vector tile for a slippy map tile in XYZ format.
async fn render_mvt(&self, pool: &PgPool, zoom: u8, x: i32, y: i32) -> Result<Vec<u8>, sqlx::Error>;
async fn render_mvt(
&self,
pool: &PgPool,
zoom: u8,
x: i32,
y: i32,
) -> Result<Vec<u8>, sqlx::Error>;
}

pub mod tm2;
Expand Down Expand Up @@ -117,4 +123,4 @@ mod tests {
};
assert_approx_eq!(correct_bounds.north, computed_bounds.north);
}
}
}
23 changes: 11 additions & 12 deletions src/tm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use serde::Deserialize;
// TODO: remove once async fn in traits become stable
use async_trait::async_trait;

use sqlx::{query, PgPool, Row};

use futures::stream::StreamExt;
use sqlx::{cursor::Cursor, query, PgPool, Row};

/// A TileMill (.tm2source) data structure.
///
Expand Down Expand Up @@ -120,7 +118,13 @@ impl TM2Source {

#[async_trait]
impl TileSource for TM2Source {
async fn render_mvt(&self, pool: &PgPool, zoom: u8, x: i32, y: i32) -> Result<Vec<u8>, sqlx::Error> {
async fn render_mvt(
&self,
pool: &PgPool,
zoom: u8,
x: i32,
y: i32,
) -> Result<Vec<u8>, sqlx::Error> {
let z: i32 = zoom.into();
let tile_bounds = get_epsg_3857_tile_bounds(self.pixel_scale, zoom, x, y, 0);
let buffer_sizes = self.buffer_sizes();
Expand All @@ -147,14 +151,9 @@ impl TileSource for TM2Source {

let mut raw_tile: Vec<u8> = Vec::new();
let mut stream = query.fetch(&mut conn);
while let Some(result) = stream.next().await {
match result {
Ok(row) => {
let layer: Vec<u8> = row.get(0);
raw_tile.extend_from_slice(&layer);
}
Err(e) => return Err(e),
}
while let Some(row) = stream.next().await? {
let layer: Vec<u8> = row.get(0);
raw_tile.extend_from_slice(&layer);
}

Ok(raw_tile)
Expand Down

0 comments on commit 1eb723b

Please sign in to comment.