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

polyphony-chat / sonata / #11

21 Jun 2025 09:29PM UTC coverage: 0.0%. Remained the same
#11

push

bitfl0wer
feat: Add Database connection method

0 of 18 new or added lines in 1 file covered. (0.0%)

0 of 55 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/database/mod.rs
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4

5
use sqlx::PgPool;
6
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};
7

8
use crate::StdResult;
9
use crate::config::DatabaseConfig;
10

11
#[derive(Debug, Clone)]
12
pub(crate) struct Database {
13
    pub pool: PgPool,
14
}
15

16
impl Database {
17
    /// Connect to the PostgreSQL Database using configuration options provided through [DatabaseConfig],
18
    /// which is most commonly derived by parsing a [SonataConfiguration].
NEW
19
    pub async fn connect_with_config(config: &DatabaseConfig) -> StdResult<Self> {
×
NEW
20
        let connect_options = PgConnectOptions::new()
×
NEW
21
            .host(&config.host)
×
NEW
22
            .database(&config.database)
×
23
            .application_name("sonata")
NEW
24
            .password(&config.password)
×
25
            .port(config.port)
NEW
26
            .ssl_mode(match config.tls {
×
NEW
27
                crate::config::TlsConfig::Disable => sqlx::postgres::PgSslMode::Disable,
×
NEW
28
                crate::config::TlsConfig::Allow => sqlx::postgres::PgSslMode::Allow,
×
NEW
29
                crate::config::TlsConfig::Prefer => sqlx::postgres::PgSslMode::Prefer,
×
NEW
30
                crate::config::TlsConfig::Require => sqlx::postgres::PgSslMode::Require,
×
NEW
31
                crate::config::TlsConfig::VerifyCa => sqlx::postgres::PgSslMode::VerifyCa,
×
NEW
32
                crate::config::TlsConfig::VerifyFull => sqlx::postgres::PgSslMode::VerifyFull,
×
33
            })
NEW
34
            .username(&config.username);
×
NEW
35
        let pool = PgPoolOptions::new()
×
NEW
36
            .max_connections(config.max_connections)
×
NEW
37
            .connect_with(connect_options)
×
NEW
38
            .await?;
×
NEW
39
        Ok(Self { pool })
×
40
    }
41
}
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