package dbml import ( "regexp" "strings" "git.warky.dev/wdevs/relspecgo/pkg/models" ) var ( generatedNoteRegex = regexp.MustCompile(`(?is)^GENERATED\s+ALWAYS\s+AS\s*\((.*)\)\s*STORED$`) identityNoteRegex = regexp.MustCompile(`(?i)^GENERATED\s+(ALWAYS|BY\s+DEFAULT)\s+AS\s+IDENTITY$`) ) // applyColumnMarkerNote interprets a column note written by the DBML writer for // GENERATED ... STORED and GENERATED ... AS IDENTITY columns, setting the matching // model fields. It returns true when the note was a marker, in which case it is not // a user comment. func applyColumnMarkerNote(column *models.Column, rawNote string) bool { note := strings.TrimSpace(rawNote) if len(note) >= 2 && (note[0] == '\'' || note[0] == '"') && note[len(note)-1] == note[0] { note = note[1 : len(note)-1] } note = strings.ReplaceAll(strings.ReplaceAll(note, `\'`, `'`), `\\`, `\`) note = strings.TrimSpace(note) if m := generatedNoteRegex.FindStringSubmatch(note); m != nil { column.Generated = true column.GenerationExpression = strings.TrimSpace(m[1]) return true } if m := identityNoteRegex.FindStringSubmatch(note); m != nil { column.Identity = true column.IdentityGeneration = strings.Join(strings.Fields(strings.ToUpper(m[1])), " ") return true } return false }