0

After creating Postgres<pool> and execute query. Database doesn't include any changes, but if I execute the same INSERT with the unique field, it returns an Error like it already exists.

let from_ssl = |ssl: bool| -> PgSslMode {
    match ssl {
        true => PgSslMode::Require,
        false => PgSslMode::Disable,
    }
};
let conn = PgConnectOptions::new()
    .host(db.host.as_str())
    .port(db.port)
    .username(db.user.as_str())
    .password(db.password.as_str())
    .ssl_mode(from_ssl(db.ssl));

let pool = PgPoolOptions::new()
    .max_connections(5)
    .idle_timeout(Some(Duration::new(60, 0)))
    .connect_with(conn)
    .await?;

Ok(DbBuilder { pool })
sqlx::query!("INSERT INTO configs \
            (name, is_available, membership_id, priority_index, params)\
            VALUES( $1, $2 ,$3 ,$4, $5);",
               name, is_available, 1, 1, params)
                .execute(&db.pool)
                .await?;
smitop
  • 4,770
  • 2
  • 20
  • 53
  • "Database doesn't include any changes" - how do you check this? – Cerberus Jun 30 '22 at 09:12
  • using the database console or directly viewing the information in it – Gleb Protasov Jun 30 '22 at 09:35
  • 1
    Not an expert of sqlx, but from description you are not committing: the key is duplicated inside your transaction, so you get the error, but reading outside you see nothing, wich can be normal if not committed. – user_0 Jun 30 '22 at 12:56
  • @https://stackoverflow.com/users/3182456/user-0 thanks for your replay. However, it still doesn't work. Next code solved my problem, but i am still don't really understand what is a difference ` let pool = PgPoolOptions::new() .connect(db_url.as_str()) .await?;` – Gleb Protasov Jul 01 '22 at 09:25

1 Answers1

0

Next code solved my problem, but i don't really understand what is a difference let pool = PgPoolOptions::new() .connect(db_url.as_str()) .await?;