{"action":"created","issue":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/71","labels_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/71/comments","events_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/71/events","html_url":"https://github.com/vitaly-t/pg-promise/issues/71","id":120065567,"number":71,"title":"Setting GUC at the beginning of each query with shared connections using Koa","user":{"login":"jmealo","id":1066536,"avatar_url":"https://avatars.githubusercontent.com/u/1066536?v=3","gravatar_id":"","url":"https://api.github.com/users/jmealo","html_url":"https://github.com/jmealo","followers_url":"https://api.github.com/users/jmealo/followers","following_url":"https://api.github.com/users/jmealo/following{/other_user}","gists_url":"https://api.github.com/users/jmealo/gists{/gist_id}","starred_url":"https://api.github.com/users/jmealo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmealo/subscriptions","organizations_url":"https://api.github.com/users/jmealo/orgs","repos_url":"https://api.github.com/users/jmealo/repos","events_url":"https://api.github.com/users/jmealo/events{/privacy}","received_events_url":"https://api.github.com/users/jmealo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/vitaly-t/pg-promise/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-12-03T00:18:03Z","updated_at":"2015-12-03T19:24:08Z","closed_at":null,"body":"Hello,\r\n\r\nI have three use cases that require setting GUCs at the beginning of each query.\r\n\r\n1. To enable end-to-end logging of a request to our web application, NGINX generates a request id and passes it to upstream proxies. By abusing the ``application_name`` GUC which can be written to the PostgreSQL log file we can aggregate syslog entries for all parts of our stack.\r\n\r\n2. To access the web application user for use with row-level security.\r\n\r\n3. To access the web application user for audit logging.\r\n\r\nI realize that you can use the ``query`` event notification to modify the query, however, this doesn't cover my use case and nearly anyway to monkey patch this into the library has been locked out by marking properties as read only.\r\n\r\nI'm using koa and each request context is decorated with a ``pgp`` property which allows me to execute queries and a ``session`` property which contains the user's ``user_id`` and ``request_id``.\r\n\r\nI would need a way to access the session or koa context from my ``query`` event handler.\r\n\r\nHow would you recommend going about this and is this a use case that you plan on supporting?\r\n\r\nI'm trying to avoid forking the code to do something I expect will be common place once a few tutorials pop up on abusing GUC to do RLS.\r\n\r\nThanks,\r\nJeff"},"comment":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/comments/161753752","html_url":"https://github.com/vitaly-t/pg-promise/issues/71#issuecomment-161753752","issue_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/71","id":161753752,"user":{"login":"jmealo","id":1066536,"avatar_url":"https://avatars.githubusercontent.com/u/1066536?v=3","gravatar_id":"","url":"https://api.github.com/users/jmealo","html_url":"https://github.com/jmealo","followers_url":"https://api.github.com/users/jmealo/followers","following_url":"https://api.github.com/users/jmealo/following{/other_user}","gists_url":"https://api.github.com/users/jmealo/gists{/gist_id}","starred_url":"https://api.github.com/users/jmealo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmealo/subscriptions","organizations_url":"https://api.github.com/users/jmealo/orgs","repos_url":"https://api.github.com/users/jmealo/repos","events_url":"https://api.github.com/users/jmealo/events{/privacy}","received_events_url":"https://api.github.com/users/jmealo/received_events","type":"User","site_admin":false},"created_at":"2015-12-03T19:24:08Z","updated_at":"2015-12-03T19:24:08Z","body":"@vitaly-t I thought that you can only ``extend`` pgp once and only through the constructor?"}}