Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about mkHsI #3

Closed
commandodev opened this issue May 3, 2016 · 3 comments
Closed

Question about mkHsI #3

commandodev opened this issue May 3, 2016 · 3 comments

Comments

@commandodev
Copy link

Hi,

I like the new API, seem a lot more straightforward!

I'm looking at the writing side of things now, but I'm unsure what columns I need to supply for the mkHsI function. I assumed it's just the 'W columns, with the 'WD columns being optional so given

data TTodoItem
instance Tabla TTodoItem where
  type Database TTodoItem = TodoDb
  type SchemaName TTodoItem = "todo"
  type TableName TTodoItem = "todo_item"
  type Cols TTodoItem =
    [ 'Col "id" 'WD 'R O.PGUuid TodoItemId
    , 'Col "title" 'W 'R O.PGText Text
    , 'Col "created" 'WD 'R O.PGTimestamptz UTCTime
    , 'Col "due" 'WD 'RN O.PGTimestamptz UTCTime
    , 'Col "completed" 'WD 'RN O.PGTimestamptz UTCTime
    ]

I had expected this:

mkHsI (T :: T TTodoItem) $ \set_ -> hBuild
    (set_ (C :: C "title") t) -- t :: Text
    (set_ (C :: C "due") mDue) -- mDue :: (Maybe UTCTime)

to be sufficient.

However I get:

    Couldn't match type '[y,
                           Tagged (TC TTodoItem "due") (Maybe UTCTime),
                           Tagged (TC TTodoItem "title") Text]
                   with '[]
    arising from a functional dependency between:
      constraint HRevApp
                    '[]
                    '[Tagged (TC TTodoItem "due") (Maybe UTCTime),
                      Tagged (TC TTodoItem "title") Text, y,
                      Tagged (TC TTodoItem "due") (Maybe UTCTime),
                      Tagged (TC TTodoItem "title") Text]
                    '[Tagged (TC TTodoItem "due") (Maybe UTCTime),
                      Tagged (TC TTodoItem "title") Text]
        arising from a use of hBuild
      instance HRevApp '[] l2 l2 at <no location info>
    In the expression:
      hBuild (set_ (C :: C "title") t) (set_ (C :: C "due") mDue)
    In the second argument of ($), namely
      ‘\ set_
         -> hBuild (set_ (C :: C "title") t) (set_ (C :: C "due") mDue)
    In the expression:
      mkHsI (T :: T TTodoItem)
      $ \ set_
          -> hBuild (set_ (C :: C "title") t) (set_ (C :: C "due") mDue)

I haven't been able to work my way through the types to understand what this is telling me yet.

Cheers!

@commandodev
Copy link
Author

Actually just writing this down seems to have fixed it :-)

mkHsI (T :: T TTodoItem) $ \set_ -> hBuild
    (set_ (C :: C "id") WDef)
    (set_ (C :: C "title") t)
    (set_ (C :: C "created") WDef)
    (set_ (C :: C "due") (WVal mDue))
    (set_ (C :: C "completed") WDef)

Maybe just a note in the docs about how to structure this?

@k0001
Copy link
Owner

k0001 commented May 3, 2016

I suspect it is reasonable to expect that the "defaultable" columns can be
left blank here. 'hBuild' doesn't work that way, but maybe some other
function can be written that sets those defaults to 'WDef'. I am not sure
if that is good, though, being explicit should make things less error
prone. I'll see if this can be written.

In any case: yes, docs are still missing about this.
On May 3, 2016 2:56 AM, "Ben Ford" notifications@github.com wrote:

Actually just writing this down seems to have fixed it :-)

mkHsI (T :: T TTodoItem) $ \set_ -> hBuild
(set_ (C :: C "id") WDef)
(set_ (C :: C "title") t)
(set_ (C :: C "created") WDef)
(set_ (C :: C "due") (WVal mDue))
(set_ (C :: C "completed") WDef)

Maybe just a note in the docs about how to structure this?


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#3 (comment)

@k0001
Copy link
Owner

k0001 commented Aug 1, 2016

This API changed https://github.com/k0001/opaleye-sot/blob/6237966fe981caefed65d346ba2b374f456e46ac/src/lib/Opaleye/SOT/Internal.hs#L837-L897

By the way, the code is now compatible with GHC 8, and support for GHC 7.10.x has been dropped.

@k0001 k0001 closed this as completed Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants