-
Notifications
You must be signed in to change notification settings - Fork 301
Warn on quoted attributes #1601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
9d114b8
4d1e164
170722a
132b617
5bfce3a
10515fc
0fe5472
7b25820
60081ca
0b9a685
d61f504
1a32daf
1f9a17c
b877de8
2e000c9
8731423
6e595e5
d5354b5
c6ee45d
a5bec09
b0090fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ( | ||
| id SERIAL PRIMARY KEY, | ||
| name VARCHAR, | ||
| age INT | ||
|
|
@@ -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 | ||
|
||
| 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!" | ||
|
|
@@ -931,6 +931,8 @@ module Database.Persist.Quasi | |
| , setPsIdName | ||
| , getPsTabErrorLevel | ||
| , setPsTabErrorLevel | ||
| , getPsQuotedArgumentErrorLevel | ||
| , setPsQuotedArgumentErrorLevel | ||
| ) where | ||
|
|
||
| import Database.Persist.Quasi.PersistSettings | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ module Database.Persist.Quasi.Internal | |
| , PersistSettings (..) | ||
| , upperCaseSettings | ||
| , lowerCaseSettings | ||
| , Token (..) | ||
| , Attribute (..) | ||
| , SourceLoc (..) | ||
| , sourceLocFromTHLoc | ||
| , parseFieldType | ||
|
|
@@ -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. | ||
| -- | ||
|
|
@@ -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 (textFields ++ textDirectives) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid changing the external interface, we'll just smush the field definitions and directives together for now. We should improve this in the future. |
||
| , entityExtra = parsedEntityDefExtras parsedEntDef | ||
| , entitySum = parsedEntityDefIsSum parsedEntDef | ||
| , entityComments = | ||
|
|
@@ -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 | ||
| textFields :: [[Text]] | ||
| textFields = entityFieldContent . fst <$> fields | ||
|
|
||
| textDirectives :: [[Text]] | ||
| textDirectives = directiveContent . fst <$> directives | ||
|
|
||
| entityConstraintDefs = | ||
| foldMap | ||
| (maybe mempty (takeConstraint ps entNameHS cols) . NEL.nonEmpty) | ||
| textAttribs | ||
| (textFields ++ textDirectives) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid changing the external interface, we'll just smush the field definitions and directives together for now. We should improve this in the future. |
||
|
|
||
| idField = | ||
| case entityConstraintDefsIdField entityConstraintDefs of | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated typo fix