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

(Postgres) Add Annotation for Generated Expressions #3984

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ivanvanderbyl
Copy link
Contributor

@ivanvanderbyl ivanvanderbyl commented Mar 21, 2024

This PR resolves #3168 to add support for generated columns as needed when using tsvector or similar extensions in Postgres.

Usage:

field.String("text_searchable_content").
	SchemaType(map[string]string{dialect.Postgres: "tsvector"}).
	Annotations(entsql.GeneratedAs("to_tsvector(...)")).
	Optional()

Todo:

  • Updated schema migration template to add generated expressions

Follow up work:

Obviously for something like tsvector where you never read or write the column, this is suboptimal and a follow up PR should add a new field type for this use case, such as field.Generated("name").As("to_expression()") with the following properties:

  • Does not add Setters or Getters for the field
  • Field is immutable
  • Field is optional for creates
  • Generates a model.FieldName var

Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Signed-off-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
@ivanvanderbyl
Copy link
Contributor Author

👋🏻 @a8m hey Ariel, I'd love to get your input on this, and any changes I can make to get it merged

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.

Support for generated columns
1 participant