first commit

This commit is contained in:
2025-11-25 16:58:24 +01:00
commit f5f5f10338
17 changed files with 5389 additions and 0 deletions

83
backend/src/db.rs Normal file
View File

@@ -0,0 +1,83 @@
use scylla::{Session, SessionBuilder};
use std::sync::Arc;
pub async fn initialize_schema(session: &Session) -> Result<(), Box<dyn std::error::Error>> {
// Create keyspace
session
.query(
"CREATE KEYSPACE IF NOT EXISTS map_data WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
&[],
)
.await?;
// Create table for OSM nodes (points)
// Partition by tile coordinates (zoom, x, y) for efficient retrieval
// This is a simplified schema. Real OSM data is more complex.
session
.query(
"CREATE TABLE IF NOT EXISTS map_data.nodes (
zoom int,
tile_x int,
tile_y int,
id bigint,
lat double,
lon double,
tags map<text, text>,
PRIMARY KEY ((zoom, tile_x, tile_y), id)
)",
&[],
)
.await?;
session
.query(
"CREATE TABLE IF NOT EXISTS map_data.ways (
zoom int,
tile_x int,
tile_y int,
id bigint,
tags map<text, text>,
points blob,
PRIMARY KEY ((zoom, tile_x, tile_y), id)
)",
&[],
)
.await?;
session
.query(
"CREATE TABLE IF NOT EXISTS map_data.buildings (
zoom int,
tile_x int,
tile_y int,
id bigint,
tags map<text, text>,
points blob,
PRIMARY KEY ((zoom, tile_x, tile_y), id)
)",
&[],
)
.await?;
println!("Schema initialized.");
Ok(())
}
pub async fn seed_data(session: &Session) -> Result<(), Box<dyn std::error::Error>> {
// Insert some dummy data for Munich (approx lat/lon)
// Munich is roughly at lat 48.1351, lon 11.5820
// At zoom 10, this falls into a specific tile.
// For simplicity, we'll just use a fixed tile coordinate for testing: 10/500/500 (not accurate, just for ID)
let insert_stmt = "INSERT INTO map_data.nodes (zoom, tile_x, tile_y, id, lat, lon, tags) VALUES (?, ?, ?, ?, ?, ?, ?)";
let prepared = session.prepare(insert_stmt).await?;
// Point 1: Marienplatz
session.execute(&prepared, (10, 500, 500, 1_i64, 48.137, 11.575, std::collections::HashMap::from([("name".to_string(), "Marienplatz".to_string())]))).await?;
// Point 2: English Garden
session.execute(&prepared, (10, 500, 500, 2_i64, 48.150, 11.590, std::collections::HashMap::from([("name".to_string(), "English Garden".to_string())]))).await?;
println!("Test data seeded.");
Ok(())
}