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

Match operator not possible inside PostgreSQL update computation expression #104

Open
zeejers opened this issue Jun 5, 2024 · 1 comment

Comments

@zeejers
Copy link

zeejers commented Jun 5, 2024

 update {
    for p in peopleService.Table do
        match person.FirstName 
        | Some firstName -> setColumn p.FirstName firstname
        | None -> ()

        where (p.Id = id)
  }

Gives me an error:

A custom operation may not be used in conjunction with 'use', 'try/with', 'try/finally', 'if/then/else' or 'match' operators within this computation expressionF# Compiler[3086](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-messages/fs3086)

Similarly, trying to use an if operator gives me this error:
This control construct may only be used if the computation expression builder defines a 'Zero' methodF# Compiler[708](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-messages/fs0708)

It would be great to be able to match in the update CE for the purpose of accepting a Partial DTO and only setting columns for those fields which have Some value.

@JordanMarr
Copy link
Contributor

JordanMarr commented Jun 5, 2024

The query expressions have a fairly narrow band of acceptable syntax. Match statements are not handled.

This is because the code in the query isn’t executed directly. Rather, it is just reading the code structures and converting them into a SQL string on your behalf.

Think of it as a strongly typed way to create a SQL command.

If you want to be able to conditionally set a field, you could fairly easily create a “setIf” extension method / custom operation that also takes a bool condition parameter.

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

No branches or pull requests

2 participants