Skip to content
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

Problematic writing generic queries with open rows #36

Open
Kamirus opened this issue May 29, 2020 · 0 comments
Open

Problematic writing generic queries with open rows #36

Kamirus opened this issue May 29, 2020 · 0 comments
Labels
add to guide Use case worth including in the guide backend-integration Interop code between DSL and some db backend, e.g. generate SQL, execute, [de]serialize results error message Refers to compilation errors (unclear, misleading, ...) query-level Change related to query DSL. Includes changes to `Query` datatype and its internals.

Comments

@Kamirus
Copy link
Owner

Kamirus commented May 29, 2020

Writing such queries often requires providing type signatures including type class constraints.

The query below uses a combination of selectFrom and query1 that require complicated constraints. The table row is open thus these constraints need to persist - it is advised to write the 'top-level constraints' (FromTable in selectFrom and GenericQuery in query1) attached to those functions (in their signatures) and don't let the compiler unfold them.

To type-check the function below we need to provide the type signature ourself - or satisfy ourselves with concrete and closed table-row t and let the compiler solve these constraints immediately.

Please note that the query (returned by selectFrom) is defined separately in the where clause.
Somehow with the proper type signature, the function getUserByEmail does not type-check if we inline the query q.

This should be mentioned in the guide.

getUserByEmail
    t m i o
  . MonadSeldaPG m
   FromTable Unit t ( emailCol Unit String | i )
   GenericQuery BackendPGClass m 
      ( emailCol Unit String | i )
      ( emailString | o )
   Selda.Table t  String  m (Maybe { emailString | o })
getUserByEmail table email = query1 q
  where
    q = selectFrom table \r → do
      restrict $ r.email .== lit email
      pure r
@Kamirus Kamirus added invalid error message Refers to compilation errors (unclear, misleading, ...) labels May 29, 2020
@Kamirus Kamirus added add to guide Use case worth including in the guide backend-integration Interop code between DSL and some db backend, e.g. generate SQL, execute, [de]serialize results query-level Change related to query DSL. Includes changes to `Query` datatype and its internals. and removed invalid labels Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to guide Use case worth including in the guide backend-integration Interop code between DSL and some db backend, e.g. generate SQL, execute, [de]serialize results error message Refers to compilation errors (unclear, misleading, ...) query-level Change related to query DSL. Includes changes to `Query` datatype and its internals.
Projects
None yet
Development

No branches or pull requests

1 participant