morphismtech / squeal

Squeal, a deep embedding of SQL in Haskell
362 stars 32 forks source link

Example: Parametrized `SELECT` query #354

Closed gasi closed 8 months ago

gasi commented 8 months ago

This PR attempts to add an example for a parametrized query getOrganizationsBy inspired by the error described in #353. The goal is to be able to query an organization by id (Int32) as well as name (Text).

Each commit proceeds one step and works until the last one prefixed with FAIL:, which is the closest I got in terms of error message complexity. Adding ToParam Schemas '[ 'NotNull pgty ] hsty => gave me:

    • Expected kind ‘NullType’,
        but ‘'[ 'NotNull pgty]’ has kind ‘[NullType]’

The error I received after running

stack run --stack-yaml stack-ghc9_6.yaml

was:

squeal/squeal-postgresql/exe/Example.hs:130:3: error: [GHC-83865]
    • Couldn't match type: NullPG hsty0
                     with: NullPG hsty
      Expected: Condition
                  Ungrouped
                  '[]
                  '[]
                  Schemas
                  '[NotNull pgty]
                  '["o" ::: ["id" ::: NotNull PGint4, "name" ::: NotNull PGtext]]
                -> Query_ Schemas (Only hsty) Organization
        Actual: Condition
                  Ungrouped
                  '[]
                  '[]
                  Schemas
                  '[NotNull pgty]
                  '["o" ::: ["id" ::: NotNull PGint4, "name" ::: NotNull PGtext]]
                -> Query_ Schemas (Only hsty0) Organization
        NB: ‘NullPG’ is a non-injective type family
        The type variable ‘hsty0’ is ambiguous
    • In the ambiguity check for ‘getOrganizationsBy’
      To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
      In the type signature:
        getOrganizationsBy :: forall pgty
                                     hsty. Condition 'Ungrouped '[] '[] Schemas '[ 'NotNull pgty] '["o"
                                                                                                    :::
                                                                                                    ["id"
                                                                                                     :::
                                                                                                     NotNull PGint4,
                                                                                                     "name"
                                                                                                     :::
                                                                                                     NotNull PGtext]]
                                           -> Query_ Schemas (Only hsty) Organization
    |
130 |   forall pgty hsty.
    |   ^^^^^^^^^^^^^^^^^...

Error: [S-7282]
       Stack failed to execute the build plan.
echatav commented 8 months ago

Can you change the PR's "into branch" from master to dev? That way, hopefully the CI checks will show up.