model

package
v0.0.0-...-c78e9a6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: LGPL-2.1 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RelationCascadeNoAction   = RelationCascade("NO ACTION")
	RelationCascadeSetNull    = RelationCascade("SET NULL")
	RelationCascadeSetDefault = RelationCascade("SET DEFAULT")
	RelationCascadeCascade    = RelationCascade("CASCADE")
)
View Source
const (
	RelationTypeOneToOne   = RelationType("one:one")
	RelationTypeOneToMany  = RelationType("one:many")
	RelationTypeManyToOne  = RelationType("many:one")
	RelationTypeManyToMany = RelationType("many:many")
)
View Source
const (
	FieldDataTypeOptEnumValues        = FieldDataTypeOptName("enumValues")
	FieldDataTypeOptLangJsonWhitelist = FieldDataTypeOptName("langJsonWhitelist")
	FieldDataTypeOptLength            = FieldDataTypeOptName("length")
	FieldDataTypeOptRange             = FieldDataTypeOptName("range")
	FieldDataTypeOptSanitizeType      = FieldDataTypeOptName("sanitizeType")
	FieldDataTypeOptScale             = FieldDataTypeOptName("scale")
)
View Source
const (
	SanitizeTypeNone      = SanitizeType("none")
	SanitizeTypeHtml      = SanitizeType("html")
	SanitizeTypePlainText = SanitizeType("plaintext")
)
View Source
const (
	FieldRuleArrayLengthType = FieldRuleName("arrlength")
)
View Source
const JsonFieldTag = "json"

Variables

This section is empty.

Functions

func CoerceFilterBool

func CoerceFilterBool(value any) (bool, error)

CoerceFilterBool parses search-graph filter values into bool (bool, *bool, string literals, etc.).

func IsFieldDataTypeModel

func IsFieldDataTypeModel(dt FieldDataType) bool

func NewFormatMismatchErr

func NewFormatMismatchErr(field string) *ft.ClientErrorItem

func NewInvalidDataTypeErr

func NewInvalidDataTypeErr(field string) *ft.ClientErrorItem

func NewMissingFieldErr

func NewMissingFieldErr(field string) *ft.ClientErrorItem

func PrefixedThroughColumn

func PrefixedThroughColumn(prefix, fieldName string) string

PrefixedThroughColumn returns junction column name prefix_fieldName (e.g. user + id -> user_id).

func RegisterSchema

func RegisterSchema(schema *ModelSchema) error

RegisterSchema registers a schema using its name as the registry key. Returns an error if a schema with the same name is already registered.

func RegisterSchemaB

func RegisterSchemaB(schemaBuilder *ModelSchemaBuilder) error

RegisterSchemaB executes the schemaBuilder then registers a schema using its name (set via ModelSchemaBuilder.Name) as the registry key. Returns an error if a schema with the same name is already registered.

func RelationsShareForeignKeyColumns

func RelationsShareForeignKeyColumns(a, b ModelRelation) bool

RelationsShareForeignKeyColumns reports whether two relations use the same FK column pairs.

func ValidateArrayLength

func ValidateArrayLength(value any, opts any) *ft.ClientErrorItem

ValidateArrayLength validates that slice/array length is between min and max (inclusive). opts must be []int{min, max}.

func ValidateEmail

func ValidateEmail(value string) *ft.ClientErrorItem

func ValidateMax

func ValidateMax(value any, opts any) *ft.ClientErrorItem

ValidateMax validates that value is not greater than max. Supports numbers, strings (length), slices (length).

func ValidateMin

func ValidateMin(value any, opts any) *ft.ClientErrorItem

ValidateMin validates that value is not less than min. Supports numbers, strings (length), slices (length).

func ValidateNotEmpty

func ValidateNotEmpty(value any) *ft.ClientErrorItem

func ValidateNotNil

func ValidateNotNil(value any) *ft.ClientErrorItem

func ValidateOneOf

func ValidateOneOf(value any, opts any) *ft.ClientErrorItem

ValidateOneOf validates that value is one of the allowed values. opts must be []any of allowed values.

func ValidatePattern

func ValidatePattern(value string, re *regexp.Regexp) bool

func ValidateUrl

func ValidateUrl(value string) *ft.ClientErrorItem

func ValidateUuid

func ValidateUuid(value string) bool

func Value

func Value(val any) value

Types

type Condition

type Condition []any

func NewCondition

func NewCondition(field string, operator Operator, values ...any) Condition

func (Condition) Field

func (c Condition) Field() string

