summaryrefslogtreecommitdiff
path: root/src/setup/repo.rs
blob: ac014968e2a9c60de3b612ab26ef0eef00c35fda (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
use sqlx::{SqliteConnection, Transaction, sqlite::Sqlite};

pub trait Provider {
    fn setup(&mut self) -> Setup;
}

impl Provider for Transaction<'_, Sqlite> {
    fn setup(&mut self) -> Setup {
        Setup(self)
    }
}

pub struct Setup<'t>(&'t mut SqliteConnection);

impl Setup<'_> {
    pub async fn completed(&mut self) -> Result<bool, sqlx::Error> {
        let completed = sqlx::query_scalar!(
            r#"
                select count(*) > 0 as "completed: bool"
                from login
            "#,
        )
        .fetch_one(&mut *self.0)
        .await?;

        Ok(completed)
    }
}