diff options
Diffstat (limited to 'src/locations.rs')
| -rw-r--r-- | src/locations.rs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/locations.rs b/src/locations.rs index e5f881d..2f8c3f8 100644 --- a/src/locations.rs +++ b/src/locations.rs @@ -21,13 +21,20 @@ impl<'a> LocationRepository<'a> { } pub async fn get_location(&self, id: i64) -> Result<Option<Location>, sqlx::Error> { - sqlx::query_as::<_, Location>("SELECT id, latitude, longitude, user_id FROM locations WHERE id = ?") - .bind(id) - .fetch_optional(self.db) - .await + sqlx::query_as::<_, Location>( + "SELECT id, latitude, longitude, user_id FROM locations WHERE id = ?", + ) + .bind(id) + .fetch_optional(self.db) + .await } - pub async fn create_location(&self, latitude: f64, longitude: f64, user_id: i64) -> Result<Location, sqlx::Error> { + pub async fn create_location( + &self, + latitude: f64, + longitude: f64, + user_id: i64, + ) -> Result<Location, sqlx::Error> { sqlx::query_as::<_, Location>( "INSERT INTO locations (latitude, longitude, user_id) VALUES (?, ?, ?) RETURNING id, latitude, longitude, user_id" ) @@ -38,7 +45,12 @@ impl<'a> LocationRepository<'a> { .await } - pub async fn update_location(&self, id: i64, latitude: f64, longitude: f64) -> Result<Location, sqlx::Error> { + pub async fn update_location( + &self, + id: i64, + latitude: f64, + longitude: f64, + ) -> Result<Location, sqlx::Error> { sqlx::query_as::<_, Location>( "UPDATE locations SET latitude = ?, longitude = ? WHERE id = ? RETURNING id, latitude, longitude, user_id" ) @@ -62,7 +74,7 @@ impl<'a> LocationRepository<'a> { mod tests { use super::*; use crate::users::{UserRepository, UserRole}; - use sqlx::{SqlitePool, Executor}; + use sqlx::{Executor, SqlitePool}; use tokio; async fn setup_db() -> SqlitePool { @@ -72,8 +84,10 @@ mod tests { id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT NOT NULL UNIQUE, role TEXT NOT NULL DEFAULT 'user' - );" - ).await.unwrap(); + );", + ) + .await + .unwrap(); pool.execute( "CREATE TABLE locations ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -81,8 +95,10 @@ mod tests { longitude REAL NOT NULL, user_id INTEGER NOT NULL, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE NO ACTION - );" - ).await.unwrap(); + );", + ) + .await + .unwrap(); pool } @@ -136,4 +152,4 @@ mod tests { let locations = repo.list_locations().await.unwrap(); assert_eq!(locations.len(), 2); } -}
\ No newline at end of file +} |