func (Condition) Operator

func (c Condition) Operator() Operator

func (Condition) Value

func (c Condition) Value() any

func (Condition) Values

func (c Condition) Values() []any

type DynamicFields

type DynamicFields map[string]any

func ExtractFieldsArr

func ExtractFieldsArr[TSrc DynamicModelGetter](arr []TSrc) []DynamicFields

func (DynamicFields) GetAny

func (this DynamicFields) GetAny(key string) any

func (DynamicFields) GetBool

func (this DynamicFields) GetBool(key string) *bool

func (DynamicFields) GetEtag

func (this DynamicFields) GetEtag(key string) *model.Etag

func (DynamicFields) GetInt

func (this DynamicFields) GetInt(key string) *int

func (DynamicFields) GetInt64

func (this DynamicFields) GetInt64(key string) *int64

GetInt64 returns the int64 value at key. Returns nil if key is missing or value is nil. Caller must ensure the map is initialized (non-nil).

func (DynamicFields) GetModelId

func (this DynamicFields) GetModelId(key string) *model.Id

GetModelId returns the model.Id value at key. Returns nil if key is missing or value is nil. Caller must ensure the map is initialized (non-nil).

func (DynamicFields) GetString

func (this DynamicFields) GetString(key string) *string

GetString returns the string value at key. Returns nil if key is missing or value is nil. Caller must ensure the map is initialized (non-nil).

func (DynamicFields) GetStrings

func (this DynamicFields) GetStrings(key string) []string

func (DynamicFields) MustGetInt64

func (this DynamicFields) MustGetInt64(key string) (result int64)

func (DynamicFields) SetAny

func (this DynamicFields) SetAny(key string, v any)

func (DynamicFields) SetBool

func (this DynamicFields) SetBool(key string, v *bool)

func (DynamicFields) SetEtag

func (this DynamicFields) SetEtag(key string, v *model.Etag)

func (DynamicFields) SetInt

func (this DynamicFields) SetInt(key string, v *int)

func (DynamicFields) SetInt64

func (this DynamicFields) SetInt64(key string, v *int64)

func (DynamicFields) SetModelId

func (this DynamicFields) SetModelId(key string, v *model.Id)

SetModelId sets the model.Id value at key. Caller must ensure the map is initialized (non-nil).

func (DynamicFields) SetString

func (this DynamicFields) SetString(key string, v *string)

SetString sets the string value at key. Caller must ensure the map is initialized (non-nil).

func (DynamicFields) SetStrings

func (this DynamicFields) SetStrings(key string, v []string)

func (*DynamicFields) UnmarshalJSON

func (this *DynamicFields) UnmarshalJSON(data []byte) error

Implements json.Unmarshaler interface

func (*DynamicFields) UnmarshalText

func (this *DynamicFields) UnmarshalText(text []byte) error

Implements encoding.TextUnmarshaler interface

type DynamicModel

type DynamicModel interface {
	DynamicModelGetter
	DynamicModelSetter
}

type DynamicModelGetter

type DynamicModelGetter interface {
	GetFieldData() DynamicFields
}

type DynamicModelSetter

type DynamicModelSetter interface {
	SetFieldData(data DynamicFields)
}

type FieldBuilder

type FieldBuilder struct {
	// contains filtered or unexported fields
}

func DefineField

func DefineField() *FieldBuilder

func (*FieldBuilder) Build

func (this *FieldBuilder) Build() *ModelField

func (*FieldBuilder) DataType

func (this *FieldBuilder) DataType(dataType FieldDataType) *FieldBuilder

func (*FieldBuilder) Default

func (this *FieldBuilder) Default(val any) *FieldBuilder

Sets the default value for the field. Default value is only used for create operations and when the input field is nil. Read-only fields are always set to the default value regardless of the input. The precedence is: Default > DefaultFn > UseTypeDefault.

func (*FieldBuilder) DefaultFn

func (this *FieldBuilder) DefaultFn(fn func() any) *FieldBuilder

Registers a function to generate the default value for the field. Default value is only used for create operations and when the input field is nil. Read-only fields are always set to the default value regardless of the input. The precedence is: Default > DefaultFn > UseTypeDefault.

func (*FieldBuilder) Description

func (this *FieldBuilder) Description(description model.LangJson) *FieldBuilder

func (*FieldBuilder) Foreign

func (this *FieldBuilder) Foreign(relationBuilder *RelationBuilder) *FieldBuilder

func (*FieldBuilder) IsReadOnly

