model

package
v0.0.0-...-f368e40 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

* @Author: Marlon.M * @Email: maiguangyang@163.com * @Date: 2025-12-22 13:38:16

Index

Constants

View Source
const (
	CREATE string = "Create"
	UPDATE string = "Update"
)

Variables

View Source
var YmlFileName = "dolphin.yml"

Functions

func All

func All[T any](items []T, predicate func(T) bool) bool

All returns true if all elements in the slice match the predicate.

func Any

func Any[T any](items []T, predicate func(T) bool) bool

Any returns true if any element in the slice matches the predicate.

func EnrichModel

func EnrichModel(m *Model) error

EnrichModel ...

func EnrichModelObjects

func EnrichModelObjects(m *Model) error

EnrichModelObjects ...

func Filter

func Filter[T any](items []T, predicate func(T) bool) []T

Filter returns a new slice containing only elements that match the predicate.

func Find

func Find[T any](items []T, predicate func(T) bool) (T, bool)

Find returns the first element matching the predicate, or the zero value if none found.

func GetRandomString

func GetRandomString(n int) string

func IndexOf

func IndexOf[T comparable](slice []T, item T) int

IndexOf returns the index of item in slice, or -1 if not found.

func Map

func Map[T any, R any](items []T, transform func(T) R) []R

Map transforms a slice using the provided function.

func PrintSchema

func PrintSchema(model Model) (string, error)

PrintSchema

func RegexpReplace

func RegexpReplace(str, start string, end string) string

RegexpReplace 正则截取:提取 start 和 end 之间的内容

Types

type Config

type Config struct {
	Package    string `json:"package"`
	Connection *struct {
		MaxIdleConnections *uint   `json:"maxIdleConnections"`
		ConnMaxLifetime    *string `json:"connMaxLifetime"`
		MaxOpenConnections *uint   `json:"maxOpenConnections"`
	} `json:"connection,omitempty"`
}

func LoadConfig

func LoadConfig() (c Config, err error)

func LoadConfigFromPath

func LoadConfigFromPath(p string) (c Config, err error)

func (*Config) ConnMaxLifetime

func (c *Config) ConnMaxLifetime() float64

func (*Config) MaxIdleConnections

func (c *Config) MaxIdleConnections() uint

func (*Config) MaxOpenConnections

func (c *Config) MaxOpenConnections() uint

type FilterMappingItem

type FilterMappingItem struct {
	Suffix      string
	Operator    string
	InputType   ast.Type
	ValueFormat string
}

FilterMappingItem 表示过滤器映射项

func (*FilterMappingItem) IsLike

func (f *FilterMappingItem) IsLike() bool

IsLike 判断是否为 LIKE 操作符

func (*FilterMappingItem) SuffixCamel

func (f *FilterMappingItem) SuffixCamel() string

SuffixCamel 返回后缀的驼峰形式

func (*FilterMappingItem) WrapValueVariable

func (f *FilterMappingItem) WrapValueVariable(v string) string

WrapValueVariable 用格式包装值变量

type Model

type Model struct {
	Doc *ast.Document
	// contains filtered or unexported fields
}

func Parse

func Parse(m string) (Model, error)

Parse

func (*Model) HasEnum

func (m *Model) HasEnum(name string) bool

HasEnum 判断模型是否有指定的枚举类型

func (*Model) HasFederatedTypes

func (m *Model) HasFederatedTypes() bool

func (*Model) HasObject

func (m *Model) HasObject(name string) bool

func (*Model) HasObjectExtension

func (m *Model) HasObjectExtension(name string) bool

func (*Model) HasScalar

func (m *Model) HasScalar(name string) bool

HasScalar 判断模型是否有指定的标量类型

func (*Model) Object

func (m *Model) Object(name string) Object

func (*Model) ObjectEntities

func (m *Model) ObjectEntities() []Object

func (*Model) ObjectExtension

func (m *Model) ObjectExtension(name string) ObjectExtension

func (*Model) ObjectExtensions

func (m *Model) ObjectExtensions() []ObjectExtension

func (*Model) ObjectShardings

func (m *Model) ObjectShardings() []Object

func (*Model) Objects

func (m *Model) Objects() []Object

func (*Model) SecretKey

func (m *Model) SecretKey() string

type Object

type Object struct {
	Def       *ast.ObjectDefinition
	Model     *Model
	Extension *ObjectExtension
}

func (*Object) Column

func (o *Object) Column(name string) *ObjectField

func (*Object) Columns

func (o *Object) Columns() []ObjectField

Columns ...

func (*Object) Directive

func (o *Object) Directive(name string) *ast.Directive

func (*Object) EntityName

func (o *Object) EntityName() string

func (*Object) Field

func (o *Object) Field(name string) *ObjectField

func (*Object) Fields

func (o *Object) Fields() []ObjectField

Fields ...

func (*Object) HasAnyRelationships

func (o *Object) HasAnyRelationships() bool

func (*Object) HasColumn

func (o *Object) HasColumn(name string) bool

func (*Object) HasDirective

func (o *Object) HasDirective(name string) bool

func (*Object) HasEmbeddedField

func (o *Object) HasEmbeddedField() bool

func (*Object) HasField

func (o *Object) HasField(name string) bool

func (*Object) HasPreloadableRelationships

func (o *Object) HasPreloadableRelationships() bool

func (*Object) HasRelationship

func (o *Object) HasRelationship(name string) bool

func (*Object) Interfaces

func (o *Object) Interfaces() []string

func (*Object) IsExtended

func (o *Object) IsExtended() bool

func (*Object) IsFederatedType

func (o *Object) IsFederatedType() bool

func (*Object) IsSharding

func (o *Object) IsSharding() bool

func (*Object) IsSkip

func (o *Object) IsSkip() bool

func (*Object) IsToManyColumn

func (o *Object) IsToManyColumn(c ObjectField) bool

func (*Object) LowerName

func (o *Object) LowerName() string

func (*Object) Name

func (o *Object) Name() string

Name ...

func (*Object) NeedsQueryResolver

func (o *Object) NeedsQueryResolver() bool

func (*Object) PluralName

func (o *Object) PluralName() string

func (*Object) PreloadableRelationships

func (o *Object) PreloadableRelationships() []*ObjectRelationship

func (*Object) Relationship

func (o *Object) Relationship(name string) *ObjectRelationship

func (*Object) Relationships

func (o *Object) Relationships() []*ObjectRelationship

func (*Object) TableName

func (o *Object) TableName() string

func (*Object) ToCamel

func (o *Object) ToCamel() string

func (*Object) ToLowerPluralName

func (o *Object) ToLowerPluralName() string

func (*Object) ToSnakeName

func (o *Object) ToSnakeName() string

func (*Object) ToSnakePluraName

func (o *Object) ToSnakePluraName() string

type ObjectExtension

type ObjectExtension struct {
	Def    *ast.TypeExtensionDefinition
	Model  *Model
	Object *Object
}

func (*ObjectExtension) ExtendsLocalObject

func (oe *ObjectExtension) ExtendsLocalObject() bool

func (*ObjectExtension) IsFederatedType

func (oe *ObjectExtension) IsFederatedType() bool

type ObjectField

type ObjectField struct {
	Def *ast.FieldDefinition
	Obj *Object
}

ObjectField 表示 GraphQL 对象的一个字段

func (*ObjectField) Arguments

func (o *ObjectField) Arguments() string

Arguments 返回格式化的 GraphQL 参数字符串

func (*ObjectField) ArgumentsValue

func (o *ObjectField) ArgumentsValue() []ObjectFieldInput

ArgumentsValue 返回字段的参数列表

func (*ObjectField) ColumnType

func (o *ObjectField) ColumnType() (value string)

ColumnType ...

func (*ObjectField) Directive

func (o *ObjectField) Directive(name string) *ast.Directive

Directive 获取字段上的指定指令

func (*ObjectField) EntityName

func (o *ObjectField) EntityName() string

EntityName 获取实体名称

func (*ObjectField) FilterMapping

func (o *ObjectField) FilterMapping() []FilterMappingItem

FilterMapping 返回字段的过滤器映射列表

func (*ObjectField) GetArgValue

func (o *ObjectField) GetArgValue(name string) map[string]map[string]string

GetArgValue 获取指令的参数值

func (*ObjectField) GetComment

func (o *ObjectField) GetComment() string

GetComment 获取字段的注释说明

func (*ObjectField) GetDefault

func (o *ObjectField) GetDefault() string

GetDefault 获取字段的默认显示设置

func (*ObjectField) GetRemark

func (o *ObjectField) GetRemark() string

GetRemark 获取字段的备注说明

func (*ObjectField) GetTableName

func (o *ObjectField) GetTableName() string

GetTableName 获取实体的表名

func (*ObjectField) GetType

func (o *ObjectField) GetType() string

GetType 获取字段的数据库类型

func (*ObjectField) GetValidator

func (o *ObjectField) GetValidator() string

GetValidator 获取字段的验证器类型

func (*ObjectField) GoType

func (o *ObjectField) GoType() string

GoType 返回字段对应的 Go 类型

func (*ObjectField) GoTypeWithPointer

func (o *ObjectField) GoTypeWithPointer() string

GoTypeWithPointer 返回带指针前缀的 Go 类型

func (*ObjectField) HasDirective

func (o *ObjectField) HasDirective(name string) bool

func (*ObjectField) HasName

func (o *ObjectField) HasName(name string) bool

HasName 检查字段是否具有指定名称

func (*ObjectField) HasTargetObject

func (o *ObjectField) HasTargetObject() bool

HasTargetObject 判断是否存在目标对象

func (*ObjectField) HasTargetObjectExtension

func (o *ObjectField) HasTargetObjectExtension() bool

HasTargetObjectExtension 判断目标对象是否有扩展

func (*ObjectField) HasTargetTypeWithIDField

func (o *ObjectField) HasTargetTypeWithIDField() bool

HasTargetTypeWithIDField 判断目标类型是否有 ID 字段

func (*ObjectField) InputType

func (o *ObjectField) InputType() ast.Type

InputType 返回字段的输入类型

func (*ObjectField) Inputs

func (o *ObjectField) Inputs() string

Inputs 返回格式化的 GraphQL 输入字符串

func (*ObjectField) IsColumn

func (o *ObjectField) IsColumn() bool

IsColumn 判断是否为数据库列

func (*ObjectField) IsCreataDocs

func (o *ObjectField) IsCreataDocs() bool

IsCreataDocs 判断字段是否应出现在创建文档中

func (*ObjectField) IsCreatable

func (o *ObjectField) IsCreatable() bool

IsCreatable 判断字段是否可用于创建操作

func (*ObjectField) IsEmbedded

func (o *ObjectField) IsEmbedded() bool

IsEmbedded 判断是否为嵌入字段

func (*ObjectField) IsEmbeddedColumn

func (o *ObjectField) IsEmbeddedColumn() bool

IsEmbeddedColumn 判断是否为嵌入式列

func (*ObjectField) IsEnumType

func (o *ObjectField) IsEnumType() bool

IsEnumType 判断是否为枚举类型

func (*ObjectField) IsHasUpperId

func (o *ObjectField) IsHasUpperId() bool

IsHasUpperId 判断是否为关系字段且包含 Id

func (*ObjectField) IsID

func (o *ObjectField) IsID() bool

IsID 判断是否为 ID 类型

func (*ObjectField) IsIdentifier

func (o *ObjectField) IsIdentifier() bool

IsIdentifier 判断是否为 ID 标识符字段

func (*ObjectField) IsInt

func (o *ObjectField) IsInt() bool

IsInt 判断是否为 Int 类型

func (*ObjectField) IsList

func (o *ObjectField) IsList() bool

IsList 判断是否为列表类型

func (*ObjectField) IsListType

func (o *ObjectField) IsListType() bool

IsListType 判断是否为列表类型(解包 NonNull 后)

func (*ObjectField) IsOptional

func (o *ObjectField) IsOptional() bool

IsOptional 判断是否为可选类型(非 NonNull)

