]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/Database.hs
Add a minor TODO note.
[dead/htsn-import.git] / src / TSN / Database.hs
1 -- | Standalone database functions for dealing with Groundhog types.
2 --
3 module TSN.Database ( insert_or_select )
4 where
5
6 import Database.Groundhog ( AutoKey, insertByAll )
7 import Database.Groundhog.Core ( PersistBackend, PersistEntity )
8
9
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)
14 => a
15 -> m (AutoKey a)
16 insert_or_select x = do
17 tmp <- insertByAll x
18 return $ (either id id) tmp