-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(postgres): add an option to specify extra options #1539
Conversation
The
I would prefer if the interface was something like: pub fn options<K, V, I>(self, options: I) -> Self
where
K: ToString,
V: ToString,
I: IntoIterator<Item = (K, V)>,
{
// ...
} As for the URL format, how about something like |
Sorry, is this in SQLx or in the PostgreSQL? So if we don't use
I see. I will convert the code to do that.
This is per https://www.postgresql.org/docs/13/libpq-connect.html#LIBPQ-CONNSTRING. PostgreSQL specified that the client should encode the URL like this. The same applies to the |
This is in Postgres (scroll down to The options can be passed directly as extra key-value pairs in the
We're really not beholden to that besides making an attempt to support the same connection string options as
What my ideal would be is to support both formats, both the
In that case, it doesn't really make sense to try to parse the |
Sorry, I didn't research enough, and you are right. I will attempt to adapt the code to your suggestions. |
I have adapted the code to @abonander 's suggestions. However, I am having difficulties coming up with a more robust In addition, I feel like the |
@liushuyu sorry my last message was probably pretty confusing, I was thinking out loud. If we want to support So go ahead and go back to what you were doing, although I would keep the change to the |
Ah, I see. I will make these changes. |
I have adapted the code to the latest suggestions. There are rough edges in the command formatting where I think I need to observe the handling of certain edge-cases by |
Thank you for reviewing my changes. I have rebased my branch and fixed the formatting. |
Is there anything left to do to get this pull request approved and merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few nits left.
... this allow you to specify stuff like search path and statement timeouts etc.
Thank you for the suggestions. Comments addressed and commits rebased. |
{ | ||
let mut options_str = String::new(); | ||
for (k, v) in options { | ||
options_str += &format!("-c {}={}", k, v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to have a bug where if multiple options are provided the -c
is tacked onto the previous one. This can be worked around by adding the space manually.
.options([
("default_transaction_isolation", "serializable "),
("idle_in_transaction_session_timeout", "5min "),
("statement_timeout", "2s"),
]);
Or by calling this multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug filed: #1730
This Pull Request allows you to specify extra command options to the PostgreSQL server through connection options like search path and statement timeouts etc.
This could fix #1290.