Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions persistent-qq/test/PersistentTestModels.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ share
~no Int
def Int

PetAnimal schema=animals
ownerId PersonId
name Text
|]

deriving instance Show (BackendKey backend) => Show (PetGeneric backend)
deriving instance Eq (BackendKey backend) => Eq (PetGeneric backend)

deriving instance Show (BackendKey backend) => Show (PetAnimalGeneric backend)
deriving instance Eq (BackendKey backend) => Eq (PetAnimalGeneric backend)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is necessary. I get a weird error when I try to do this derivation with the standard deriving Eq Show syntax.


share [ mkPersist sqlSettings { mpsPrefixFields = False, mpsGeneric = True }
, mkMigrate "noPrefixMigrate"
] [persistLowerCase|
Expand Down Expand Up @@ -178,3 +184,4 @@ cleanDB = do
deleteWhere ([] :: [Filter (OutdoorPetGeneric backend)])
deleteWhere ([] :: [Filter (UserPTGeneric backend)])
deleteWhere ([] :: [Filter (EmailPTGeneric backend)])
deleteWhere ([] :: [Filter (PetAnimalGeneric backend)])
15 changes: 15 additions & 0 deletions persistent-qq/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ spec = describe "persistent-qq" $ do
liftIO $ ret1 @?= [Entity p1k p1]
liftIO $ ret2 @?= [Entity (RFOKey $ unPersonKey p1k) (RFO p1)]

it "sqlQQ/entity in schema" $ db $ do
let person = Person "Zacarias" 93 Nothing
personKey <- insert person
let pet = PetAnimal personKey "Fluffy"
petKey <- insert pet
let runQueryQuoted, runQueryRaw
:: (RawSql a, Functor m, MonadIO m)
=> ReaderT SqlBackend m [a]
runQueryQuoted = [sqlQQ| SELECT ?? FROM ^{PetAnimal} |]
runQueryRaw = [sqlQQ| SELECT ?? FROM animals.pet_animal |]
retQuoted <- runQueryQuoted
retRaw <- runQueryRaw
liftIO $ retQuoted @?= [Entity petKey pet]
liftIO $ retRaw @?= [Entity petKey pet]

it "sqlQQ/OUTER JOIN" $ db $ do
let insert' :: (PersistStore backend, PersistEntity val, PersistEntityBackend val ~ BaseBackend backend, MonadIO m, SafeToInsert val)
=> val -> ReaderT backend m (Key val, val)
Expand Down