Use double precision for coordinates
This commit is contained in:
parent
78185cd40d
commit
2f238e8d1c
4 changed files with 53 additions and 51 deletions
|
|
@ -1,11 +1,11 @@
|
|||
CREATE TABLE places (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
name VARCHAR NOT NULL,
|
||||
address VARCHAR NOT NULL,
|
||||
open_hours VARCHAR NOT NULL,
|
||||
icon VARCHAR NOT NULL,
|
||||
description VARCHAR NOT NULL,
|
||||
longitude REAL NOT NULL,
|
||||
latitude REAL NOT NULL,
|
||||
longitude DOUBLE NOT NULL,
|
||||
latitude DOUBLE NOT NULL,
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,35 @@
|
|||
},
|
||||
"query": "UPDATE places SET (name, address, open_hours, icon, description, longitude, latitude) = (?, ?, ?, ?, ?, ?, ?)"
|
||||
},
|
||||
"8f8e9058b89c1f10360e08f8733c75e6ea2e8c15ff2c1e8a9f4a8ecd6e778642": {
|
||||
"af66ec71413501f84c7f4cb0dd732c8ebfcd3da36a5f1177918c2277a8674c28": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "UPDATE places SET active = FALSE WHERE id = ?"
|
||||
},
|
||||
"e10f7e8f125a3f60338f6c35b195517d4304304599c75e4f26f071e2a09609dc": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 7
|
||||
}
|
||||
},
|
||||
"query": "INSERT INTO places (name, address, open_hours, icon, description, longitude, latitude)VALUES (?, ?, ?, ?, ?, ?, ?)RETURNING id"
|
||||
},
|
||||
"fdc2eb1d98b93f2b61c756687f1a30edf2e4a74622e23b6b72a9509a9303385d": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
|
|
@ -44,12 +72,12 @@
|
|||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "longitude",
|
||||
"name": "longitude: f64",
|
||||
"ordinal": 6,
|
||||
"type_info": "Float"
|
||||
},
|
||||
{
|
||||
"name": "latitude",
|
||||
"name": "latitude: f64",
|
||||
"ordinal": 7,
|
||||
"type_info": "Float"
|
||||
}
|
||||
|
|
@ -68,34 +96,6 @@
|
|||
"Right": 0
|
||||
}
|
||||
},
|
||||
"query": "SELECT id, name, address, open_hours, icon, description, longitude, latitude FROM places WHERE active = TRUE"
|
||||
},
|
||||
"af66ec71413501f84c7f4cb0dd732c8ebfcd3da36a5f1177918c2277a8674c28": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "UPDATE places SET active = FALSE WHERE id = ?"
|
||||
},
|
||||
"e10f7e8f125a3f60338f6c35b195517d4304304599c75e4f26f071e2a09609dc": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 7
|
||||
}
|
||||
},
|
||||
"query": "INSERT INTO places (name, address, open_hours, icon, description, longitude, latitude)VALUES (?, ?, ?, ?, ?, ?, ?)RETURNING id"
|
||||
"query": "SELECT id, name, address, open_hours, icon, description,longitude as \"longitude: f64\", latitude as \"latitude: f64\" FROM places WHERE active = TRUE"
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,6 @@ pub struct Place {
|
|||
pub open_hours: String,
|
||||
pub icon: String,
|
||||
pub description: String,
|
||||
pub longitude: f32,
|
||||
pub latitude: f32,
|
||||
pub longitude: f64,
|
||||
pub latitude: f64,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ struct Db(rocket_db_pools::sqlx::SqlitePool);
|
|||
#[get("/places")]
|
||||
async fn get_places(mut db: Connection<Db>) -> Result<Json<Vec<Place>>> {
|
||||
let places = rocket_db_pools::sqlx::query!(
|
||||
"SELECT id, name, address, open_hours, icon, description, longitude, latitude FROM places WHERE active = TRUE")
|
||||
"SELECT id, name, address, open_hours, icon, description," +
|
||||
r#"longitude as "longitude: f64", latitude as "latitude: f64" FROM places WHERE active = TRUE"#
|
||||
)
|
||||
.fetch(&mut *db)
|
||||
.map_ok(|p| Place {
|
||||
id: Some(p.id),
|
||||
|
|
@ -26,7 +28,7 @@ async fn get_places(mut db: Connection<Db>) -> Result<Json<Vec<Place>>> {
|
|||
icon: p.icon,
|
||||
description: p.description,
|
||||
latitude: p.latitude,
|
||||
longitude: p.longitude
|
||||
longitude: p.longitude,
|
||||
})
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue