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

Ability to extend upsert expression with options #1317

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

atzedus
Copy link

@atzedus atzedus commented Oct 17, 2023

This PR adds ability to provide some options to extend UPSERT expression.
For example, following sql needed:

CREATE TABLE test (name text);
CREATE UNIQUE INDEX ON test(lower(name)) WHERE name IS NOT NULL;

INSERT INTO test (name) ON CONFLICT (lower(name)) WHERE name IS NOT NULL DO NOTHING;

Currently it not possible with "Upsert" method.
This PR adds ability to provide options to Upsert method, for example:

m := &models.Test{ name: "test" }

m.Upsert(ctx, db, false, nil, boil.Infer(), boil.Infer(), models.UpsertConflictObject("(lower(name)) WHERE name IS NOT NULL"))

Also, it adds UpsertUpdateSet(string) option to customize DO UPDATE SET expression to any custom value.

@stephenafamo
Copy link
Collaborator

This looks quite nice and is fully backwards-compatible. Thank you.

@stephenafamo stephenafamo merged commit 6c91199 into volatiletech:master Oct 18, 2023
2 checks passed
@atzedus atzedus deleted the upsert-options-feature branch October 18, 2023 08:12
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

Successfully merging this pull request may close these issues.

2 participants