Skip to content

generates error constants based on unique indexes #360

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

tlietz
Copy link
Contributor

@tlietz tlietz commented Feb 19, 2025

Closes #355

Let me know if I should change anything.

@stephenafamo
Copy link
Owner

Why are you using the column names and not the index name?

@tlietz
Copy link
Contributor Author

tlietz commented Feb 20, 2025

Initially, I was using the column names because those were used with the unique constraints.

However, after looking into using index names, the generated constants seem more verbose with Postgres, and information about the columns are lost in Sqlite (assuming default index naming). Should I still go through with using the index name instead of the column name?

Postgres:

// Generated with Index Names
var JetErrors = &jetErrors{
	ErrUniqueJetsPkey: &UniqueConstraintError{s: "jets_pkey"},

	ErrUniqueJetsNameColorKey: &UniqueConstraintError{s: "jets_name_color_key"},

	ErrUniqueJetsPilotIdAirportIdKey: &UniqueConstraintError{s: "jets_pilot_id_airport_id_key"},
}

type jetErrors struct {
	ErrUniqueJetsPkey *UniqueConstraintError

	ErrUniqueJetsNameColorKey *UniqueConstraintError

	ErrUniqueJetsPilotIdAirportIdKey *UniqueConstraintError
}
// Generated with Column Names
var JetErrors = &jetErrors{
	ErrUniqueId: &UniqueConstraintError{s: "jets_pkey"},

	ErrUniqueNameAndColor: &UniqueConstraintError{s: "jets_name_color_key"},

	ErrUniquePilotIdAndAirportId: &UniqueConstraintError{s: "jets_pilot_id_airport_id_key"},
}

type jetErrors struct {
	ErrUniqueId *UniqueConstraintError

	ErrUniqueNameAndColor *UniqueConstraintError

	ErrUniquePilotIdAndAirportId *UniqueConstraintError
}

Sqlite:

// Generated with index Names
var JetErrors = &jetErrors{
	ErrUniqueIdxJets: &UniqueConstraintError{s: "idx_jets"},

	ErrUniqueSqliteAutoindexJets1: &UniqueConstraintError{s: "sqlite_autoindex_jets_1"},
}

type jetErrors struct {
	ErrUniqueIdxJets *UniqueConstraintError

	ErrUniqueSqliteAutoindexJets1 *UniqueConstraintError
}

@stephenafamo
Copy link
Owner

Yes, let's use the index names.

Users can rename the indexes if they want, and in the future, we can expand aliases to allow aliasing indexes too

@stephenafamo
Copy link
Owner

Final comment.

Update CHANGELOG.md with your changes, along with attribution (thanks @tlietz)

@tlietz
Copy link
Contributor Author

tlietz commented Feb 20, 2025

Should the docs, or any tests be changed with this pull request?
I'd be glad to update those as well if so.

@stephenafamo
Copy link
Owner

Should the docs, or any tests be changed with this pull request?

The docs need a lot of work. Any improvements are very welcome. At the moment though, I'm first making sure the CHANGELOG is up to date, I'll find time to dive deeply into improving the docs later.

@stephenafamo stephenafamo merged commit 5d6bdfc into stephenafamo:main Feb 22, 2025
8 checks passed
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.

No generated error constants for unique index
2 participants