Here's my insert statement:
let insert_query: (&str, &[&str]) = (
"INSERT INTO multicast_bgproute (cd_id, route, peer, age, net_mask, missing) VALUES ((select id from multicast_contentdevices WHERE ip_address= $1), $2, $3, $4, $5, $6) ON CONFLICT (cd_id, route, peer, net_mask) DO UPDATE SET age = $7",
&[&address, &route, &peer, &age, &netmask, &missing, &age]
);
I pass it to here:
pub fn insert(&self, qs: (&'static str, &[&str])) {
let mut tasks = vec![];
for _ in 0..20 {
let mut pool = self.pool.clone();
let i = qs.0.clone();
let params = qs.1.clone();
let th = thread::spawn(move || {
let mut client = pool.get().unwrap();
client.execute(i, &[params]).unwrap();
});
tasks.push(th);
}
for th in tasks {
let _ = th.join();
}
}
I just can't get the params to work.
error[E0277]: the trait bound `[&str]: ToSql` is not satisfied
--> /home/mitch/CLionProjects/psql/src/lib.rs:45:45
|
45 | client.execute(i, &[params]).unwrap();
| ^^^^^^ the trait `ToSql` is not implemented for `[&str]`
|
= help: the following implementations were found:
<&'a [T] as ToSql>
<&'a [u8] as ToSql>
= note: required for the cast to the object type `dyn ToSql + Sync`
Also, I could use a time stamp in that query, but I don't know how to get time as a String/&str in Rust.