How to empty a table in Esqueleto.Experimental without where_ clause

28 views
Skip to first unread message

kees Bleijenberg

unread,
Apr 10, 2023, 2:28:23 PM4/10/23
to Yesod Web Framework
{-# TypeApplications #-}
import qualified Database.Esqueleto.Experimental as E

myHandler:: Text -> Handler Value
myHandler t = do
runDB $ E.delete $ do
v <- E.from $ E.Table @Vogel
???
retun a Value

The persistmodel for the table Vogel is
Vogel
naam     Text
deriving Show



Jakob Schöttl

unread,
Apr 10, 2023, 3:59:31 PM4/10/23
to yeso...@googlegroups.com, kees Bleijenberg

Does that help? I asket ChatGPT ^^ I don't know Esqueleto though.

If you want to delete all the rows from a table using Esqueleto.Experimental, you can use the E.delete function without any WHERE clause. Here's an example:

haskell
import qualified Database.Esqueleto.Experimental as E myHandler :: Handler Value myHandler = do runDB $ E.delete $ E.from $ E.Table @Vogel return someValue

In the example above, the E.delete function is called with a query that selects all rows from the Vogel table using the E.from function. The E.Table function is used to indicate the table name explicitly. Since there is no WHERE clause, all rows in the table will be deleted.

Am 10.04.23 um 20:28 schrieb kees Bleijenberg:
--
You received this message because you are subscribed to the Google Groups "Yesod Web Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yesodweb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/yesodweb/c351b6ef-c612-4f23-b091-82e037d0f16cn%40googlegroups.com.

kees Bleijenberg

unread,
Apr 11, 2023, 4:34:47 AM4/11/23
to Yesod Web Framework
I tried your solution in this code:
myHandler :: Handler Value 
myHandler  = do 
      runDB $ E.delete $ E.from $ E.table @Vogel  -- I get a warning when I use E.Table
      return $ object [("errMsg","")]

and I got an error message about E.from:
Couldn't match type `E.SqlExpr( Entity Vogel)' with '()'
     arising from a functional dependency between:
      constraint 'Database.Esqueleto.Experimental.From.ToFrom  
          (E.From (E.SqlExpr (Entity Vogel))) ()'
          arising from a use of 'E.from'
     instance 'Database.Esqueleto.Experimental.From.ToFrom (E.From a) a'
          at <no location info>
          ....... 
Reply all
Reply to author
Forward
0 new messages