MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

21_postgresql/rust/pg_blocking/src/main.rs:37–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35}
36
37fn main() -> Result<(), Error> {
38 let mut client = Client::connect("host=localhost user=htd", NoTls)?;
39
40 let rows = client.query(MOST_RECOVERED, &[])?;
41
42 let value: chrono::NaiveDate = rows[0].get(0);
43 println!("{:?}", value);
44 println!("{:?}", row_to_str_vec(&rows[0]));
45 println!("{:?}", row_to_str_hashmap(&rows[0]));
46
47 let mut transaction = client.transaction()?;
48 transaction.query("DELETE FROM month_cases", &[])?;
49 let ins_mv = transaction.prepare(
50 "INSERT INTO month_cases
51 (mon, new_cases, recovered)
52 VALUES ($1, $2, $3)",
53 )?;
54 for row in transaction.query(GROUP_BY_MONTH, &[])? {
55 println!("{:?}", row_to_str_vec(&row));
56 let date: chrono::NaiveDate = row.get(0);
57 let new_cases: i64 = row.get(1);
58 let recovered: i64 = row.get(2);
59 transaction.execute(
60 &ins_mv,
61 &[&date.to_string(), &(new_cases as i32), &(recovered as i32)],
62 )?;
63 }
64 transaction.commit()?;
65 Ok(())
66}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected