Skip to content

Commit 1eb723b

Browse files
author
Ian Wagner
authored
Merge pull request #1 from stadiamaps/upgrade-sqlx
Upgrade SQLx
2 parents 72474bc + 92f857a commit 1eb723b

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tile_sorcerer"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Ian Wagner <[email protected]>", "Luke Seelenbinder <[email protected]>"]
55
license = "BSD-3-Clause"
66
repository = "https://github.com/stadiamaps/tile_sorcerer"
@@ -22,7 +22,7 @@ version = "~1.0"
2222
features = ["derive"]
2323

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

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ use sqlx::PgPool;
1717
#[async_trait]
1818
pub trait TileSource: Sized {
1919
/// Renders the Mapbox vector tile for a slippy map tile in XYZ format.
20-
async fn render_mvt(&self, pool: &PgPool, zoom: u8, x: i32, y: i32) -> Result<Vec<u8>, sqlx::Error>;
20+
async fn render_mvt(
21+
&self,
22+
pool: &PgPool,
23+
zoom: u8,
24+
x: i32,
25+
y: i32,
26+
) -> Result<Vec<u8>, sqlx::Error>;
2127
}
2228

2329
pub mod tm2;
@@ -117,4 +123,4 @@ mod tests {
117123
};
118124
assert_approx_eq!(correct_bounds.north, computed_bounds.north);
119125
}
120-
}
126+
}

src/tm2.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use serde::Deserialize;
1010
// TODO: remove once async fn in traits become stable
1111
use async_trait::async_trait;
1212

13-
use sqlx::{query, PgPool, Row};
14-
15-
use futures::stream::StreamExt;
13+
use sqlx::{cursor::Cursor, query, PgPool, Row};
1614

1715
/// A TileMill (.tm2source) data structure.
1816
///
@@ -120,7 +118,13 @@ impl TM2Source {
120118

121119
#[async_trait]
122120
impl TileSource for TM2Source {
123-
async fn render_mvt(&self, pool: &PgPool, zoom: u8, x: i32, y: i32) -> Result<Vec<u8>, sqlx::Error> {
121+
async fn render_mvt(
122+
&self,
123+
pool: &PgPool,
124+
zoom: u8,
125+
x: i32,
126+
y: i32,
127+
) -> Result<Vec<u8>, sqlx::Error> {
124128
let z: i32 = zoom.into();
125129
let tile_bounds = get_epsg_3857_tile_bounds(self.pixel_scale, zoom, x, y, 0);
126130
let buffer_sizes = self.buffer_sizes();
@@ -147,14 +151,9 @@ impl TileSource for TM2Source {
147151

148152
let mut raw_tile: Vec<u8> = Vec::new();
149153
let mut stream = query.fetch(&mut conn);
150-
while let Some(result) = stream.next().await {
151-
match result {
152-
Ok(row) => {
153-
let layer: Vec<u8> = row.get(0);
154-
raw_tile.extend_from_slice(&layer);
155-
}
156-
Err(e) => return Err(e),
157-
}
154+
while let Some(row) = stream.next().await? {
155+
let layer: Vec<u8> = row.get(0);
156+
raw_tile.extend_from_slice(&layer);
158157
}
159158

160159
Ok(raw_tile)

0 commit comments

Comments
 (0)