From: Bjorn B. <bj...@br...> - 2008-04-04 16:13:45
|
On Fri, Apr 4, 2008 at 5:51 PM, Justin Bailey <jgb...@gm...> wrote: > On Fri, Apr 4, 2008 at 8:28 AM, Bjorn Bringert <bj...@br...> wrote: > > this looks great. How do you substitute in values for parameters in queries? > > That's something I didn't look at, but is needed. Since I'm using > haskelldb just to generate SQL I haven't concentrated on the runtime > side. However, see below .. > > > > Here, prepare and queryBind are something along these lines (but more > > general to support multiple arguments, and with some type class > > constraints): > > > > prepare :: Database -> (a -> Query (Rel b)) -> PreparedQuery (a -> Rel b) > > > > queryBind :: Database -> PreparedQuery (a -> Rel b) -> a -> IO [b] > > I like this, and I wonder if Peter's code (mentioned in another > thread) addresses it. I'd be glad to take a shot at unifying the two > approaches, once his patch is in. > > In any case, do you think the parameters should show up in the type of > Query (Rel b)? Any ideas how that could look, and how to make sure > queries can still be rendered to SQL w/o runtime values (so I can > still get my SQL w/o having to execute it)? Hmm, I'm not sure that the Query should have the parameters in it, since a Query is different from a PreparedQuery. To render a parametrized query as SQL, you could have a function (needs a better name): showParamSql :: (a -> Query (Rel b)) -> String This would have to invent names for the parameters, so it needs some trickery inside. Or maybe, forcing you to supply a name for each parameter: showParamSql :: (a -> Query (Rel b)) -> String -> String (All of the above needs to be extended with type-trickery to handle multiple parameters) /Björn |