Connect Neon Database with Rust

I got “connection is insecure” error when I follow this (Connect a Rust application to Neon — Neon Docs). Do you have any idea how to solve this?

Hi. Yeah, we require TLS, we’ll update the example. The following works for me:

use postgres::Client;
use openssl::ssl::{SslConnector, SslMethod};
use postgres_openssl::MakeTlsConnector;
use std::error;

fn main() -> Result<(), Box<dyn error::Error>> {
    let builder = SslConnector::builder(SslMethod::tls())?;
    let connector = MakeTlsConnector::new(builder.build());

    let mut client = Client::connect("postgres://stas:[PASSWORD]@ep-cold-shadow-998636.eu-central-1.aws.neon.tech/ololo", connector)?;

    for row in client.query("SELECT 42", &[])? {
        let ret : i32 = row.get(0);
        println!("Result = {}", ret);
    }

    Ok(())
}
[dependencies]
postgres = "0.19"
postgres-openssl = "0.5"
openssl = "0.10"
1 Like