You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Accept connecting with PostgreSQL URLs instead of connection strings #2090
This is how Heroku provides access to its databases, and due the fact the values can (will?) change without announcement, it becomes quite cumbersome to manage it to the current "key value" format.
If you guys think it's a good idea, I would be happy to submit a PR to enhance the NpgsqlConnectionStringBuilder class.
Thanks!
Reacted by Austin Drenski, Yoh Deadfall, Luis Ferrao, Jonathan Gilchrist, Jonathan Allen, Richard Holland, Andrew Backer, akublickij, Richard Hagen, Samuel Carswell and 5 more
I really like this idea. Maintaining different connection strings for tools like psql/Rider/DataGrip and Npgsql/EF Core can be a real pain.
There are probably some ADO.NET requirements to consider, but there are examples where Npgsql-specific APIs are implemented because the standard was insufficient.
However, we should avoid having a constructor that accepts URIs, for perf reasons... The pool manager keys by string, which would mean that every (pooled) connection open has to do Uri.ToString() - not ideal. At some point there was a constructor that accepted an instance of NpgsqlConnectionStringBuilder and it encouraged bad perf behavior so it was removed.
I think this issue is more a matter of detecting URIs and then internally constructing instances of NpgsqlConnectionStringBuilder from them, it shouldn't be too hard...
At the moment you can only set connection strings on a connection with a simple string. The first time a string is seen, it's parsed into an NpgsqlConnectionStringBuilder (this is an expensive one-time operation), which is then cached in the pool. The next time the string is found by the pool manager, and the cached parsed NpgsqlConnectionStringBuilder is reused. I think we should stick to this model which is very efficient, and only change the one-time parsing process to support URIs.
I think this issue is more a matter of detecting URIs and then internally constructing instances of NpgsqlConnectionStringBuilder from them, it shouldn't be too hard...
Do we need to support anything other than postgresql://?
Uri.ToString returns the original string when it doesn't contain Unicode characters.
Hmm, OK, so maybe it's not a problem. I still don't see great value in a constructor accepting a Uri (the user can just do ToString() themselves) but as long as it's OK for perf I'm not really against it either...
I'm not sure about the specific implementation details, but ideally the URI handling logic would be handled outside NpgsqlStringConnectionBuilder, to keep that class concerned with what DbStringConnectionBuilders usually do. However, if a URI is detected, an instance of NpgsqlConnectionStringBuilder would be constructed and used internally to hold all the parsed configuration options, just as it is done today.
Note that accessing NpgsqlConnection.ConnectionString should still provide the connection string as a URI, and ideally we'd also elide the password after connection open just like we do today.
I have to say I have no experience yet contributing to open source projects. I'm excited about finally having a chance to help, but probably I won't get it right in a first trial.
So, if you guys don't mind a bit of back and forth during the PR review, I'm glad in doing it. Otherwise, I don't mind leaving this to someone with more experience.
@pedrowindisch please take a look at the earlier two PRs. This isn't a trivial thing to implement, and requires quite a bit of effort and design thinking; we spent time reviewing the previous two PRs, but unfortunately they were abandoned by their original authors. So while we welcome contributions, please only start working on this if you're determined to carry it through (also keep in mind that we may not have time to review right away, so this make take a while).
Otherwise, if you're looking for something to contribute, there are probably smaller work items that may be a better fit.
changed the title [-]Accept URI format as valid connection string[/-][+]Accept connecting with PostgreSQL URLs instead of connection strings[/+]on Nov 17, 2024
Activity
austindrenski commentedon Aug 2, 2018
I really like this idea. Maintaining different connection strings for tools like psql/Rider/DataGrip and Npgsql/EF Core can be a real pain.
There are probably some ADO.NET requirements to consider, but there are examples where Npgsql-specific APIs are implemented because the standard was insufficient.
Related
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-strings
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax
YohDeadfall commentedon Aug 2, 2018
Makes sense, but I would like to discuss the design first here. I think there should be a constructor which accepts
Urias a parameter.austindrenski commentedon Aug 2, 2018
@YohDeadfall Then parse
Uriinto the current connection string format?Parsing with
Span<T>could help limit the overhead of theUriconstructor vs the standard constructor.roji commentedon Aug 2, 2018
I don't see any reason not to support this...
However, we should avoid having a constructor that accepts URIs, for perf reasons... The pool manager keys by string, which would mean that every (pooled) connection open has to do
Uri.ToString()- not ideal. At some point there was a constructor that accepted an instance ofNpgsqlConnectionStringBuilderand it encouraged bad perf behavior so it was removed.I think this issue is more a matter of detecting URIs and then internally constructing instances of
NpgsqlConnectionStringBuilderfrom them, it shouldn't be too hard...roji commentedon Aug 2, 2018
Another note on perf...
At the moment you can only set connection strings on a connection with a simple string. The first time a string is seen, it's parsed into an
NpgsqlConnectionStringBuilder(this is an expensive one-time operation), which is then cached in the pool. The next time the string is found by the pool manager, and the cached parsedNpgsqlConnectionStringBuilderis reused. I think we should stick to this model which is very efficient, and only change the one-time parsing process to support URIs.YohDeadfall commentedon Aug 2, 2018
Uri.ToStringreturns the original string when it doesn't contain Unicode characters.austindrenski commentedon Aug 2, 2018
Do we need to support anything other than
postgresql://?roji commentedon Aug 2, 2018
Hmm, OK, so maybe it's not a problem. I still don't see great value in a constructor accepting a
Uri(the user can just doToString()themselves) but as long as it's OK for perf I'm not really against it either...roji commentedon Aug 2, 2018
I don't think so - we should aim to support the URIs as described in the PostgreSQL docs.
Note that for now we don't support multiple hosts or ports, although there's a PR pending for that.
luizs81 commentedon Aug 3, 2018
@YohDeadfall
I believe we could use
Uri.TryCreateto detect whenever the argument is a Uri or not, and then proceed accordingly.YohDeadfall commentedon Aug 3, 2018
@roji @luizs81 Does it mean that the existing string builder constructor will take a string and check that it's possible to construct an
Urifrom it?roji commentedon Aug 4, 2018
I'm not sure about the specific implementation details, but ideally the URI handling logic would be handled outside
NpgsqlStringConnectionBuilder, to keep that class concerned with whatDbStringConnectionBuilders usually do. However, if a URI is detected, an instance ofNpgsqlConnectionStringBuilderwould be constructed and used internally to hold all the parsed configuration options, just as it is done today.Note that accessing
NpgsqlConnection.ConnectionStringshould still provide the connection string as a URI, and ideally we'd also elide the password after connection open just like we do today.YohDeadfall commentedon Aug 4, 2018
I like the idea.
@luizs81 Would you like to implement it?
luizs81 commentedon Aug 7, 2018
@YohDeadfall
I have to say I have no experience yet contributing to open source projects. I'm excited about finally having a chance to help, but probably I won't get it right in a first trial.
So, if you guys don't mind a bit of back and forth during the PR review, I'm glad in doing it. Otherwise, I don't mind leaving this to someone with more experience.
YohDeadfall commentedon Aug 7, 2018
@luizs81 It's fine to change the code based on the feedback. So feel free to open a pull request, and we will help you (:
luizs81 commentedon Aug 7, 2018
Cool!
I will be working on that soon and hopefully open the PR in the following days.
bezchristo commentedon Jun 14, 2019
@luizs81, @YohDeadfall Was there ever a PR created for this?
YohDeadfall commentedon Jun 14, 2019
No one has opened a PR, so it's still up for grabs.
jgilchrist commentedon Jul 7, 2019
@YohDeadfall I've filed a early WIP (#2512) - it would be great to get your thoughts on the approach!
pedrowindisch commentedon Mar 25, 2024
It seems like this issue is still up for grabs. I'd like to start working on it if possible. =)
Since this issue has been inactive for some time, I'd like to know if there is something to be aware of before starting working on it.
Or can I just go ahead and start implementing the connection URI support?
Thanks!
roji commentedon Mar 26, 2024
@pedrowindisch please take a look at the earlier two PRs. This isn't a trivial thing to implement, and requires quite a bit of effort and design thinking; we spent time reviewing the previous two PRs, but unfortunately they were abandoned by their original authors. So while we welcome contributions, please only start working on this if you're determined to carry it through (also keep in mind that we may not have time to review right away, so this make take a while).
Otherwise, if you're looking for something to contribute, there are probably smaller work items that may be a better fit.
[-]Accept URI format as valid connection string[/-][+]Accept connecting with PostgreSQL URLs instead of connection strings[/+]