func (this *FieldBuilder) IsReadOnly(isReadOnly bool) *FieldBuilder

func (*FieldBuilder) IsRequired

func (this *FieldBuilder) IsRequired(isRequired bool) *FieldBuilder

func (*FieldBuilder) IsRequiredForCreate

func (this *FieldBuilder) IsRequiredForCreate(isRequired bool) *FieldBuilder

func (*FieldBuilder) IsRequiredForUpdate

func (this *FieldBuilder) IsRequiredForUpdate(isRequired bool) *FieldBuilder

func (*FieldBuilder) Label

func (this *FieldBuilder) Label(label model.LangJson) *FieldBuilder

func (*FieldBuilder) LabelRef

func (this *FieldBuilder) LabelRef(key string) *FieldBuilder

func (*FieldBuilder) Name

func (this *FieldBuilder) Name(name string) *FieldBuilder

func (*FieldBuilder) PrimaryKey

func (this *FieldBuilder) PrimaryKey() *FieldBuilder

func (*FieldBuilder) ReadOnly

func (this *FieldBuilder) ReadOnly() *FieldBuilder

Indicates that the field value cannot be set by user but by the system. Any input value will be silently ignored when creating or updating the model. If a default value is registered, it will be used in create operations.

func (*FieldBuilder) Required

func (this *FieldBuilder) Required() *FieldBuilder

Uses this for schemas which is used for validation and not for SQL generation.

func (*FieldBuilder) RequiredForCreate

func (this *FieldBuilder) RequiredForCreate() *FieldBuilder

Causes the field to be required for create operations, and determines the "NOT NULL" constraint for the database column. Missing field error will occur when the input value is nil and the field doesn't have a registered default value.

func (*FieldBuilder) RequiredForUpdate

func (this *FieldBuilder) RequiredForUpdate() *FieldBuilder

Causes the field to be required for update operations, but doesn't affect the generated CREATE SQL query. Missing field error will occur when the input value is nil REGARDLESS the field has a registered default value or not.

func (*FieldBuilder) Rule

func (this *FieldBuilder) Rule(rule FieldRule) *FieldBuilder

func (*FieldBuilder) SetUseTypeDefault

func (this *FieldBuilder) SetUseTypeDefault(useTypeDefault bool) *FieldBuilder

func (*FieldBuilder) TenantKey

func (this *FieldBuilder) TenantKey() *FieldBuilder

func (*FieldBuilder) Unique

func (this *FieldBuilder) Unique() *FieldBuilder

func (*FieldBuilder) UseTypeDefault

func (this *FieldBuilder) UseTypeDefault() *FieldBuilder

Indicates that the field should use the default value from the type definition. Default value is only used for create operations and when the input field is nil. Read-only fields are always set to the default value regardless of the input. The precedence is: Default > DefaultFn > UseTypeDefault.

func (*FieldBuilder) VersioningKey

func (this *FieldBuilder) VersioningKey() *FieldBuilder

Indicates that the field value is used for versioning the model, which means it is both read-only and required for update operations.

type FieldDataType

type FieldDataType interface {
	ArrayType() FieldDataType
	DefaultValue() value
	IsArray() bool
	Options() FieldDataTypeOptions
	String() string
	TryConvert(val any, options FieldDataTypeOptions) (value, error)
	Validate(val value) (value, *ft.ClientErrorItem)
}

FieldDataType defines the interface for dynamic field data types. Validate returns (validatedValue, nil) on success or (nil, ValidationError) on failure. Validate always runs TryConvert first to coerce the payload to the concrete storage type, then applies type-specific rules. Options are embedded in the data type; both use them internally.

func FieldDataTypeBoolean

func FieldDataTypeBoolean() FieldDataType

func FieldDataTypeDate

func FieldDataTypeDate() FieldDataType

func FieldDataTypeDateTime

func FieldDataTypeDateTime() FieldDataType

func FieldDataTypeDecimal

func FieldDataTypeDecimal(min string, max string, scale uint) FieldDataType

func FieldDataTypeEmail

func FieldDataTypeEmail() FieldDataType

func FieldDataTypeEnumInteger

func FieldDataTypeEnumInteger(enumValues []int64) FieldDataType

func FieldDataTypeEnumString

func FieldDataTypeEnumString(enumValues []string) FieldDataType

func FieldDataTypeEtag

func FieldDataTypeEtag() FieldDataType

func FieldDataTypeInt

func FieldDataTypeInt(min int, max int) FieldDataType

func FieldDataTypeInt64