func (*ObjectField) IsReadonlyType

func (o *ObjectField) IsReadonlyType() bool

IsReadonlyType 判断是否为只读类型

func (*ObjectField) IsRelationship

func (o *ObjectField) IsRelationship() bool

IsRelationship 判断是否为关系字段

func (*ObjectField) IsRelationshipIdentifier

func (o *ObjectField) IsRelationshipIdentifier() bool

IsRelationshipIdentifier 判断是否为关系 ID 字段(如 userId)

func (*ObjectField) IsRelationshipRequired

func (o *ObjectField) IsRelationshipRequired() bool

IsRelationshipRequired 判断关系是否为必填

func (*ObjectField) IsRequired

func (o *ObjectField) IsRequired() bool

IsRequired 判断是否为必填类型

func (*ObjectField) IsScalarType

func (o *ObjectField) IsScalarType() bool

IsScalarType 判断是否为标量类型

func (*ObjectField) IsSearchable

func (o *ObjectField) IsSearchable() bool

IsSearchable 判断字段是否可搜索

func (*ObjectField) IsShardingID

func (o *ObjectField) IsShardingID() bool

IsShardingID 判断是否为分片 ID 字段

func (*ObjectField) IsSortable

func (o *ObjectField) IsSortable() bool

IsSortable 判断字段是否可排序

func (*ObjectField) IsString

func (o *ObjectField) IsString() bool

IsString 判断是否为 String 类型

func (*ObjectField) IsUpdatable

func (o *ObjectField) IsUpdatable() bool

IsUpdatable 判断字段是否可用于更新操作

func (*ObjectField) IsWritableType

func (o *ObjectField) IsWritableType() bool

IsWritableType 判断是否为可写类型

func (*ObjectField) LowerName

func (o *ObjectField) LowerName() string

LowerName 返回字段名称的小驼峰形式

func (*ObjectField) MethodName

func (o *ObjectField) MethodName() string

MethodName 返回适用于 Go 方法的字段名称(首字母大写)

func (*ObjectField) ModelTags

func (o *ObjectField) ModelTags() string

ModelTags 生成字段的 GORM 模型标签

func (*ObjectField) Name

func (o *ObjectField) Name() string

Name 返回字段的原始名称

func (*ObjectField) NeedsQueryResolver

func (o *ObjectField) NeedsQueryResolver() bool

NeedsQueryResolver 判断是否需要查询解析器

func (*ObjectField) RelationshipName

func (o *ObjectField) RelationshipName() string

RelationshipName 返回关系名称(移除 ID 后缀)

func (*ObjectField) RelationshipTypeName

func (o *ObjectField) RelationshipTypeName() string

RelationshipTypeName 返回关系的类型名称

func (*ObjectField) TargetObject

func (o *ObjectField) TargetObject() *Object

TargetObject 返回目标对象

func (*ObjectField) TargetObjectExtension

func (o *ObjectField) TargetObjectExtension() *ObjectExtension

TargetObjectExtension 返回目标对象的扩展

func (*ObjectField) TargetType

func (o *ObjectField) TargetType() string

TargetType 返回字段的目标类型(解包 NonNull 和 List)

func (*ObjectField) ToSnakeName

func (o *ObjectField) ToSnakeName() string

ToSnakeName 返回字段名称的蛇形命名形式

func (*ObjectField) Type

func (o *ObjectField) Type() string

Type 返回字段的 GraphQL 类型名称

type ObjectFieldInput

type ObjectFieldInput struct {
	Def   *ast.InputValueDefinition
	Field *ObjectField
}

func (*ObjectFieldInput) IsListType

func (o *ObjectFieldInput) IsListType() bool

func (*ObjectFieldInput) Name

func (o *ObjectFieldInput) Name() string

func (*ObjectFieldInput) NonNullType

func (o *ObjectFieldInput) NonNullType() string

func (*ObjectFieldInput) Required

func (o *ObjectFieldInput) Required() bool

func (*ObjectFieldInput) TargetType

func (o *ObjectFieldInput) TargetType() string

type ObjectRelationship

