2021-07-27 17:39:21 +02:00
|
|
|
package metadata
|
|
|
|
|
|
2024-09-24 20:41:27 +02:00
|
|
|
import "regexp"
|
|
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
// Table metadata struct
|
|
|
|
|
type Table struct {
|
2024-02-03 14:35:28 -08:00
|
|
|
Name string `sql:"primary_key"`
|
2024-09-24 20:41:27 +02:00
|
|
|
Comment string
|
2021-07-27 17:39:21 +02:00
|
|
|
Columns []Column
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MutableColumns returns list of mutable columns for table
|
|
|
|
|
func (t Table) MutableColumns() []Column {
|
|
|
|
|
var ret []Column
|
|
|
|
|
|
|
|
|
|
for _, column := range t.Columns {
|
2023-01-30 10:42:06 -05:00
|
|
|
if column.IsPrimaryKey || column.IsGenerated {
|
2021-07-27 17:39:21 +02:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = append(ret, column)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
}
|
2024-09-24 20:41:27 +02:00
|
|
|
|
|
|
|
|
// GoLangComment returns table comment without ascii control characters
|
|
|
|
|
func (t Table) GoLangComment() string {
|
|
|
|
|
if t.Comment == "" {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove ascii control characters from string
|
|
|
|
|
return regexp.MustCompile(`[[:cntrl:]]+`).ReplaceAllString(t.Comment, "")
|
|
|
|
|
}
|