MCPcopy Create free account
hub / github.com/actix/examples / add_user

Function add_user

databases/postgres/src/db.rs:21–42  ·  view source on GitHub ↗
(client: &Client, user_info: User)

Source from the content-addressed store, hash-verified

19}
20
21pub async fn add_user(client: &Client, user_info: User) -> Result<User, MyError> {
22 let _stmt = include_str!("../sql/add_user.sql");
23 let _stmt = _stmt.replace("$table_fields", &User::sql_table_fields());
24 let stmt = client.prepare(&_stmt).await.unwrap();
25
26 client
27 .query(
28 &stmt,
29 &[
30 &user_info.email,
31 &user_info.first_name,
32 &user_info.last_name,
33 &user_info.username,
34 ],
35 )
36 .await?
37 .iter()
38 .map(|row| User::from_row_ref(row).unwrap())
39 .collect::<Vec<User>>()
40 .pop()
41 .ok_or(MyError::NotFound) // more applicable for SELECTs
42}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected