{"action":"created","issue":{"url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/205","repository_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye","labels_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/205/labels{/name}","comments_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/205/comments","events_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/205/events","html_url":"https://github.com/tomjaguarpaw/haskell-opaleye/issues/205","id":176206261,"number":205,"title":"Request for docs: How to runUpdate with records?","user":{"login":"saurabhnanda","id":28369,"avatar_url":"https://avatars.githubusercontent.com/u/28369?v=3","gravatar_id":"","url":"https://api.github.com/users/saurabhnanda","html_url":"https://github.com/saurabhnanda","followers_url":"https://api.github.com/users/saurabhnanda/followers","following_url":"https://api.github.com/users/saurabhnanda/following{/other_user}","gists_url":"https://api.github.com/users/saurabhnanda/gists{/gist_id}","starred_url":"https://api.github.com/users/saurabhnanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saurabhnanda/subscriptions","organizations_url":"https://api.github.com/users/saurabhnanda/orgs","repos_url":"https://api.github.com/users/saurabhnanda/repos","events_url":"https://api.github.com/users/saurabhnanda/events{/privacy}","received_events_url":"https://api.github.com/users/saurabhnanda/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-09-10T22:07:47Z","updated_at":"2016-09-12T17:08:10Z","closed_at":null,"body":"I'm not able to figure out how to do a `runUpdate` given the following record-types:\r\n\r\n```\r\ndata TenantPoly key createdAt updatedAt name status ownerId backofficeDomain = Tenant {\r\n  tenantKey :: key\r\n  ,tenantCreatedAt :: createdAt\r\n  ,tenantUpdatedAt :: updatedAt\r\n  ,tenantName :: name\r\n  ,tenantStatus :: status\r\n  ,tenantOwnerId :: ownerId\r\n  ,tenantBackofficeDomain :: backofficeDomain\r\n  }\r\n\r\ntype TenantPGWrite = TenantPoly\r\n  (Maybe (Column PGInt8)) -- key\r\n  (Maybe (Column PGTimestamptz)) -- createdAt\r\n  (Maybe (Column PGTimestamptz)) -- updatedAt\r\n  (Column PGText) -- name\r\n  (Column PGText) -- status\r\n  (Column (Nullable PGInt8)) -- ownerId\r\n  (Column PGText) -- backofficeDomain\r\n\r\ntype TenantPGRead = TenantPoly\r\n  (Column PGInt8) -- key\r\n  (Column PGTimestamptz) -- createdAt\r\n  (Column PGTimestamptz) -- updatedAt\r\n  (Column PGText) -- name\r\n  (Column PGText) -- status\r\n  (Column (Nullable PGInt8)) -- ownerId\r\n  (Column PGText) -- backofficeDomain\r\n```\r\n\r\n**How do I make the following function type-check?**\r\n\r\n```\r\nactivateTenant :: TenantId -> AppM (Tenant)\r\nactivateTenant tenantId@(TenantId tid) = do\r\n  conn <- askDbConnection\r\n  liftIO $ do \r\n    _ <- runUpdate conn tenantTable\r\n      (\\tenant -> tenant & status .~ TenantActive) -- ERROR: Couldn't match type ‘Column PGInt8’ with ‘Maybe (Column PGInt8)’\r\n      (\\tenant -> (tenant ^. key .== pgInt8 tid))\r\n    head <$> runQuery conn (tenantById tenantId)\r\n```\r\n\r\nIf I understand the type error correctly, it's expecting that lambda to return a `TenantPGWrite`, where `key`, `createdAt`, `updatedAt` are Maybes. Does that mean I need to transform the entire row from `TenantPGRead` to `TenantPGWrite` for a simple update?\r\n\r\nAlso, it's not clear from the type signature and [docs for `runUpdate`](https://www.stackage.org/haddock/lts-6.12/opaleye-0.4.2.0/Opaleye-Manipulation.html#v:runUpdate) what the resulting `Int64` represents. Is it the number of records updated?"},"comment":{"url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/comments/246417597","html_url":"https://github.com/tomjaguarpaw/haskell-opaleye/issues/205#issuecomment-246417597","issue_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/205","id":246417597,"user":{"login":"saurabhnanda","id":28369,"avatar_url":"https://avatars.githubusercontent.com/u/28369?v=3","gravatar_id":"","url":"https://api.github.com/users/saurabhnanda","html_url":"https://github.com/saurabhnanda","followers_url":"https://api.github.com/users/saurabhnanda/followers","following_url":"https://api.github.com/users/saurabhnanda/following{/other_user}","gists_url":"https://api.github.com/users/saurabhnanda/gists{/gist_id}","starred_url":"https://api.github.com/users/saurabhnanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saurabhnanda/subscriptions","organizations_url":"https://api.github.com/users/saurabhnanda/orgs","repos_url":"https://api.github.com/users/saurabhnanda/repos","events_url":"https://api.github.com/users/saurabhnanda/events{/privacy}","received_events_url":"https://api.github.com/users/saurabhnanda/received_events","type":"User","site_admin":false},"created_at":"2016-09-12T17:08:10Z","updated_at":"2016-09-12T17:08:10Z","body":"It's not about **typesafe** per-se, it's about dealing with only **specific columns** and not the entire row. Else, one has to resort to raw SQL, which is not typesafe."}}
{"actor":{"display_login":"saurabhnanda"}}