-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Describe the feature
Currently, the only option for adding a functional index is to use an expression, which requires specifying the column name in the database. With dynamically generated names based on a custom naming strategy, this is very difficult. The mentioned tag could generate the appropriate expression during the parseFieldIndexes stage.
I create simple fork for my own:
gorm/schema/index.go
if settings["FUNCTION"] != "" && settings["EXPRESSION"] == "" {
f := strings.Split(settings["FUNCTION"], ":")
if len(f) == 1 {
settings["EXPRESSION"] = f[0] + "(" + field.DBName + ")"
} else {
settings["EXPRESSION"] = f[0] + "(" + field.DBName + ", " + f[1] + ")"
}
}
example:
function:upper
result:
upper("DB_COLUMN_NAME")
example:
function:coalesce:-1
result:
coalesce("DB_COLUMN_NAME", -1)
Motivation
Simplifying the creation of simple functional indexes with dynamically generated column names