Mercurial > lbo > hg > geohub
changeset 3:3586f77a0142
Add id column
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 01 Dec 2020 19:07:32 +0100 |
parents | 60191fa46a65 |
children | 5a0ac0fe8fb6 |
files | pgsql_schema.sql src/main.rs |
diffstat | 2 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/pgsql_schema.sql Tue Dec 01 14:32:30 2020 +0100 +++ b/pgsql_schema.sql Tue Dec 01 19:07:32 2020 +0100 @@ -24,7 +24,10 @@ -- Name: geodata; Type: TABLE; Schema: public; Owner: lbo -- -CREATE TABLE public.geodata ( +CREATE SCHEMA IF NOT EXISTS geohub; + +CREATE TABLE geohub.geodata ( + id text, lat double precision, long double precision, spd double precision, @@ -32,7 +35,7 @@ ); -ALTER TABLE public.geodata OWNER TO lbo; +ALTER TABLE geohub.geodata OWNER TO lbo; -- -- PostgreSQL database dump complete
--- a/src/main.rs Tue Dec 01 14:32:30 2020 +0100 +++ b/src/main.rs Tue Dec 01 19:07:32 2020 +0100 @@ -4,20 +4,21 @@ use rocket; use chrono::TimeZone; + #[rocket_contrib::database("geohub")] struct DBConn(postgres::Connection); /// lat, long are floats /// time is like 2020-11-30T20:12:36.444Z (ISO 8601) -#[rocket::get("/geo/log?<lat>&<longitude>&<time>&<s>")] -fn hello(db: DBConn, lat: f64, longitude: f64, time: String, s: f64) -> &'static str { +#[rocket::get("/geo/<name>/log?<lat>&<longitude>&<time>&<s>")] +fn hello(db: DBConn, name: String, lat: f64, longitude: f64, time: String, s: f64) -> &'static str { let ts = chrono::NaiveDateTime::parse_from_str(time.as_str(), "%Y-%m-%dT%H:%M:%S%.fZ") .ok() .map(|t| chrono::Utc::now().timezone().from_utc_datetime(&t)); println!("{:?}", ts); db.0.execute( - "INSERT INTO geodata (lat, long, spd, t) VALUES ($1, $2, $3, $4)", - &[&lat, &longitude, &s, &ts], + "INSERT INTO geohub.geodata (id, lat, long, spd, t) VALUES ($1, $2, $3, $4, $5)", + &[&name, &lat, &longitude, &s, &ts], ) .unwrap(); "OK"