From: Justin B. <jgb...@gm...> - 2009-09-29 15:30:26
|
The generated module is what I wanted. Here is your table definition: > type ImageTable = > (RecCons IndexNumber (Expr Integer) > (RecCons Caption (Expr String) > (RecCons Thumbnail (Expr String) > (RecCons Preview (Expr String) > (RecCons Original (Expr (Maybe String)) > (RecCons UploadTime (Expr CalendarTime) RecNil)))))) Specifically, UploadTime is of tyep "CalendarTime". The error you got was: > ct <- getCurrentTime > DB.insert db IT.imageTable (<snip> # IT.uploadTime <<- ct) > > the compiler complains: > > Couldn't match expected type `System.Time.CalendarTime' > against inferred type `UTCTime' > In the second argument of `(<<-)', namely `ct' > In the second argument of `(#)', namely `IT.uploadTime <<- ct' The solution is to make "ct" have type CalendarTime, not UTCTime. HaskellDB uses the deprecated, but still in wide use, old-time package which exposes System.Time.CalendarTime. You can't get a CalendarTime for the current date direclty, but you can indirectly. Try: clockTime <- getClockTime ct <- toCalendarTime clockTime Or more succinctly: ct <- getClockTime >>= toCalendarTime Then you should be able to do your insert. Finally, you asked: > How do I control this with a signature? That's not relevant here as I was referring to the conversion of SQL types to Haskell values. Since DBDirect generates the code for your table, you are stuck with CalendarTime. DBDirect is just a convenience, though. You could make your own definition by hand. There is also the haskelldb-th package, which gives some Template Haskell functions for defining tables and columns. Just FYI. Justin |