• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / pg_replicate / 12929014939

23 Jan 2025 12:19PM UTC coverage: 36.501% (-0.5%) from 36.994%
12929014939

push

github

imor
update sqlx metadata

2005 of 5493 relevant lines covered (36.5%)

15.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

24.0
/api/src/db/replicators.rs
1
use sqlx::{PgPool, Postgres, Transaction};
2

3
pub struct Replicator {
4
    pub id: i64,
5
    pub tenant_id: String,
6
    pub image_id: i64,
7
}
8

9
pub async fn create_replicator(
×
10
    pool: &PgPool,
×
11
    tenant_id: &str,
×
12
    image_id: i64,
×
13
) -> Result<i64, sqlx::Error> {
×
14
    let mut txn = pool.begin().await?;
×
15
    let res = create_replicator_txn(&mut txn, tenant_id, image_id).await;
×
16
    txn.commit().await?;
×
17
    res
×
18
}
×
19

20
pub async fn create_replicator_txn(
8✔
21
    txn: &mut Transaction<'_, Postgres>,
8✔
22
    tenant_id: &str,
8✔
23
    image_id: i64,
8✔
24
) -> Result<i64, sqlx::Error> {
8✔
25
    let record = sqlx::query!(
8✔
26
        r#"
8✔
27
        insert into app.replicators (tenant_id, image_id)
8✔
28
        values ($1, $2)
8✔
29
        returning id
8✔
30
        "#,
8✔
31
        tenant_id,
8✔
32
        image_id
8✔
33
    )
8✔
34
    .fetch_one(&mut **txn)
8✔
35
    .await?;
8✔
36

37
    Ok(record.id)
8✔
38
}
8✔
39

40
pub async fn read_replicator_by_pipeline_id(
×
41
    pool: &PgPool,
×
42
    tenant_id: &str,
×
43
    pipeline_id: i64,
×
44
) -> Result<Option<Replicator>, sqlx::Error> {
×
45
    let record = sqlx::query!(
×
46
        r#"
×
47
        select r.id, r.tenant_id, r.image_id
×
48
        from app.replicators r
×
49
        join app.pipelines p on r.id = p.replicator_id
×
50
        where r.tenant_id = $1 and p.tenant_id = $1 and p.id = $2
×
51
        "#,
×
52
        tenant_id,
×
53
        pipeline_id,
×
54
    )
×
55
    .fetch_optional(pool)
×
56
    .await?;
×
57

58
    Ok(record.map(|r| Replicator {
×
59
        id: r.id,
×
60
        tenant_id: r.tenant_id,
×
61
        image_id: r.image_id,
×
62
    }))
×
63
}
×
64

65
pub async fn read_replicators(
×
66
    pool: &PgPool,
×
67
    tenant_id: &str,
×
68
) -> Result<Vec<Replicator>, sqlx::Error> {
×
69
    let mut records = sqlx::query!(
×
70
        r#"
×
71
        select r.id, r.tenant_id, r.image_id
×
72
        from app.replicators r
×
73
        join app.pipelines p on r.id = p.replicator_id
×
74
        where r.tenant_id = $1 and p.tenant_id = $1
×
75
        "#,
×
76
        tenant_id,
×
77
    )
×
78
    .fetch_all(pool)
×
79
    .await?;
×
80

81
    Ok(records
×
82
        .drain(..)
×
83
        .map(|r| Replicator {
×
84
            id: r.id,
×
85
            tenant_id: r.tenant_id,
×
86
            image_id: r.image_id,
×
87
        })
×
88
        .collect())
×
89
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc