From 10017f2596673f2918708fd706a1cbf399679e78 Mon Sep 17 00:00:00 2001 From: Ethan Donowitz Date: Fri, 23 Jul 2021 17:55:32 +0000 Subject: [PATCH] review --- src/tokenserver/db/models.rs | 51 ++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/tokenserver/db/models.rs b/src/tokenserver/db/models.rs index 8e7b34bc18..06df9303b1 100644 --- a/src/tokenserver/db/models.rs +++ b/src/tokenserver/db/models.rs @@ -64,10 +64,11 @@ impl TokenserverDb { fn get_user_sync(&self, email: String) -> DbResult { let query = r#" SELECT users.uid, users.email, users.client_state, users.generation, - users.keys_changed_at, users.created_at, nodes.node - FROM users - JOIN nodes ON nodes.id = users.nodeid - WHERE users.email = ? + users.keys_changed_at, users.created_at, nodes.node + FROM users + JOIN nodes + ON nodes.id = users.nodeid + WHERE users.email = ? "#; let mut user_records = diesel::sql_query(query) .bind::(email) @@ -87,9 +88,8 @@ impl TokenserverDb { fn post_node_sync(&self, node: params::PostNode) -> DbResult { let query = r#" INSERT INTO nodes (service, node, available, current_load, capacity, downed, backoff) - VALUES (?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?) "#; - diesel::sql_query(query) .bind::(node.service_id) .bind::(&node.node) @@ -101,16 +101,16 @@ impl TokenserverDb { .execute(&self.inner.conn)?; let query = r#" - SELECT id FROM nodes - WHERE service = ? AND - node = ? AND - available = ? AND - current_load = ? AND - capacity = ? AND - downed = ? AND - backoff = ? + SELECT id + FROM nodes + WHERE service = ? + AND node = ? + AND available = ? + AND current_load = ? + AND capacity = ? + AND downed = ? + AND backoff = ? "#; - diesel::sql_query(query) .bind::(node.service_id) .bind::(&node.node) @@ -125,13 +125,21 @@ impl TokenserverDb { #[cfg(test)] fn post_service_sync(&self, service: params::PostService) -> DbResult { - let query = "INSERT INTO services (service, pattern) VALUES (?, ?)"; + let query = r#" + INSERT INTO services (service, pattern) + VALUES (?, ?) + "#; diesel::sql_query(query) .bind::(&service.service) .bind::(service.pattern) .execute(&self.inner.conn)?; - let query = "SELECT id FROM services WHERE service = ? AND pattern = ?"; + let query = r#" + SELECT id + FROM services + WHERE service = ? + AND pattern = ? + "#; diesel::sql_query(query) .bind::(&service.service) .bind::(&service.service) @@ -143,9 +151,8 @@ impl TokenserverDb { fn post_user_sync(&self, user: params::PostUser) -> DbResult { let query = r#" INSERT INTO users (service, email, generation, client_state, created_at, replaced_at, nodeid, keys_changed_at) - VALUES (?, ?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) "#; - diesel::sql_query(query) .bind::(user.service_id) .bind::(&user.email) @@ -157,7 +164,11 @@ impl TokenserverDb { .bind::, _>(user.keys_changed_at) .execute(&self.inner.conn)?; - let query = "SELECT uid FROM users WHERE email = ?"; + let query = r#" + SELECT uid + FROM users + WHERE email = ? + "#; diesel::sql_query(query) .bind::(&user.email) .get_result::(&self.inner.conn)