Skip to content

include entity and foreign field schema name parsing#9

Merged
benjonesy merged 5 commits intomasterfrom
benj/include-schema-in-qq-parse
Oct 4, 2024
Merged

include entity and foreign field schema name parsing#9
benjonesy merged 5 commits intomasterfrom
benj/include-schema-in-qq-parse

Conversation

@benjonesy
Copy link
Copy Markdown
Collaborator

@benjonesy benjonesy commented Oct 2, 2024

Adding support for schema=schema_name to be added to Persistent entity syntax so that the quasiquoter can generate schema specifications for entities or their foreign key fields (when using the complex Foreign keyword).

@benjonesy benjonesy force-pushed the benj/include-schema-in-qq-parse branch 2 times, most recently from ac32a4d to f4be66e Compare October 3, 2024 04:22
@benjonesy benjonesy changed the title include schema in qq parse include entity and foreign field schema name parsing Oct 3, 2024
| not (T.null constraintNameText) && isLower (T.head constraintNameText) =
go :: [Text] -> Maybe SchemaNameDB -> Maybe CascadeAction -> Maybe CascadeAction -> UnboundForeignDef
go (constraintNameText:rest) schemaName onDelete onUpdate
| isConstraintName =
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Here we're a bit into the parsing of the Foreign keyword that specifies complex foreign fields (TargetEntity is already known at this point), and follows the syntax:

Foreign TargetEntity schema-name [cascade-actions] constraint-name [columns] [references]

go is structured such that it expects to terminate at constraint-name: the preceding fields (schema-name, cascade-actions - parsed below and carried through) should have already been populated, and the succeeding fields (columns, references) will be parsed/added as part of this condition.

Comment on lines +107 to +110
[childForeignDef] =
entityForeigns $ entityDef $ Proxy @ChildExplicit
it "should have a schema name defined" $ do
(foreignRefSchemaDBName childForeignDef)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'd prefer to use NamedFieldPuns here but adding a pragma for a couple of lines seems excessive.

Comment thread persistent/Database/Persist/Quasi/Internal.hs
Comment thread persistent/Database/Persist/Quasi/Internal.hs Outdated
@benjonesy benjonesy force-pushed the benj/include-schema-in-qq-parse branch 3 times, most recently from 54dc83d to 5ca6374 Compare October 3, 2024 21:21
@benjonesy benjonesy force-pushed the benj/include-schema-in-qq-parse branch from 5ca6374 to d57084f Compare October 3, 2024 21:30
fixForeignRefTableDBName =
getEntityDBName (unboundEntityDef parentDef)
fixForeignRefSchemaDBName =
getEntitySchema (unboundEntityDef parentDef)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Wild. We're lucky it's this easy to add in, I was wondering if it'd be a bit of a wild goose chase. Thanks!

@benjonesy benjonesy merged commit e4a0f27 into master Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants