Skip to content

Commit

Permalink
fix: disabling the statement cache for sqlx
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowHatpro committed Sep 15, 2024
1 parent 417447f commit 28aa5f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/development.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ url = "your sentry DSN here"

[database]
pg_host = "localhost" # If running as a docker container, change this to musicbrainz-docker-db-1
pg_port = "5432"
pg_port = 5432
pg_user = "musicbrainz"
pg_password = "musicbrainz"
pg_database = "musicbrainz_db"
Expand Down
2 changes: 1 addition & 1 deletion config/production.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ url = "enter your project url"

[database]
pg_host = ""
pg_port = ""
pg_port = 5432
pg_user = ""
pg_password = ""
pg_database = ""
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Sentry {
#[derive(Debug, Deserialize)]
pub struct Database {
pub pg_host: String,
pub pg_port: String,
pub pg_port: u16,
pub pg_user: String,
pub pg_password: String,
pub pg_database: String,
Expand Down
17 changes: 11 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::configuration::Settings;
use sqlx::postgres::PgPoolOptions;
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};

mod app;
mod archival;
Expand Down Expand Up @@ -38,13 +38,18 @@ fn main() {
let password = settings.database.pg_password;
let port = settings.database.pg_port;
let db = settings.database.pg_database;
let db_url = format!(
"postgres://{}:{}@{}:{}/{}",
user, password, hostname, port, db
);

let connect_options = PgConnectOptions::new()
.host(&hostname)
.port(port)
.username(&user)
.password(&password)
.database(&db)
.statement_cache_capacity(0);

let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&db_url)
.connect_with(connect_options)
.await
.expect("Failed to connect to the database");

Expand Down

0 comments on commit 28aa5f5

Please sign in to comment.