SQLProvider
SQLProvider copied to clipboard
Allow developers to extend/create their own the OnConflict clause
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.
Maybe you could do OnConflict raise event like there is the QueryEvents module? And then write your event listener to do what you want?
I don't think there is a definition of "desired features"; if you send a PR without any major issues, I'll merge.