Skip to content

Commit 778d23e

Browse files
committed
Fixed Retries
1 parent 9024b7b commit 778d23e

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,31 @@ my-postgres = { tag = "xxx", git = "https://github.com/MyJetTools/my-postgres.gi
2828
```
2929
whether to use TLS or not is detected by **sslmode=require** in the connection string
3030

31+
### SSH Connection
3132

33+
For the sake of optimization - the SSH feature is not included by default.
34+
35+
If you are planning to use connections with SSH tunneling, please add a feature
36+
37+
```toml
38+
[dependencies]
39+
my-postgres = { tag = "xxx", git = "https://github.com/MyJetTools/my-postgres.git", features = [
40+
"with-ssh",
41+
] }
42+
```
43+
44+
It is possible to connect to a PostgreSQL database through an SSH tunnel by adding the `ssh` parameter to the connection string. The format is `ssh=user@sshhost:22` where:
45+
- `user` is the SSH username
46+
- `sshhost` is the SSH server hostname or IP address
47+
- `22` is the SSH port (default is 22)
48+
49+
Example connection string with SSH tunneling:
50+
51+
```
52+
host=xxx port=5432 dbname=xxx user=xxx password=xxx ssh=user@sshhost:22
53+
```
54+
55+
The SSH tunnel will be established automatically, and the connection to PostgreSQL will be routed through it.
3256

3357
### Application name
3458

my-postgres-core/src/connection/postgres_connect_inner.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,45 @@ impl PostgresConnectionInner {
477477
Ok(())
478478
}
479479

480+
fn is_non_retryable_postgres_error(err: &tokio_postgres::Error) -> bool {
481+
if let Some(state) = err.code() {
482+
let code = state.code();
483+
if code == "42P01" // undefined_table (relation does not exist)
484+
|| code == "3D000" // invalid_catalog_name (database does not exist)
485+
|| code == "28P01" // invalid_authorization_specification (invalid password)
486+
|| code == "42704" // undefined_object (object does not exist)
487+
|| code == "42601" // syntax_error (SQL syntax error)
488+
|| code == "42501" // insufficient_privilege (permission denied)
489+
|| code == "42703" // undefined_column (column does not exist)
490+
|| code == "42883" // undefined_function (function does not exist)
491+
|| code == "23502" // not_null_violation (NOT NULL constraint violation)
492+
|| code == "23503" // foreign_key_violation (foreign key constraint violation)
493+
|| code == "23505" // unique_violation (unique constraint violation)
494+
|| code == "22001" // string_data_right_truncation (string too long for column)
495+
|| code == "22003" // numeric_value_out_of_range (numeric value out of range)
496+
|| code == "22007" // invalid_datetime_format (invalid date/time format)
497+
|| code == "22008" // datetime_field_overflow (date/time field out of range)
498+
|| code == "22012"
499+
// division_by_zero (division by zero)
500+
{
501+
return true;
502+
}
503+
}
504+
false
505+
}
506+
480507
fn handle_error(
481508
&self,
482509
err: MyPostgresError,
483510
ctx: &crate::RequestContext,
484511
) -> Result<(), MyPostgresError> {
512+
// Check if this is a non-retryable PostgresError and return immediately
513+
if let MyPostgresError::PostgresError(ref postgres_err) = &err {
514+
if Self::is_non_retryable_postgres_error(postgres_err) {
515+
return Err(err);
516+
}
517+
}
518+
485519
match &err {
486520
MyPostgresError::NoConnection => {}
487521
MyPostgresError::SingleRowRequestReturnedMultipleRows(_) => {}

my-postgres-macros/src/attributes/where_operator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub enum WhereOperator {
1818
NotEqual2,
1919
#[value("like")]
2020
Like,
21+
#[value("not")]
22+
Not,
2123
}
2224

2325
impl WhereOperator {
@@ -31,6 +33,7 @@ impl WhereOperator {
3133
Self::NotEqual => "!=",
3234
Self::NotEqual2 => "<>",
3335
Self::Like => " like ",
36+
Self::Not => " not ",
3437
}
3538
}
3639
}

0 commit comments

Comments
 (0)