func FieldDataTypeInt64(min int64, max int64) FieldDataType

func FieldDataTypeLangCode

func FieldDataTypeLangCode() FieldDataType

func FieldDataTypeLangJson

func FieldDataTypeLangJson(sanitizeType ...SanitizeType) FieldDataType

func FieldDataTypeModel

func FieldDataTypeModel() FieldDataType

FieldDataTypeModel represents a virtual/implicit field that holds a related model or slice of models. It is not persisted as a DB column; it is used for graph traversal and API response expansion.

func FieldDataTypePhone

func FieldDataTypePhone() FieldDataType

func FieldDataTypeSecret

func FieldDataTypeSecret() FieldDataType

func FieldDataTypeSlug

func FieldDataTypeSlug() FieldDataType

func FieldDataTypeString

func FieldDataTypeString(minLength int, maxLength int, sanitizeType ...SanitizeType) FieldDataType

func FieldDataTypeTime

func FieldDataTypeTime() FieldDataType

func FieldDataTypeUlid

func FieldDataTypeUlid() FieldDataType

func FieldDataTypeUrl

func FieldDataTypeUrl() FieldDataType

func FieldDataTypeUuid

func FieldDataTypeUuid() FieldDataType

type FieldDataTypeOptName

type FieldDataTypeOptName string

type FieldDataTypeOptions

type FieldDataTypeOptions map[FieldDataTypeOptName]any

type FieldRule

type FieldRule []any

func FieldRuleArrayLength

func FieldRuleArrayLength(min, max int) FieldRule

func (FieldRule) RuleName

func (this FieldRule) RuleName() FieldRuleName

func (FieldRule) RuleOptions

func (this FieldRule) RuleOptions() any

type FieldRuleName

type FieldRuleName string

type ForeignKeyColumnPair

type ForeignKeyColumnPair struct {
	FkColumn         string `json:"fk_column"`
	ReferencedColumn string `json:"referenced_column"`
}

ForeignKeyColumnPair describes one column of a (possibly composite) foreign key. FkColumn is always on the table that owns the FK constraint; ReferencedColumn is on the referenced table.

type M2mPeerLink struct {
	DestSchema      *ModelSchema
	ThroughSchema   *ModelSchema
	SrcFieldPrefix  string
	DestFieldPrefix string
	Edge            string
}

M2mPeerLink holds junction and FK-prefix metadata for a finalized many-to-many edge from the owning schema toward DestSchema (peer). Used by repositories to insert junction rows without a schema registry.

type ModelField

type ModelField struct {
	// contains filtered or unexported fields
}

func (*ModelField) Clone

func (this *ModelField) Clone() *ModelField

func (*ModelField) ColumnNullable

func (this *ModelField) ColumnNullable() string

ColumnNullable returns "NOT NULL" if required, else "NULL".

func (*ModelField) ColumnType

func (this *ModelField) ColumnType() string

ColumnType returns the SQL column type string (from DataType).

func (*ModelField) Copy

func (this *ModelField) Copy() *ModelField

Copy creates a new instance of ModelField with the same name, data type, and rules; other properties are not copied.

func (*ModelField) DataType

func (this *ModelField) DataType() FieldDataType

func (*ModelField) Default

func (this *ModelField) Default() *value

func (*ModelField) DefaultFn

func (this *ModelField) DefaultFn() func() any

func (*ModelField) Description

func (this *ModelField) Description() model.LangJson

func (*ModelField) IsArray

func (this *ModelField) IsArray() bool

func (*ModelField) IsNullable

func (this *ModelField) IsNullable() bool

IsNullable returns true if the column allows NULL.

func (*ModelField) IsPrimaryKey

func (this *ModelField) IsPrimaryKey() bool

func (*ModelField) IsReadOnly

func (this *ModelField) IsReadOnly() bool

func (*ModelField) IsRequiredForCreate

func (this *ModelField) IsRequiredForCreate() bool

func (*ModelField) IsRequiredForUpdate

func (this *ModelField) IsRequiredForUpdate() bool

func (*ModelField) IsTenantKey

func (this *ModelField) IsTenantKey() bool

func (*ModelField) IsUnique

func (this *ModelField) IsUnique() bool

func (*ModelField) IsVersioningKey

func (this *ModelField) IsVersioningKey() bool

func (*ModelField) IsVirtualModelField

func (this *ModelField) IsVirtualModelField() bool

IsVirtualModelField is true for FieldDataTypeModel (in-app only; no database column).

func (*ModelField) Label

