1 -- | Standalone database functions for dealing with Groundhog types.
3 module TSN.Database ( insert_or_select )
6 import Database.Groundhog ( AutoKey, insertByAll )
7 import Database.Groundhog.Core ( PersistBackend, PersistEntity )
10 -- | Attempt to insert the given object returning its new primary
11 -- key. If any unique constraints would be violated, instead return
12 -- the primary key of the existing record that caused the collision.
13 insert_or_select :: (PersistBackend m, PersistEntity a)
16 insert_or_select x = do
18 return $ (either id id) tmp