type ObjectRelationship struct {
	Def *ast.FieldDefinition
	Obj *Object
}

func (*ObjectRelationship) BoolForRelationshipDirectiveAttribute

func (o *ObjectRelationship) BoolForRelationshipDirectiveAttribute(name string) (val bool, ok bool)

func (*ObjectRelationship) ChangesName

func (o *ObjectRelationship) ChangesName() string

func (*ObjectRelationship) ChangesType

func (o *ObjectRelationship) ChangesType() string

func (*ObjectRelationship) GoType

func (o *ObjectRelationship) GoType() string

func (*ObjectRelationship) InverseRelationship

func (o *ObjectRelationship) InverseRelationship() *ObjectRelationship

func (*ObjectRelationship) InverseRelationshipName

func (o *ObjectRelationship) InverseRelationshipName() string

func (*ObjectRelationship) IsDelete

func (o *ObjectRelationship) IsDelete() bool

func (*ObjectRelationship) IsMainRelationshipForManyToMany

func (o *ObjectRelationship) IsMainRelationshipForManyToMany() bool

func (*ObjectRelationship) IsManyToMany

func (o *ObjectRelationship) IsManyToMany() bool

func (*ObjectRelationship) IsManyToOne

func (o *ObjectRelationship) IsManyToOne() bool

func (*ObjectRelationship) IsMaster

func (o *ObjectRelationship) IsMaster() bool

func (*ObjectRelationship) IsNonNull

func (o *ObjectRelationship) IsNonNull() bool

func (*ObjectRelationship) IsOneToMany

func (o *ObjectRelationship) IsOneToMany() bool

func (*ObjectRelationship) IsOneToOne

func (o *ObjectRelationship) IsOneToOne() bool

func (*ObjectRelationship) IsSelfReferencing

func (o *ObjectRelationship) IsSelfReferencing() bool

func (*ObjectRelationship) IsToMany

func (o *ObjectRelationship) IsToMany() bool

func (*ObjectRelationship) IsToOne

func (o *ObjectRelationship) IsToOne() bool

func (*ObjectRelationship) JoinString

func (o *ObjectRelationship) JoinString() string

func (*ObjectRelationship) LowerName

func (o *ObjectRelationship) LowerName() string

func (*ObjectRelationship) MainRelationshipForManyToMany

func (o *ObjectRelationship) MainRelationshipForManyToMany() *ObjectRelationship

func (*ObjectRelationship) ManyToManyJoinTable

func (o *ObjectRelationship) ManyToManyJoinTable() string

func (*ObjectRelationship) MethodName

func (o *ObjectRelationship) MethodName() string

func (*ObjectRelationship) ModelTags

func (o *ObjectRelationship) ModelTags() string

func (*ObjectRelationship) Name

func (o *ObjectRelationship) Name() string

func (*ObjectRelationship) Preload

func (o *ObjectRelationship) Preload() bool

func (*ObjectRelationship) ReturnType

func (o *ObjectRelationship) ReturnType() string

func (*ObjectRelationship) StringForRelationshipDirectiveAttribute

func (o *ObjectRelationship) StringForRelationshipDirectiveAttribute(name string) (val string, ok bool)

func (*ObjectRelationship) Target

func (o *ObjectRelationship) Target() *Object

func (*ObjectRelationship) TargetType

func (o *ObjectRelationship) TargetType() string

func (*ObjectRelationship) TargetTypeToSnakeName

func (o *ObjectRelationship) TargetTypeToSnakeName() string

func (*ObjectRelationship) ToSnakeName

func (o *ObjectRelationship) ToSnakeName() string

func (*ObjectRelationship) ToSnakeRelationshipName

func (o *ObjectRelationship) ToSnakeRelationshipName() string

func (*ObjectRelationship) UpperRelationshipName

func (o *ObjectRelationship) UpperRelationshipName() string

func (*ObjectRelationship) ValueForRelationshipDirectiveAttribute

func (o *ObjectRelationship) ValueForRelationshipDirectiveAttribute(name string) (val interface{}, ok bool)

Jump to

Keyboard shortcuts

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