func (this *ModelField) Label() model.LangJson

func (*ModelField) Name

func (this *ModelField) Name() string

Getter methods

func (*ModelField) Rules

func (this *ModelField) Rules() []*FieldRule

func (*ModelField) Validate

func (this *ModelField) Validate(val any, forEdit ...bool) (value, *ft.ClientErrorItem)

Validate invokes the field's data type Validate (which validates and may sanitize), then applies field rules. Returns the validated value and technical error if any. When value is empty: uses default if available; otherwise errors only when required with no fallback.

type ModelRelation

type ModelRelation struct {
	Edge         string       `json:"edge"`
	SrcField     string       `json:"src_field"`
	RelationType RelationType `json:"relation_type"`

	DestSchemaName string `json:"dest_schema_name"`
	DestField      string `json:"dest_field"`
	// ForeignKeys is the canonical multi-column FK. When empty, SrcField/DestField represent a single pair.
	ForeignKeys []ForeignKeyColumnPair `json:"foreign_keys,omitempty"`
	// UnvalidatedFkMap is consumed by SchemaRegistry.FinalizeRelations (src field name -> dest field name).
	UnvalidatedFkMap DynamicFields `json:"-"`
	// InversePeerSchemaName and InversePeerEdgeName are set by EdgeFrom / Existing() and cleared after finalize.
	InversePeerSchemaName string          `json:"inverse_peer_schema_name,omitempty"`
	InversePeerEdgeName   string          `json:"inverse_peer_edge_name,omitempty"`
	OnDelete              RelationCascade `json:"on_delete"`
	OnUpdate              RelationCascade `json:"on_update"`

	M2mThroughModel      *ModelSchema `json:"through_model,omitempty"`
	M2mThroughSchemaName string       `json:"through_table_name,omitempty"`
	// M2mSrcFieldPrefix is this (src) schema's junction-table FK prefix, not a single physical column name.
	// JOINs use PrefixedThroughColumn(M2mSrcFieldPrefix, pk) for each entry in this schema's PrimaryKeys(),
	// and PrefixedThroughColumn(M2mSrcFieldPrefix, tenantKey) when a tenant key exists (e.g. user -> user_id,
	// user_tenant_id). The peer (dest) side uses DestFieldPrefix the same way.
	M2mSrcFieldPrefix string `json:"src_field_prefix,omitempty"`
	// M2mDestFieldPrefix is the peer (dest) schema's junction FK prefix; set by FinalizeRelations.
	M2mDestFieldPrefix string `json:"dest_field_prefix,omitempty"`
	// contains filtered or unexported fields
}

func (ModelRelation) EffectiveForeignKeys

func (this ModelRelation) EffectiveForeignKeys() []ForeignKeyColumnPair

EffectiveForeignKeys returns the resolved FK column pairs for this relation.

type ModelSchema

type ModelSchema struct {
	// contains filtered or unexported fields
}

func GetOrRegisterSchema

func GetOrRegisterSchema(schemaName string, getBuilder func() *ModelSchemaBuilder) *ModelSchema

GetOrRegisterSchema first attempts to retrieve a registered schema by its name. If not found, it builds a new schema using the builder and registers it.

func GetSchema

func GetSchema(name string) *ModelSchema

GetSchema retrieves a registered schema by its name.

func MustGetSchema

func MustGetSchema(name string) *ModelSchema

MustGetSchema retrieves a registered schema by its name.

func (ModelSchema) AllUniques

func (this ModelSchema) AllUniques() [][]string

UniqueKeys returns all unique constraints (field-level and schema-level).

func (ModelSchema) Column

func (this ModelSchema) Column(name string) (*ModelField, bool)

Column returns the field by name (alias for Field for ORM compatibility).

func (ModelSchema) Columns

func (this ModelSchema) Columns() []*ModelField

Columns returns fields in definition order for SQL operations. Model-typed fields (virtual edge fields) are excluded as they have no DB column.

func (ModelSchema) CompositeUniques

func (this ModelSchema) CompositeUniques() [][]string

CompositeUniques returns schema-level composite UNIQUE constraints (all columns NOT NULL). Each inner slice is a group of field names.

func (ModelSchema) Description

func (this ModelSchema) Description() model.LangJson

func (ModelSchema) Field

func (this ModelSchema) Field(name string) (*ModelField, bool)

func (ModelSchema) Fields

func (this ModelSchema) Fields() map[string]*ModelField

func (ModelSchema) IsPrimaryKey

func (this ModelSchema) IsPrimaryKey(name string) bool

