[web-devel] Esqueleto : SELECT COUNT(*) FROM table_name ;

Erik de Castro Lopo mle+hs at mega-nerd.com
Fri Nov 23 23:06:22 CET 2012


Felipe Almeida Lessa wrote:

> You may just return countRows as Gaël said.  However, there's a catch:
> GHC won't have enough information to typecheck the code and infer
> which table you're talking about.  You'll probably need something such
> as:
> 
>   count <-
>     select $
>     from \(foo :: SqlExpr (Entity Foo)) ->
>     return countRows
> 
> Alternatively, you could constraint the type via an unused expression:
> 
>   count <-
>     select $
>     from \foo ->
>     let _ = foo ^. FooId -- constraint the type of foo
>     return countRows
> 
> Both code snippets are untested.  Have fun =).

There are still some problems typing all these and they all still return
a list instead of a value whereas the SQL statement returns a single value.

Looks like I'll need to dig into the Esqueleto sources.

Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/



More information about the web-devel mailing list