-
Notifications
You must be signed in to change notification settings - Fork 54
Add support for conflict_target: {:unsafe_fragment, _} #59
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
Conversation
Sqlite does support ON CONFLICT DO upsert feature, eg: https://www.sqlite.org/lang_UPSERT.html Sync definitions with postgrex
| defp update_key(_kind, key, _query, _sources) do | ||
| quote_name(key) | ||
| defp update_fields(%{updates: updates} = query, sources) do | ||
| for(%{expr: expr} <- updates, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did mix format make this get all aligned on the same column?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me with the default I think not... The lines I carefully copy/pasted from postgrex. No special reason other than I kind of consider it the main upstream implementation and I guess the closer this file is to the upstream the easier to merge in changes going forward?
https://github.com/elixir-ecto/ecto_sql/blob/master/lib/ecto/adapters/postgres/connection.ex#L176
I wonder if they use a custom .formatter file, didn't think to check? For me also, the formatter will add extra row spaces between each of these clauses, but their formatting has them all bunched together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Are there tests we could add to the integration suite to ensure this is doing what we want it to do? Or rather are there already existing integration tests that we can enable to test against?
|
I approved the test suite to run. @ewildgoose feel free to push changes and what not. |
|
OK, so this looks like I've introduced some bug, probably syncing with (what I'll call upstream) Error is: I assume it's the improper list [117 | "0"] which is breaking things? I've copied a couple of what I thought were indifferent changes from "upstream" where they appear to do a list cons when returning a value, rather than returning the longer list. I would hazard a guess there is somewhere sending a value not wrapped in a list, which then gets turned into an improper list I could remove some of the changes, but I wonder if you can guide on what you see as "upstream"? Is it work a slightly larger sync change to make our code look more substantially similar to postgrex? (ease of comparison/digression being the only motivation) |
|
Can you link me to the sections you copied upstream? I want to take a look at the blame and do some digging. |
|
Hi, see comment above. Main link is this: I had to merge it because of the extra clause we have forbidding using named contraints. I also added the error message at the base of the file. Then I jumped to a wrong conclusion, which is why I synced "update_fields" as well. The only useful functional line that I've added is line 667: The rest is just syncing with ecto_sql (which may or may not be desired?) |
Don't worry it confuses me as well. |
|
I presume it's this change causing the issue (or the update_fields() change, but can't see how that causes it?) |
Sqlite does support ON CONFLICT DO upsert feature, eg:
https://www.sqlite.org/lang_UPSERT.html
As part of this I synced a couple of function definitions to match current upstream postgrex as part of this. This is a bit stark as they use a different formatting option. Does this fit with your goals?
Note my goal here was to be able to do something like:
Where the goal is to simulate a unique constraint on a column which accepts nulls (default for sqlite is to allow multiple "unique" rows in a nullable column)