Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion persistent-qq/test/PersistentTestModels.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ share
-- Indented comment
Person json
name Text
age Int "some ignored -- \" attribute"
age Int some="ignored -- \" attribute"
color Text Maybe -- this is a comment sql=foobarbaz
PersonNameKey name -- this is a comment sql=foobarbaz
deriving Show Eq
Expand Down
2 changes: 1 addition & 1 deletion persistent-sqlite/test1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Control.Monad.IO.Class
mkPersist [$persist|
Person sql=PersonTable
name String update Eq Ne Desc In
age Int update "Asc" Lt "some ignored attribute"
age Int update Asc Lt someIgnoredAttribute
color String null Eq Ne sql=mycolorfield NotIn Ge
PersonNameKey name
Pet
Expand Down
2 changes: 1 addition & 1 deletion persistent-test/src/PersistentTestModels.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "testMigrate"
-- Indented comment
Person json
name Text
age Int "some ignored -- \" attribute"
age Int some="ignored -- \" attribute"
color Text Maybe -- this is a comment sql=foobarbaz
PersonNameKey name -- this is a comment sql=foobarbaz
deriving Show Eq
Expand Down
8 changes: 5 additions & 3 deletions persistent/Database/Persist/Quasi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ User sql=big_user_table
This will alter the generated SQL to be:

@
CREATE TABEL big_user_table (
CREATE TABLE big_user_table (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated typo fix

id SERIAL PRIMARY KEY,
name VARCHAR,
age INT
Expand Down Expand Up @@ -784,9 +784,9 @@ check = do
convert
:: (Entity Vehicle, Maybe (Entity Bicycle), Maybe (Entity Car))
-> Vehicle'
convert (Entity _ (VehicycleBicycleSum _), Just (Entity _ (Bicycle brand)), _) =
convert (Entity _ (VehicleBicycleSum _), Just (Entity _ (Bicycle brand)), _) =
Bike brand
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two unrelated typo fixes

Copy link
Collaborator

Choose a reason for hiding this comment

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

lol vehicycle

convert (Entity _ (VehicycleCarSum _), _, Just (Entity _ (Car make model))) =
convert (Entity _ (VehicleCarSum _), _, Just (Entity _ (Car make model))) =
Car make model
convert _ =
error "The database preconditions have been violated!"
Expand Down Expand Up @@ -931,6 +931,8 @@ module Database.Persist.Quasi
, setPsIdName
, getPsTabErrorLevel
, setPsTabErrorLevel
, getPsQuotedArgumentErrorLevel
, setPsQuotedArgumentErrorLevel
) where

import Database.Persist.Quasi.PersistSettings
Expand Down
30 changes: 16 additions & 14 deletions persistent/Database/Persist/Quasi/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Database.Persist.Quasi.Internal
, PersistSettings (..)
, upperCaseSettings
, lowerCaseSettings
, Token (..)
, Attribute (..)
, SourceLoc (..)
, sourceLocFromTHLoc
, parseFieldType
Expand Down Expand Up @@ -206,7 +206,7 @@ entityNamesFromParsedDef ps parsedEntDef = (entNameHS, entNameDB)
getDbName
ps
(unEntityNameHS entNameHS)
(parsedEntityDefEntityAttributes parsedEntDef)
(attributeContent <$> parsedEntityDefEntityAttributes parsedEntDef)

-- | This type represents an @Id@ declaration in the QuasiQuoted syntax.
--
Expand Down Expand Up @@ -527,12 +527,11 @@ mkUnboundEntityDef ps parsedEntDef =
EntityIdField $
maybe autoIdField (unboundIdDefToFieldDef (defaultIdName ps) entNameHS) idField
, entityAttrs =
parsedEntityDefEntityAttributes parsedEntDef
, entityFields =
[]
attributeContent <$> parsedEntityDefEntityAttributes parsedEntDef
, entityFields = []
, entityUniques = entityConstraintDefsUniquesList entityConstraintDefs
, entityForeigns = []
, entityDerives = concat $ mapMaybe takeDerives textAttribs
, entityDerives = concat $ mapMaybe takeDerives (textAttribs ++ textDirectives)
, entityExtra = parsedEntityDefExtras parsedEntDef
, entitySum = parsedEntityDefIsSum parsedEntDef
, entityComments =
Expand All @@ -546,19 +545,22 @@ mkUnboundEntityDef ps parsedEntDef =
(entNameHS, entNameDB) =
entityNamesFromParsedDef ps parsedEntDef

attribs =
parsedEntityDefFieldAttributes parsedEntDef
fields = parsedEntityDefFields parsedEntDef
directives = parsedEntityDefDirectives parsedEntDef

cols :: [UnboundFieldDef]
cols = foldMap (toList . commentedField ps) attribs
cols = foldMap (toList . commentedField ps) fields

textAttribs :: [[Text]]
textAttribs = fmap tokenContent . fst <$> attribs
textAttribs = entityFieldContent . fst <$> fields

textDirectives :: [[Text]]
textDirectives = directiveContent . fst <$> directives

entityConstraintDefs =
foldMap
(maybe mempty (takeConstraint ps entNameHS cols) . NEL.nonEmpty)
textAttribs
(textAttribs ++ textDirectives)

idField =
case entityConstraintDefsIdField entityConstraintDefs of
Expand All @@ -574,10 +576,10 @@ mkUnboundEntityDef ps parsedEntDef =

commentedField
:: PersistSettings
-> ([Token], Maybe Text)
-> (EntityField, Maybe Text)
-> Maybe UnboundFieldDef
commentedField s (tokens, mCommentText) = do
unb <- takeColsEx s (tokenContent <$> tokens)
commentedField s (field, mCommentText) = do
unb <- takeColsEx s (entityFieldContent field)
pure $ unb{unboundFieldComments = mCommentText}

autoIdField :: FieldDef
Expand Down
Loading
Loading