On Fri, Apr 4, 2008 at 10:20 PM, Justin Bailey <jgb...@gm...> wrote:
> I just spent most of the day creating some TH functions that generate
> DirectDB style table and field definitions. It allows me to create a
> module that exports a table like so:
>
> module My_Table where
>
> $(mkDBDirectTable "my_table"
> [("event_dtl_id", [t|Int|])
> , ("event_hdr_id", [t|Int|])
> , ("foo", [t|Int|])
> , ("bar", [t|Int|])])
>
> The above is a table name and a list of fields with types. TH
> generates appropriate haskell source so the definition looks just
> something DBDirect would produce:
>
> module My_Table where
>
> type My_table =
> (RecCons Pts_dlvry_carrier_flight_id (Expr Int)
> (RecCons Pts_dlvry_carrier_id (Expr Int) ...))
>
> my_table :: Table My_table
> my_table = baseTable "my_table" $
> hdbMakeEntry Event_dtl_id # ...
>
> data Event_dtl_id = Event_dtl_id
>
> instance FieldTag Event_dtl_id where
> fieldName _ = "event_dtl_id"
>
> event_dtl_id :: Attr Event_dtl_id
> event_dtl_id = mkAttr Event_dtl_id
> ....
>
> I also have a function that creates a field using TH, which is very
> useful when you need "fake" fields in a projection:
>
> $(mkDBDirectField "filtered" [t|Bool|])
>
> which produces something like:
>
> data Filtered = Filtered
>
> instance FieldTag Filtered where
> fieldName _ = "filtered"
>
> filtered :: Attr Filtered
> filtered = mkAttr Filtered
>
> Is there a place in the haskelldb source for TH utilities like this?
>
> Justin
Nice! I seem to recall there being such code somewhere in the past,
but I have no idea where.
I should probably go in a separate cabal package, since it adds a dep
on TH. Maybe add a haskelldb-th dir in the repo and put the code +
.cabal there.
I should move the repo to code.haskell.org to remove me as a
bottleneck for your work.
/Bjorn
|