to have a reusable function to truncate tables for testing. However, I run into the error syntax error at or near \"'users'\. I suspect that postgres-simple adds '' to parameters, which makes sense for rows but tables should not be quoted. Is there any way to pass a non-quoted parameter?
Looks good, but Identifier doesn’t seem to have a ToRow instance. Which makes sense to me but that is the parameter required by execute. I changed it to
truncateTable :: Text -> (Ctx, a) -> IO ()
truncateTable text (ctx, _) = do
_ <-
Database.execute ctx.connection [sql| TRUNCATE TABLE ? |] (Identifier (text))
return ()
And I got the error that No instance for ‘Database.ToRow Identifier’
In order to pass a single parameter you can wrap it in Only. Only has ToRow/FromRow instances provided the wrapped type has ToField/FromField instances.