blob: 15adb3135cdbccfd6a5ba79855ca67e985613de4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
use sqlx::sqlite::SqlitePool;
use crate::event::{repo::Provider as _, Sequence};
#[cfg(test)]
use super::{repo::Provider as _, Login, Password};
pub struct Logins<'a> {
db: &'a SqlitePool,
}
impl<'a> Logins<'a> {
pub const fn new(db: &'a SqlitePool) -> Self {
Self { db }
}
pub async fn boot_point(&self) -> Result<Sequence, sqlx::Error> {
let mut tx = self.db.begin().await?;
let sequence = tx.sequence().current().await?;
tx.commit().await?;
Ok(sequence)
}
#[cfg(test)]
pub async fn create(&self, name: &str, password: &Password) -> Result<Login, CreateError> {
let password_hash = password.hash()?;
let mut tx = self.db.begin().await?;
let login = tx.logins().create(name, &password_hash).await?;
tx.commit().await?;
Ok(login)
}
}
#[cfg(test)]
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub enum CreateError {
DatabaseError(#[from] sqlx::Error),
PasswordHashError(#[from] password_hash::Error),
}
|