-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from nightly-labs/update-api-methods
Update api methods
- Loading branch information
Showing
28 changed files
with
270 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
pub enum DbError { | ||
DatabaseError(String), | ||
SqlxDbError(sqlx::Error), | ||
} | ||
|
||
impl fmt::Display for DbError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
DbError::DatabaseError(ref err) => write!(f, "Database error: {}", err), | ||
DbError::SqlxDbError(ref err) => write!(f, "Sqlx database error: {}", err), | ||
} | ||
} | ||
} | ||
|
||
impl From<sqlx::Error> for DbError { | ||
fn from(error: sqlx::Error) -> DbError { | ||
DbError::SqlxDbError(error) | ||
} | ||
} | ||
|
||
impl From<String> for DbError { | ||
fn from(error: String) -> DbError { | ||
DbError::DatabaseError(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
use super::table_struct::ClientProfile; | ||
use crate::db::Db; | ||
use crate::structs::db_error::DbError; | ||
use crate::tables::client_profiles::table_struct::CLIENT_PROFILES_TABLE_NAME; | ||
use sqlx::query_as; | ||
|
||
impl Db { | ||
pub async fn get_profile_by_profile_id( | ||
&self, | ||
client_profile_id: i64, | ||
) -> Result<ClientProfile, sqlx::Error> { | ||
) -> Result<ClientProfile, DbError> { | ||
let query = | ||
format!("SELECT * FROM {CLIENT_PROFILES_TABLE_NAME} WHERE client_profile_id = $1"); | ||
let typed_query = query_as::<_, ClientProfile>(&query); | ||
|
||
return typed_query | ||
.bind(&client_profile_id) | ||
.fetch_one(&self.connection_pool) | ||
.await; | ||
.await | ||
.map_err(|e| e.into()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.