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

gen: expose table's primary key and/or constraint names for use in im.OnConflict()/im.OnConflictOnConstraint() #315

Open
edigaryev opened this issue Nov 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@edigaryev
Copy link

The recent 0.29.0 release made some pretty substantial changes to the generated code's API (and I hope for the good), one of which was the deprecation of Upsert() in favor of Insert() with some mods.

Assuming that one now has to use im.OnConflict() or im.OnConflictOnConstraint() to achieve the same behavior, the table's primary key and/or constraint names needs to be specified explicitly for use in these mods.

Whereas before this was handled automatically by the Upsert(), when passing conflictCols equal to nil:

bob/dialect/sqlite/table.go

Lines 205 to 207 in 09c8491

if len(conflictCols) == 0 {
conflictCols = t.pkCols
}

As a result, one now has to type these constraints by hand, which makes things more error-prone than they were before.

@stephenafamo
Copy link
Owner

This is on the radar.

In the CHANGELOG, you may notice that constraints and indexes are now being loaded with even a bit more information than before (e.g. CHECK constraints are now loaded too).

In the near future, the plan is to generate code with this information so that it can be used in queries.

In the meantime, you can supply your own templates and generate any code you need.

@stephenafamo stephenafamo added the enhancement New feature or request label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants