This library maps datatypes to a relational model, in a way similar to what ORM libraries do in OOP. See the tutorial https://www.schoolofhaskell.com/user/lykahb/groundhog for introduction
I'm hoping to be able to define my types in one module and write queries using those types in another module. E.g.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
module Models where
import Database.Groundhog.TH
import Database.Groundhog.MySQL
data Record = Record
{ field :: String }
deriving instance Show Record
mkPersist defaultCodegenConfig [groundhog|
- entity: Record
|]
And:
module Main where
import Database.Groundhog.MySQL
import Models
main :: IO ()
main = do
xs <- withMySQLConn defaultConnectInfo $ runDbConn $ select $ (Field ==. "foo")
putStrLn $ head xs
But what actually happens here is:
Main.hs:8:66: error:
• Data constructor not in scope: Field
• Perhaps you meant variable ‘field’ (imported from Models)
By default the generated constructor name is the capitalized record field with the suffix "Field". So, in your case, the line should be FieldField ==. "foo"
I'm hoping to be able to define my types in one module and write queries using those types in another module. E.g.
And:
But what actually happens here is:
Any ideas what's going on here?