IsPrimaryKey returns true if the given field is a primary key.

func (ModelSchema) IsTenantKey

func (this ModelSchema) IsTenantKey(name string) bool

IsTenantKey returns true if the given field is the tenant key.

func (ModelSchema) IsVersioningKey

func (this ModelSchema) IsVersioningKey(name string) bool

IsVersioningKey returns true if the given field is an audit key.

func (ModelSchema) KeyColumns

func (this ModelSchema) KeyColumns() []string

KeyColumns returns primary keys plus tenant key if present.

func (ModelSchema) Label

func (this ModelSchema) Label() model.LangJson

func (*ModelSchema) M2mPeerLinkForDest

func (this *ModelSchema) M2mPeerLinkForDest(destSchemaName string) (*M2mPeerLink, bool)

M2mPeerLinkForDest returns the link for associating this schema with the given peer schema name.

func (ModelSchema) MustField

func (this ModelSchema) MustField(name string) *ModelField

func (ModelSchema) Name

func (this ModelSchema) Name() string

func (ModelSchema) PartialUniques

func (this ModelSchema) PartialUniques() [][]string

PartialUniques returns pairs of field names for partial unique indexes: UNIQUE (required column) WHERE (nullable column) IS NULL. Only populated after ShouldBuildDb / populateDbMetadata validation.

func (ModelSchema) Pick

func (this ModelSchema) Pick(fieldNames []string) *ModelSchema

Picks creates a new instance of ModelSchema with only the specified fields. Other information such as table name, labels, descriptions, etc. are not copied.

func (ModelSchema) PrimaryKeys

func (this ModelSchema) PrimaryKeys() []string

PrimaryKeys returns the list of primary key column names.

func (ModelSchema) Relations

func (this ModelSchema) Relations() []ModelRelation

func (ModelSchema) TableName

func (this ModelSchema) TableName() string

TableName returns the table name associated with this schema.

func (ModelSchema) TenantKey

func (this ModelSchema) TenantKey() string

TenantKey returns the tenant key column name, or empty if not tenant-scoped.

func (*ModelSchema) Validate

func (this *ModelSchema) Validate(input DynamicFields, forEdit ...bool) (DynamicFields, ft.ClientErrors)

ValidateMap validates each map key against the corresponding schema field by invoking ModelField.Validate. Returns a new map with validated and sanitized values, or (nil, ClientErrors) when invalid.

func (*ModelSchema) ValidateStruct

func (this *ModelSchema) ValidateStruct(target any, forEdit ...bool) (any, ft.ClientErrors)

ValidateStruct validates a struct pointer by converting to map and validating. Uses "json" struct tag: missing tag uses field name, tag "-" skips the field.

type ModelSchemaBuilder

type ModelSchemaBuilder struct {
	// contains filtered or unexported fields
}

func DefineModel

func DefineModel(name string) *ModelSchemaBuilder

func (*ModelSchemaBuilder) Build

func (this *ModelSchemaBuilder) Build() *ModelSchema

func (*ModelSchemaBuilder) CompositeUnique

func (this *ModelSchemaBuilder) CompositeUnique(composite ...string) *ModelSchemaBuilder

func (*ModelSchemaBuilder) CopyField

func (this *ModelSchemaBuilder) CopyField(schema *ModelSchema, fieldName string) *ModelSchemaBuilder

func (*ModelSchemaBuilder) CopyFieldN

func (this *ModelSchemaBuilder) CopyFieldN(schemaName string, fieldName string) *ModelSchemaBuilder

func (*ModelSchemaBuilder) Description

func (this *ModelSchemaBuilder) Description(description model.LangJson) *ModelSchemaBuilder

func (*ModelSchemaBuilder) EdgeFrom

func (*ModelSchemaBuilder) EdgeTo

func (*ModelSchemaBuilder) ExclusiveFieldGroup

func (this *ModelSchemaBuilder) ExclusiveFieldGroup(fieldNames []string) *ModelSchemaBuilder

ExclusiveFieldGroup registers one exclusive group: exactly one of the listed fields must be non-empty on validate. The slice may contain any number of field names (minimum two). Call multiple times to register multiple independent groups. Each name must exist on the schema when Build runs.

func (*ModelSchemaBuilder) ExclusiveFields

func (this *ModelSchemaBuilder) ExclusiveFields(fieldNames ...string) *ModelSchemaBuilder

ExclusiveFields is equivalent to ExclusiveFieldGroup(fieldNames) for a variadic argument list.

