Source File
sqltype.go
Belonging Package
github.com/uptrace/bun/dialect/pgdialect
package pgdialectimport ()const (// Date / TimepgTypeTimestampTz = "TIMESTAMPTZ" // Timestamp with a time zonepgTypeDate = "DATE" // DatepgTypeTime = "TIME" // Time without a time zonepgTypeTimeTz = "TIME WITH TIME ZONE" // Time with a time zonepgTypeInterval = "INTERVAL" // Time Interval// Network AddressespgTypeInet = "INET" // IPv4 or IPv6 hosts and networkspgTypeCidr = "CIDR" // IPv4 or IPv6 networkspgTypeMacaddr = "MACADDR" // MAC addresses// Serial TypespgTypeSmallSerial = "SMALLSERIAL" // 2 byte autoincrementing integerpgTypeSerial = "SERIAL" // 4 byte autoincrementing integerpgTypeBigSerial = "BIGSERIAL" // 8 byte autoincrementing integer// Character TypespgTypeChar = "CHAR" // fixed length string (blank padded)pgTypeText = "TEXT" // variable length string without limit// JSON TypespgTypeJSON = "JSON" // text representation of json datapgTypeJSONB = "JSONB" // binary representation of json data// Binary Data TypespgTypeBytea = "BYTEA" // binary string)var (timeType = reflect.TypeOf((*time.Time)(nil)).Elem()ipType = reflect.TypeOf((*net.IP)(nil)).Elem()ipNetType = reflect.TypeOf((*net.IPNet)(nil)).Elem()jsonRawMessageType = reflect.TypeOf((*json.RawMessage)(nil)).Elem())func ( *schema.Field) string {if .UserSQLType != "" {return .UserSQLType}if , := .Tag.Options["composite"]; {return}if , := .Tag.Options["hstore"]; {return "hstore"}if , := .Tag.Options["array"]; {switch .IndirectType.Kind() {case reflect.Slice, reflect.Array::= sqlType(.IndirectType.Elem())return + "[]"}}return sqlType(.IndirectType)}func ( reflect.Type) string {switch {case ipType:return pgTypeInetcase ipNetType:return pgTypeCidrcase jsonRawMessageType:return pgTypeJSONB}:= schema.DiscoverSQLType()switch {case sqltype.Timestamp:= pgTypeTimestampTz}switch .Kind() {case reflect.Map, reflect.Struct:if == sqltype.VarChar {return pgTypeJSONB}returncase reflect.Array, reflect.Slice:if .Elem().Kind() == reflect.Uint8 {return pgTypeBytea}return pgTypeJSONB}return}
![]() |
The pages are generated with Golds v0.3.6. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |