How can I get esqueleto to generate an SQL string from a from
statement?
The documentation of toRawSql
says that "you may just turn on query logging of persistent". I tried all possible forms of MonadLogger
that I could understand, but it never printed any SQL. The same documentation also says "manually using this function ... is possible but tedious". However, no constructors of the type, nor any functions returning values of the type, QueryType
are exported. I managed to get around this by noticing that QueryType
is a newtype
and using unsafeCoerce
!
I was also forced to provide a Connection
(which I got via SQLite) even though there should be no need to connect to a database to generate the SQL.
This is what I've got. There must be a better way.
withSqliteConn ":memory:" $
\conn -> return $ toRawSql SELECT
(unsafeCoerce ((const mempty)
:: a -> Text.Lazy.Builder.Builder))
(conn, initialIdentState) myFromStatement)
http://hackage.haskell.org/package/esqueleto-1.3.4.2/docs/Database-Esqueleto-Internal-Sql.html