vapor / postgres-nio

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
https://api.vapor.codes/postgresnio/documentation/postgresnio/
MIT License
319 stars 72 forks source link

Connection metadata #100

Open tanner0101 opened 5 years ago

tanner0101 commented 5 years ago

Currently, the FluentPostgreSQL integration needs to check PSQL version during boot time. This happens here.

This check requires a known, static database identifier to create a new connection. This makes supporting multiple Postgres databases with possibly different versions difficult / impossible.

Ideally this package would provide a better way to check active Postgres version. I believe this is sent during startup, so it could be stored and accessed on individual connections without the need for any extra queries.

gperdomor commented 5 years ago

in the fluent-postgresql PR that line is updated to use the custom identifier

tanner0101 commented 5 years ago

@gperdomor the problem with that is it's still limited to at max one Postgres database. This package ostensibly supports working with multiple DBs with potentially different versions of Postgres running. We need a solution that solves both of these problems.

gperdomor commented 5 years ago

I use two database with this solution soñé time ago, but in that case was the same postgres version (postgres:10-alpine)

tanner0101 commented 5 years ago

Upon further investigation, it appears that the connection status returned by Postgres does indeed contain the server version:

["IntervalStyle": "postgres", "application_name": "", "DateStyle": "ISO, MDY", "is_superuser": "on", "standard_conforming_strings": "on", "server_encoding": "UTF8", "integer_datetimes": "on", "session_authorization": "vapor_username", "client_encoding": "UTF8", "server_version": "10.5 (Debian 10.5-2.pgdg90+1)", "TimeZone": "UTC"]

Grabbing this value from the connection directly instead of using a global seems like the right approach going forward.