I get a json timestamp and want to store that in a Postgresql database. I am drowning in all the types.
input (from google location export):
"timestamp": "2019-12-31T13:29:28.613Z"
my up.sql:
CREATE TABLE IF NOT EXISTS public.log_google
(
time_visited timestamp with time zone NOT NULL,
latitude double precision NOT NULL,
longitude double precision NOT NULL,
accuracy integer,
CONSTRAINT log_google_pkey PRIMARY KEY (time_visited)
)
And then, I first parse it into a intermediate struct:
#[derive(Deserialize)]
#[allow(dead_code, non_snake_case)]
struct Location {
latitudeE7: i64,
longitudeE7: i64,
accuracy: isize,
source: String,
deviceTag: i64,
timestamp: DateTime<Utc>,
}
So far so good, but here is the first question is DateTime<Utc>
the most convenient choice?
And then to the next struct for PostgreSQL storage:
#[table_name = "log_google"]
pub struct LogGoogle {
pub time_visited: Timestamp,
pub latitude: f64,
pub longitude: f64,
pub accuracy: isize,
}
Here again, is Timestamp the one to use?
Any suggestions for optimal route from JSON to DB are welcome
And also how to convert between those types