Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TYPES = &typeRegistry{ byType: make(map[reflect.Type]Type), byKind: make(map[reflect.Kind]Type), Locked: signals.New[TypeRegistry]("dbtype.TYPES.Locked"), }
Functions ¶
func Add ¶
Add a type to the registry.
The srcTyp can be a reflect.Type, reflect.Value, reflect.Kind, or we use reflect.TypeOf(srcTyp) to get the type. The dbType is the database type to bind to the srcTyp.
If forceKind is true, the kind of the srcTyp will be used to register the type as well.
After adding the type, calling `For(reflect.Type)` will return the dbType for the srcTyp.
This function will only return false if the type registry is locked.
func Lock ¶
func Lock()
Lock locks the type registry.
This is used to prevent further modifications to the type registry after it has been locked.
It is used to ensure that the type registry is not modified after everything has been setup and registered.
func Types ¶
Types returns a sequence of all registered types in the registry. It yields pairs of reflect.Type and Type, allowing iteration over all registered types. This is useful for introspection, debugging purposes and type management.
Currently, it is only used in [drivers.registerTypeConversions] for converting a [string] of `<pkgpath.typename>` to reflect.Type for the initialization of default values during migrations for older migration files who's default value type might not match the current type. this is because the type registry provides a nice and unified way to handle go types which are also used in the database drivers.
Types ¶
type CanDBType ¶
type CanDBType interface {
DBType() Type
}
CanDBType is an interface that defines a method to get the database type of a value.
It can be implemented by both [attrs.Field], or the reflect.Type returned by [attrs.Field.Type]
type CanDBTypeString ¶
type CanDBTypeString interface {
DBType() string
}
CanDBTypeString is a type that can be used to define a field that can return a database type as a string.
type Type ¶
type Type int
func For ¶
For returns the database type for the given reflect.Type.
If the type is not registered, it will return the default type (Text).
func NewFromString ¶
func (Type) MarshalJSON ¶
func (*Type) UnmarshalJSON ¶
type TypeRegistry ¶
type TypeRegistry interface { Add(srcTyp any, dbType Type, forceKind ...bool) bool For(typ reflect.Type) (dbType Type, exists bool) IsLocked() bool Lock() (success bool) Types() iter.Seq2[reflect.Type, Type] Unlock() }
The TypeRegistry interface defines methods for managing a registry of database types. It is only used for the signal before the type registry is locked.