As seen here, it is possible to use PyQGIS to load layers from PostgreSQL using an instance of QgsDataSourceUri(). You then set the connection and load a layer.
uri = QgsDataSourceUri() uri.setConnection("localhost", "5432", "myBase", "myUser", "myPassword")
In QGIS our users will have standardized named connections in the QGIS data browser, something along the lines of 'GIS-DATA' to connect to the GIS database etc. Is there a way to leverage using something like the following to avoid having to parse out all of the parameters each time?
uri = QgsDataSourceUri() uri.setConnection("GIS-DATA")
Using named connections seems to be possible in Processing Algorithms (ex- see the PostgreSQL Execute and Load SQL tool, it has a parameter for 'connection name'). https://docs.qgis.org/3.28/en/docs/user_manual/processing_algs/qgis/database.html#export-to-postgresql
Is there a way to access this connection to add and load layers?