2021-07-27 17:39:21 +02:00
|
|
|
package metadata
|
|
|
|
|
|
2023-07-23 17:56:07 +02:00
|
|
|
import (
|
|
|
|
|
"regexp"
|
|
|
|
|
)
|
2023-07-22 12:01:49 +02:00
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
// Column struct
|
|
|
|
|
type Column struct {
|
2024-02-03 14:35:28 -08:00
|
|
|
Name string `sql:"primary_key"`
|
2021-07-27 17:39:21 +02:00
|
|
|
IsPrimaryKey bool
|
|
|
|
|
IsNullable bool
|
2023-01-30 10:42:06 -05:00
|
|
|
IsGenerated bool
|
2024-08-13 14:52:54 -06:00
|
|
|
HasDefault bool
|
2021-07-27 17:39:21 +02:00
|
|
|
DataType DataType
|
2023-03-31 14:43:47 +02:00
|
|
|
Comment string
|
2021-07-27 17:39:21 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-22 12:01:49 +02:00
|
|
|
// GoLangComment returns column comment without ascii control characters
|
|
|
|
|
func (c Column) GoLangComment() string {
|
|
|
|
|
if c.Comment == "" {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove ascii control characters from string
|
|
|
|
|
return regexp.MustCompile(`[[:cntrl:]]+`).ReplaceAllString(c.Comment, "")
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
// DataTypeKind is database type kind(base, enum, user-defined, array)
|
|
|
|
|
type DataTypeKind string
|
|
|
|
|
|
|
|
|
|
// DataTypeKind possible values
|
|
|
|
|
const (
|
|
|
|
|
BaseType DataTypeKind = "base"
|
|
|
|
|
EnumType DataTypeKind = "enum"
|
|
|
|
|
UserDefinedType DataTypeKind = "user-defined"
|
|
|
|
|
ArrayType DataTypeKind = "array"
|
2024-02-01 15:20:49 +01:00
|
|
|
RangeType DataTypeKind = "range"
|
2021-07-27 17:39:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// DataType contains information about column data type
|
|
|
|
|
type DataType struct {
|
|
|
|
|
Name string
|
|
|
|
|
Kind DataTypeKind
|
|
|
|
|
IsUnsigned bool
|
2024-09-03 15:39:36 +02:00
|
|
|
Dimensions int // The number of array dimensions
|
2021-07-27 17:39:21 +02:00
|
|
|
}
|