14 lines
525 B
Haskell
14 lines
525 B
Haskell
module DB.Interpreter where
|
|
|
|
import Control.Exception (throwIO)
|
|
import Control.Monad.Free.Church (foldF)
|
|
import Database.PostgreSQL.Simple (Connection, Query)
|
|
import DB.Language
|
|
|
|
interpretSqlDBMethod :: Connection -> Query -> SqlDBMethodF a -> IO a
|
|
interpretSqlDBMethod conn squery (SqlDBMethod runner next) = next <$> runner conn squery
|
|
interpretSqlDBMethod _ _ (SqlThrowException exception _) = throwIO exception
|
|
|
|
runDB :: Connection -> Query -> SqlDb a -> IO a
|
|
runDB conn squery = foldF $ interpretSqlDBMethod conn squery
|