func (*ModelSchemaBuilder) Extend

func (*ModelSchemaBuilder) Field

func (this *ModelSchemaBuilder) Field(fieldBuilder *FieldBuilder) *ModelSchemaBuilder

func (*ModelSchemaBuilder) Label

func (*ModelSchemaBuilder) LabelRef

func (this *ModelSchemaBuilder) LabelRef(key string) *ModelSchemaBuilder

func (*ModelSchemaBuilder) Name

func (this *ModelSchemaBuilder) Name(name string) *ModelSchemaBuilder

func (*ModelSchemaBuilder) PartialUnique

func (this *ModelSchemaBuilder) PartialUnique(field1, field2 string) *ModelSchemaBuilder

PartialUnique registers a partial unique index on two columns: exactly one must be requiredForCreate (NOT NULL) and the other nullable. Enforced in Build() when ShouldBuildDb is set.

func (*ModelSchemaBuilder) SetCompositeUniques

func (this *ModelSchemaBuilder) SetCompositeUniques(allUniques [][]string) *ModelSchemaBuilder

func (*ModelSchemaBuilder) ShouldBuildDb

func (this *ModelSchemaBuilder) ShouldBuildDb() *ModelSchemaBuilder

func (*ModelSchemaBuilder) TableName

func (this *ModelSchemaBuilder) TableName(tableName string) *ModelSchemaBuilder

type ModelSchemaValidateOpts

type ModelSchemaValidateOpts struct {
	// Whether to validate for edit or create (default).
	ForEdit bool
}

type Operator

type Operator string
const (
	Equals        Operator = "="
	NotEquals     Operator = "!="
	GreaterThan   Operator = ">"
	GreaterEqual  Operator = ">="
	LessThan      Operator = "<"
	LessEqual     Operator = "<="
	Contains      Operator = "*"
	NotContains   Operator = "!*"
	StartsWith    Operator = "^"
	NotStartsWith Operator = "!^"
	EndsWith      Operator = "$"
	NotEndsWith   Operator = "!$"
	In            Operator = "in"
	NotIn         Operator = "not_in"
	IsSet         Operator = "is_set"
	IsNotSet      Operator = "not_set"
)

type OrderDirection

type OrderDirection string
const (
	Asc  OrderDirection = "asc"
	Desc OrderDirection = "desc"
)

type RelationBuilder

type RelationBuilder struct {
	// contains filtered or unexported fields
}

func Edge

func Edge(edgeName string) *RelationBuilder

func (*RelationBuilder) Build

func (this *RelationBuilder) Build() *ModelRelation

func (*RelationBuilder) Existing

func (this *RelationBuilder) Existing(srcSchemaName, srcEdgeName string) *RelationBuilder

func (*RelationBuilder) Label

func (this *RelationBuilder) Label(label model.LangJson) *RelationBuilder

func (*RelationBuilder) ManyToMany

func (this *RelationBuilder) ManyToMany(peerSchemaName, throughSchemaName, srcFieldPrefix string) *RelationBuilder

func (*RelationBuilder) ManyToOne

func (this *RelationBuilder) ManyToOne(destSchemaName string, srcDestKeyMap DynamicFields) *RelationBuilder

func (*RelationBuilder) OnDelete

func (this *RelationBuilder) OnDelete(onDelete RelationCascade) *RelationBuilder

func (*RelationBuilder) OnUpdate

func (this *RelationBuilder) OnUpdate(onUpdate RelationCascade) *RelationBuilder

func (*RelationBuilder) OneToMany

func (this *RelationBuilder) OneToMany(destSchemaName string, srcDestKeyMap DynamicFields) *RelationBuilder

func (*RelationBuilder) OneToOne

func (this *RelationBuilder) OneToOne(destSchemaName string, srcDestKeyMap DynamicFields) *RelationBuilder

type RelationCascade

type RelationCascade string

func (RelationCascade) Sql

func (this RelationCascade) Sql() string

Sql returns the SQL keyword for this cascade action, defaulting to NO ACTION for the zero value.

type RelationType

type RelationType string

type RelationValidator

type RelationValidator func(registry *SchemaRegistry, schemaName string, relation ModelRelation) error

type SanitizeType

type SanitizeType string

type SchemaGetter

type SchemaGetter interface {
	GetFieldData() DynamicFields
	GetSchema() *ModelSchema
}

type SchemaRegistry

type SchemaRegistry struct {
	// contains filtered or unexported fields
}

func GetSchemaRegistry

