Skip to content

Commit

Permalink
rename mbtiles files
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Oct 2, 2023
1 parent 8002283 commit cc6b8fd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 38 deletions.
20 changes: 10 additions & 10 deletions martin-mbtiles/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};

use clap::{Parser, Subcommand};
use log::{error, LevelFilter};
use martin_mbtiles::{apply_mbtiles_diff, IntegrityCheckType, MbtResult, Mbtiles, TileCopier};
use martin_mbtiles::{apply_mbtiles_diff, IntegrityCheckType, MbtResult, Mbtiles, MbtilesCopier};

#[derive(Parser, PartialEq, Eq, Debug)]
#[command(
Expand Down Expand Up @@ -46,7 +46,7 @@ enum Commands {
},
/// Copy tiles from one mbtiles file to another.
#[command(name = "copy")]
Copy(TileCopier),
Copy(MbtilesCopier),
/// Apply diff file generated from 'copy' command
#[command(name = "apply-diff")]
ApplyDiff {
Expand Down Expand Up @@ -163,7 +163,7 @@ mod tests {

use clap::error::ErrorKind;
use clap::Parser;
use martin_mbtiles::{CopyDuplicateMode, TileCopier};
use martin_mbtiles::{CopyDuplicateMode, MbtilesCopier};

use crate::Commands::{ApplyDiff, Copy, MetaGetValue, MetaSetValue, Validate};
use crate::{Args, IntegrityCheckType};
Expand All @@ -184,7 +184,7 @@ mod tests {
Args::parse_from(["mbtiles", "copy", "src_file", "dst_file"]),
Args {
verbose: false,
command: Copy(TileCopier::new(
command: Copy(MbtilesCopier::new(
PathBuf::from("src_file"),
PathBuf::from("dst_file")
))
Expand All @@ -208,7 +208,7 @@ mod tests {
Args {
verbose: false,
command: Copy(
TileCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
MbtilesCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
.min_zoom(Some(1))
.max_zoom(Some(100))
)
Expand Down Expand Up @@ -268,7 +268,7 @@ mod tests {
Args {
verbose: false,
command: Copy(
TileCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
MbtilesCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
.zoom_levels(vec![1, 3, 7])
)
}
Expand All @@ -289,7 +289,7 @@ mod tests {
Args {
verbose: false,
command: Copy(
TileCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
MbtilesCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
.diff_with_file(PathBuf::from("no_file"))
)
}
Expand All @@ -310,7 +310,7 @@ mod tests {
Args {
verbose: false,
command: Copy(
TileCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
MbtilesCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
.on_duplicate(CopyDuplicateMode::Override)
)
}
Expand All @@ -331,7 +331,7 @@ mod tests {
Args {
verbose: false,
command: Copy(
TileCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
MbtilesCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
.on_duplicate(CopyDuplicateMode::Ignore)
)
}
Expand All @@ -352,7 +352,7 @@ mod tests {
Args {
verbose: false,
command: Copy(
TileCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
MbtilesCopier::new(PathBuf::from("src_file"), PathBuf::from("dst_file"))
.on_duplicate(CopyDuplicateMode::Abort)
)
}
Expand Down
57 changes: 35 additions & 22 deletions martin-mbtiles/src/tile_copier.rs → martin-mbtiles/src/copier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sqlx::{query, Connection, Row, SqliteConnection};
use crate::errors::MbtResult;
use crate::mbtiles::MbtType::{Flat, FlatWithHash, Normalized};
use crate::mbtiles::{attach_hash_fn, MbtType};
use crate::mbtiles_queries::{
use crate::queries::{
create_flat_tables, create_flat_with_hash_tables, create_metadata_table,
create_normalized_tables, create_tiles_with_hash_view,
};
Expand All @@ -28,7 +28,7 @@ pub enum CopyDuplicateMode {

#[derive(Clone, Default, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "cli", derive(Args))]
pub struct TileCopier {
pub struct MbtilesCopier {
/// MBTiles file to read from
src_file: PathBuf,
/// MBTiles file to write to
Expand Down Expand Up @@ -89,13 +89,13 @@ impl clap::builder::TypedValueParser for HashSetValueParser {
}

#[derive(Clone, Debug)]
struct TileCopierInt {
struct MbtileCopierInt {
src_mbtiles: Mbtiles,
dst_mbtiles: Mbtiles,
options: TileCopier,
options: MbtilesCopier,
}

impl TileCopier {
impl MbtilesCopier {
#[must_use]
pub fn new(src_filepath: PathBuf, dst_filepath: PathBuf) -> Self {
Self {
Expand Down Expand Up @@ -154,13 +154,13 @@ impl TileCopier {
}

pub async fn run(self) -> MbtResult<SqliteConnection> {
TileCopierInt::new(self)?.run().await
MbtileCopierInt::new(self)?.run().await
}
}

impl TileCopierInt {
pub fn new(options: TileCopier) -> MbtResult<Self> {
Ok(TileCopierInt {
impl MbtileCopierInt {
pub fn new(options: MbtilesCopier) -> MbtResult<Self> {
Ok(MbtileCopierInt {
src_mbtiles: Mbtiles::new(&options.src_file)?,
dst_mbtiles: Mbtiles::new(&options.dst_file)?,
options,
Expand Down Expand Up @@ -475,7 +475,7 @@ mod tests {
dst_type: Option<MbtType>,
expected_dst_type: MbtType,
) -> MbtResult<()> {
let mut dst_conn = TileCopier::new(src_filepath.clone(), dst_filepath.clone())
let mut dst_conn = MbtilesCopier::new(src_filepath.clone(), dst_filepath.clone())
.dst_type(dst_type)
.run()
.await?;
Expand All @@ -502,7 +502,7 @@ mod tests {
}

async fn verify_copy_with_zoom_filter(
opts: TileCopier,
opts: MbtilesCopier,
expected_zoom_levels: u8,
) -> MbtResult<()> {
let mut dst_conn = opts.run().await?;
Expand Down Expand Up @@ -596,7 +596,7 @@ mod tests {
async fn copy_with_min_max_zoom() -> MbtResult<()> {
let src = PathBuf::from("../tests/fixtures/mbtiles/world_cities.mbtiles");
let dst = PathBuf::from("file:copy_with_min_max_zoom_mem_db?mode=memory&cache=shared");
let opt = TileCopier::new(src, dst)
let opt = MbtilesCopier::new(src, dst)
.min_zoom(Some(2))
.max_zoom(Some(4));
verify_copy_with_zoom_filter(opt, 3).await
Expand All @@ -606,7 +606,7 @@ mod tests {
async fn copy_with_zoom_levels() -> MbtResult<()> {
let src = PathBuf::from("../tests/fixtures/mbtiles/world_cities.mbtiles");
let dst = PathBuf::from("file:copy_with_zoom_levels_mem_db?mode=memory&cache=shared");
let opt = TileCopier::new(src, dst)
let opt = MbtilesCopier::new(src, dst)
.min_zoom(Some(2))
.max_zoom(Some(4))
.zoom_levels(vec![1, 6]);
Expand All @@ -621,7 +621,8 @@ mod tests {
let diff_file =
PathBuf::from("../tests/fixtures/mbtiles/geography-class-jpg-modified.mbtiles");

let copy_opts = TileCopier::new(src.clone(), dst.clone()).diff_with_file(diff_file.clone());
let copy_opts =
MbtilesCopier::new(src.clone(), dst.clone()).diff_with_file(diff_file.clone());

let mut dst_conn = copy_opts.run().await?;

Expand Down Expand Up @@ -669,7 +670,9 @@ mod tests {
"file:ignore_dst_type_when_copy_to_existing_mem_db?mode=memory&cache=shared",
);

let _dst_conn = TileCopier::new(dst_file.clone(), dst.clone()).run().await?;
let _dst_conn = MbtilesCopier::new(dst_file.clone(), dst.clone())
.run()
.await?;

verify_copy_all(src_file, dst, Some(Normalized), Flat).await
}
Expand All @@ -680,7 +683,7 @@ mod tests {
let dst = PathBuf::from("../tests/fixtures/mbtiles/world_cities.mbtiles");

let copy_opts =
TileCopier::new(src.clone(), dst.clone()).on_duplicate(CopyDuplicateMode::Abort);
MbtilesCopier::new(src.clone(), dst.clone()).on_duplicate(CopyDuplicateMode::Abort);

assert!(matches!(
copy_opts.run().await.unwrap_err(),
Expand All @@ -697,9 +700,13 @@ mod tests {
let dst =
PathBuf::from("file:copy_to_existing_override_mode_mem_db?mode=memory&cache=shared");

let _dst_conn = TileCopier::new(dst_file.clone(), dst.clone()).run().await?;
let _dst_conn = MbtilesCopier::new(dst_file.clone(), dst.clone())
.run()
.await?;

let mut dst_conn = TileCopier::new(src_file.clone(), dst.clone()).run().await?;
let mut dst_conn = MbtilesCopier::new(src_file.clone(), dst.clone())
.run()
.await?;

// Verify the tiles in the destination file is a superset of the tiles in the source file
Mbtiles::new(src_file)?
Expand All @@ -724,9 +731,11 @@ mod tests {
let dst =
PathBuf::from("file:copy_to_existing_ignore_mode_mem_db?mode=memory&cache=shared");

let _dst_conn = TileCopier::new(dst_file.clone(), dst.clone()).run().await?;
let _dst_conn = MbtilesCopier::new(dst_file.clone(), dst.clone())
.run()
.await?;

let mut dst_conn = TileCopier::new(src_file.clone(), dst.clone())
let mut dst_conn = MbtilesCopier::new(src_file.clone(), dst.clone())
.on_duplicate(CopyDuplicateMode::Ignore)
.run()
.await?;
Expand Down Expand Up @@ -771,7 +780,9 @@ mod tests {
let src_file = PathBuf::from("../tests/fixtures/mbtiles/world_cities.mbtiles");
let src = PathBuf::from("file:apply_flat_diff_file_mem_db?mode=memory&cache=shared");

let mut src_conn = TileCopier::new(src_file.clone(), src.clone()).run().await?;
let mut src_conn = MbtilesCopier::new(src_file.clone(), src.clone())
.run()
.await?;

// Apply diff to the src data in in-memory DB
let diff_file = PathBuf::from("../tests/fixtures/mbtiles/world_cities_diff.mbtiles");
Expand All @@ -798,7 +809,9 @@ mod tests {
let src_file = PathBuf::from("../tests/fixtures/mbtiles/geography-class-jpg.mbtiles");
let src = PathBuf::from("file:apply_normalized_diff_file_mem_db?mode=memory&cache=shared");

let mut src_conn = TileCopier::new(src_file.clone(), src.clone()).run().await?;
let mut src_conn = MbtilesCopier::new(src_file.clone(), src.clone())
.run()
.await?;

// Apply diff to the src data in in-memory DB
let diff_file = PathBuf::from("../tests/fixtures/mbtiles/geography-class-jpg-diff.mbtiles");
Expand Down
10 changes: 5 additions & 5 deletions martin-mbtiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub use errors::{MbtError, MbtResult};
mod mbtiles;
pub use mbtiles::{IntegrityCheckType, Mbtiles, Metadata};

mod mbtiles_pool;
pub use mbtiles_pool::MbtilesPool;
mod pool;
pub use pool::MbtilesPool;

mod tile_copier;
pub use tile_copier::{apply_mbtiles_diff, CopyDuplicateMode, TileCopier};
mod copier;
pub use copier::{apply_mbtiles_diff, CopyDuplicateMode, MbtilesCopier};

mod mbtiles_queries;
mod queries;
2 changes: 1 addition & 1 deletion martin-mbtiles/src/mbtiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sqlx::{query, Connection as _, Row, SqliteConnection, SqliteExecutor};
use tilejson::{tilejson, Bounds, Center, TileJSON};

use crate::errors::{MbtError, MbtResult};
use crate::mbtiles_queries::{
use crate::queries::{
is_flat_tables_type, is_flat_with_hash_tables_type, is_normalized_tables_type,
};
use crate::MbtError::{
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit cc6b8fd

Please sign in to comment.