Allow developers to extend/create their own the OnConflict clause

Open
#730 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
fsharp, postgresql
Domain
databases

Research direction

Start at src/SQLProvider.Runtime/Providers.Postgresql.fs around line 516 and inspect the OnConflict discriminated union and its SQL generation. Compare how the other providers handle conflict behavior before deciding the extension's scope. Done means custom ON CONFLICT behavior can address non-primary unique-index conflicts without breaking Throw, Update, or DoNothing.

Written by the indexing model from the issue text.

Description

https://github.com/fsprojects/SQLProvider/blob/8afaad203efe2b3b900a2ad1a6d8a35d66ebe40a/src/SQLProvider.Runtime/Providers.Postgresql.fs#L516

Is there any way to create / use a custom "ON CONFLICT" clause? It looks like this should be easily extendible by adding another case to the OnConflict discriminated union:

        match entity.OnConflict with
        | Throw -> ()
        | Update ->
          ~~(sprintf " ON CONFLICT (%s) DO UPDATE SET %s "                
                (String.Join(",", pk |> List.map (sprintf "\"%s\"")))
                (String.Join(",", columnNamesWithValues |> List.map(fun (c,p) -> sprintf "\"%s\" = %s" c p.ParameterName ) )))
        | DoNothing ->
          ~~(sprintf " ON CONFLICT DO NOTHING ")
        | Custom clause -> ~~(sprintf clause)

I have a postgres database with tables that contain unique indices that aren't a primary key (created via Rails migrations). I'd like to be able to watch out for conflicts on these columns and update other columns as necessary.


edit
If you think this would be a desired feature, I'd be happy to submit a pull request. I'd need/want your help for other providers but I could at least kick it off.

Dominant language
F#
Stars
627
Forks
147
Avg merge
2h 2m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fsprojects/SQLProvider

All issues in fsprojects/SQLProvider

Similar issues

More Databases issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.