func GetSchemaRegistry() *SchemaRegistry

func (*SchemaRegistry) Field

func (this *SchemaRegistry) Field(schemaName string, fieldName string) *ModelField

func (*SchemaRegistry) FieldSafe

func (this *SchemaRegistry) FieldSafe(schemaName string, fieldName string) (*ModelField, error)

func (*SchemaRegistry) FinalizeRelations

func (this *SchemaRegistry) FinalizeRelations() error

FinalizeRelations runs all schema relation finalization after every model is registered: foreign-key map normalization, EdgeFrom peer resolution, then many-to-many junction wiring. Internal helpers must index reg.schemas directly instead of Get, because this method holds reg.mu.Lock and Get uses RLock (same goroutine would deadlock: RWMutex is not reentrant).

func (*SchemaRegistry) ForEach

func (this *SchemaRegistry) ForEach(fn func(schemaName string, schema *ModelSchema) error) error

func (*SchemaRegistry) ForEachOrder

func (this *SchemaRegistry) ForEachOrder(fn func(schemaName string, schema *ModelSchema) error) error

ForEachOrder iterates schemas in FK-dependency order (parents before children), suitable for generating CREATE TABLE statements in the correct sequence.

func (*SchemaRegistry) Get

func (this *SchemaRegistry) Get(name string) *ModelSchema

type SearchGraph

type SearchGraph struct {
	// contains filtered or unexported fields
}

func NewSearchGraph

func NewSearchGraph() *SearchGraph

func (*SearchGraph) And

func (this *SearchGraph) And(nodes ...SearchNode) *SearchGraph

func (*SearchGraph) Condition

func (this *SearchGraph) Condition(c Condition) *SearchGraph

func (*SearchGraph) GetAnd

func (this *SearchGraph) GetAnd() []SearchNode

func (*SearchGraph) GetCondition

func (this *SearchGraph) GetCondition() Condition

func (*SearchGraph) GetOr

func (this *SearchGraph) GetOr() []SearchNode

func (*SearchGraph) GetOrder

func (this *SearchGraph) GetOrder() SearchOrder

func (*SearchGraph) MarshalJSON

func (this *SearchGraph) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SearchGraph) NewCondition

func (this *SearchGraph) NewCondition(field string, operator Operator, values ...any) *SearchGraph

func (*SearchGraph) Or

func (this *SearchGraph) Or(nodes ...SearchNode) *SearchGraph

func (*SearchGraph) Order

func (this *SearchGraph) Order(o SearchOrder) *SearchGraph

func (*SearchGraph) OrderBy

func (this *SearchGraph) OrderBy(field string, direction ...OrderDirection) *SearchGraph

func (*SearchGraph) UnmarshalJSON

func (this *SearchGraph) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*SearchGraph) UnmarshalText

func (this *SearchGraph) UnmarshalText(text []byte) error

type SearchNode

type SearchNode struct {
	// contains filtered or unexported fields
}

func NewSearchNode

func NewSearchNode() *SearchNode

func (*SearchNode) And

func (this *SearchNode) And(nodes ...SearchNode) *SearchNode

func (*SearchNode) Condition

func (this *SearchNode) Condition(c Condition) *SearchNode

func (*SearchNode) GetAnd

func (this *SearchNode) GetAnd() []SearchNode

func (*SearchNode) GetCondition

func (this *SearchNode) GetCondition() Condition

func (*SearchNode) GetOr

func (this *SearchNode) GetOr() []SearchNode

func (*SearchNode) MarshalJSON

func (this *SearchNode) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SearchNode) NewCondition

func (this *SearchNode) NewCondition(field string, operator Operator, values ...any) *SearchNode

func (*SearchNode) Or

func (this *SearchNode) Or(nodes ...SearchNode) *SearchNode

func (*SearchNode) UnmarshalJSON

func (this *SearchNode) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type SearchOrder

type SearchOrder []SearchOrderItem

func NewSearchOrder

func NewSearchOrder(field string, direction ...OrderDirection) SearchOrder

func NewSearchOrderMulti

func NewSearchOrderMulti(items map[string]OrderDirection) SearchOrder

type SearchOrderItem

type SearchOrderItem []string

func NewSearchOrderItem

func NewSearchOrderItem(field string, direction ...OrderDirection) SearchOrderItem

func (SearchOrderItem) Direction

func (item SearchOrderItem) Direction() OrderDirection

func (SearchOrderItem) Field

func (item SearchOrderItem) Field() string

Jump to

Keyboard shortcuts

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