types

package
v1.2.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoTypeMapperFound is returned when no type mapper found.
	ErrNoTypeMapperFound = errors.New("no type mapper found for database type")
	// ErrUnsupportedType is returned when unsupported type.
	ErrUnsupportedType = errors.New("unsupported database type")
)

Functions

func FormatCamelCase

func FormatCamelCase(dbColumnName string) string

FormatCamelCase formats camel case.

func FormatDisplayName

func FormatDisplayName(dbColumnName string) string

FormatDisplayName formats display name.

func FormatFieldName

func FormatFieldName(dbColumnName string) string

FormatFieldName formats field name.

Types

type TypeMapper

type TypeMapper struct {
	DatabaseType string
	NullType     string // "pointer", "sql.Null", or "bun.Null"
	Overrides    []TypeOverride
}

TypeMapper represents type mapper.

func NewTypeMapper

func NewTypeMapper(databaseType string) *TypeMapper

NewTypeMapper creates a new type mapper.

func (*TypeMapper) BuildBunTag added in v1.0.0

func (tm *TypeMapper) BuildBunTag(col *catalog.Column) string

BuildBunTag returns the value of the `bun:"..."` struct tag for a column. Only emits attributes that affect query/marshaling behavior — column name, primary-key marker, and a `type:` hint where bun's default mapping would otherwise be wrong (notably uuid columns). DDL-only attributes (notnull/nullzero/default/unique/autoincrement) are intentionally omitted because andurel does not use bun for schema management.

func (*TypeMapper) GetDatabaseType

func (tm *TypeMapper) GetDatabaseType() string

GetDatabaseType returns database type.

func (*TypeMapper) MapSQLTypeToGo

func (tm *TypeMapper) MapSQLTypeToGo(
	sqlType string,
	nullable bool,
) (goType, packageName string, err error)

MapSQLTypeToGo returns the Go type for a SQL column. Nullable columns are wrapped according to tm.NullType ("pointer" → *string, "sql.Null" → sql.NullString, "bun.Null" → bun.NullString). The second return value is the import path required for the type, or "" if it is a builtin.

type TypeOverride

type TypeOverride struct {
	DatabaseType string
	GoType       string
	Package      string
}

TypeOverride lets users map a SQL database type to a custom Go type. When the column is nullable, the resulting Go type will be wrapped according to the TypeMapper's NullType setting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL