mirror of
https://github.com/MedzikUser/HomeDisk.git
synced 2024-08-14 21:46:53 +00:00
database: update docs
This commit is contained in:
parent
08a61f1a48
commit
2cca093d26
2 changed files with 20 additions and 4 deletions
|
@ -23,8 +23,8 @@ impl fmt::Display for Error {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Error::UserNotFound => write!(f, "user not found"),
|
||||
Error::SQLx(err) => write!(f, "sqlx error: {}", err),
|
||||
Error::Io(err) => write!(f, "std::io error: {}", err),
|
||||
Error::SQLx(err) => write!(f, "kind `sqlx`: {:?}", err),
|
||||
Error::Io(err) => write!(f, "kind `io`: {:?}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,15 @@ impl Database {
|
|||
}
|
||||
|
||||
/// Find user
|
||||
/// ```ignore
|
||||
/// use homedisk_database::{Database, User};
|
||||
///
|
||||
/// let user = User::new("username", "password");
|
||||
///
|
||||
/// db.find_user(&user.username, &user.password).await?;
|
||||
/// ```
|
||||
pub async fn find_user(&self, username: &str, password: &str) -> Result<User, Error> {
|
||||
debug!("search for user - {}", username);
|
||||
debug!("searching for user - {}", username);
|
||||
|
||||
let query =
|
||||
sqlx::query_as::<_, User>("SELECT * FROM user WHERE username = ? AND password = ?")
|
||||
|
@ -67,7 +74,16 @@ impl Database {
|
|||
}
|
||||
|
||||
/// Find user by UUID
|
||||
/// ```ignore
|
||||
/// use homedisk_database::{Database, User};
|
||||
///
|
||||
/// let user = User::new("username", "password");
|
||||
///
|
||||
/// db.find_user_by_id(&user.id).await?;
|
||||
/// ```
|
||||
pub async fn find_user_by_id(&self, id: String) -> Result<User, Error> {
|
||||
debug!("searching for a user by UUID - {}", id);
|
||||
|
||||
let query = sqlx::query_as::<_, User>("SELECT * FROM user WHERE id = ?").bind(id);
|
||||
|
||||
let mut stream = self.conn.fetch(query);
|
||||
|
@ -191,7 +207,7 @@ mod tests {
|
|||
|
||||
new_user(&db).await;
|
||||
|
||||
let other_user = User::new("other_user", "secretpassphrase123!");
|
||||
let other_user = User::new("other_user", "secret@passphrase123!");
|
||||
|
||||
let err = db.find_user_by_id(other_user.id).await.unwrap_err();
|
||||
|
||||
|
|
Loading…
Reference in a new issue