Skip to content

Proposal: ignore_conflict #120

@bunnylushington

Description

@bunnylushington

Hi -- I use the following code to add an on conflict (col) do nothing clause to the SQL statement Moebius generates and wonder if (a) this would be a generally useful addition to the library and (b) how detailed an implementation would be required to be general enough. (on conflict can be arbitrarily complicated; personally I'd opt for a function for anything more involved than this simple statement but I know that might be an extreme position.)

  @spec ignore_conflict(%Moebius.QueryCommand{}, String.t) ::
      %Moebius.QueryCommand{}
  @doc "Do nothing when an insert conflict is detected on COL."
  def ignore_conflict(%Moebius.QueryCommand{} = cmd, col) do
    conflict = "on conflict (#{col}) do nothing"
    new = Regex.replace(~r/returning.+$/, cmd.sql, "#{conflict} \\0")
    %{cmd | sql: new}
  end

If there is interest, I'd be happy to supply a PR (with any guidance incorporated). Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions