conditions

package
v0.0.0-...-0dc4617 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DestPackageKey = "dest_package"
)

Variables

View Source
var ErrFkNotInTypeFields = errors.New("fk not in type's fields")
View Source
var GenConditionsCmd = verdeter.BuildVerdeterCommand(verdeter.VerdeterConfig{
	Use:   "conditions",
	Short: "Generate conditions to query your objects using cql",
	Long:  `gen is the command you can use to generate conditions to query your objects using cql.`,
	Run:   GenerateConditions,
	Args:  cobra.MinimumNArgs(1),
})

Functions

func GenerateConditions

func GenerateConditions(_ *cobra.Command, args []string)

GenConditionsCmd Run func

Types

type CodeGenerator

type CodeGenerator[T any] interface {
	Into(file *File) error
	ForEachField(file *File, fields []Field) []T
}

type Condition

type Condition struct {
	FieldName             string
	FieldType             *jen.Statement
	FieldDefinition       *jen.Statement
	ConditionMethod       *jen.Statement
	PreloadRelationName   string
	PreloadRelationMethod *jen.Statement
	// contains filtered or unexported fields
}

func NewCondition

func NewCondition(destPkg string, objectType Type, field Field) *Condition

type ConditionsGenerator

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

func NewConditionsGenerator

func NewConditionsGenerator(object types.Object) *ConditionsGenerator

func (ConditionsGenerator) ForEachField

func (cg ConditionsGenerator) ForEachField(file *File, fields []Field) []Condition

Generate the conditions for each of the object's fields

func (ConditionsGenerator) Into

func (cg ConditionsGenerator) Into(file *File) error

Add conditions for an object in the file

type Field

type Field struct {
	Name         string
	NamePrefix   string
	Type         Type
	Embedded     bool
	Tags         GormTags
	ColumnPrefix string
}

func (Field) ChangeType

func (field Field) ChangeType(newType types.Type, fromPointer bool) Field

Create a new field with the same name and tags but a different type

func (Field) CompleteName

func (field Field) CompleteName() string

func (Field) GetType

func (field Field) GetType() types.Type

func (Field) IsModelID

func (field Field) IsModelID() bool

func (Field) IsNullable

func (field Field) IsNullable() bool

func (Field) IsUpdatable

func (field Field) IsUpdatable() bool

func (Field) TypeName

func (field Field) TypeName() string

Get field's type name

func (Field) TypeString

func (field Field) TypeString() string

Get field's type full string (pkg + name)

type File

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

func NewFile

func NewFile(destPkg, name string) *File

func (*File) Add

func (file *File) Add(codes ...jen.Code)

func (File) Save

func (file File) Save() error

Write generated file

type GormTag

type GormTag string

type GormTags

type GormTags map[GormTag]string

type JenParam

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

func NewJenParam

func NewJenParam() *JenParam

func (JenParam) GenericType

func (param JenParam) GenericType() *jen.Statement

func (*JenParam) SQLToBasicType

func (param *JenParam) SQLToBasicType(typeV Type)

func (*JenParam) ToBasicKind

func (param *JenParam) ToBasicKind(basicType *types.Basic)

func (*JenParam) ToBool

func (param *JenParam) ToBool()

func (JenParam) ToCustomType

func (param JenParam) ToCustomType(destPkg string, typeV Type)

func (*JenParam) ToSlice

func (param *JenParam) ToSlice()

func (*JenParam) ToString

func (param *JenParam) ToString()

type RelationGettersGenerator

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

func NewRelationGettersGenerator

func NewRelationGettersGenerator(object types.Object) *RelationGettersGenerator

func (RelationGettersGenerator) ForEachField

func (generator RelationGettersGenerator) ForEachField(file *File, fields []Field) []jen.Code

func (RelationGettersGenerator) Into

func (generator RelationGettersGenerator) Into(file *File) error

Add conditions for an object in the file

type Type

type Type struct {
	types.Type
	// contains filtered or unexported fields
}

func (Type) CQLModelStruct

func (t Type) CQLModelStruct() (*types.Struct, error)

Get the struct under type if it is a cql model Returns error if the type is not a cql model

func (Type) GetFK

func (t Type) GetFK(field Field) (*Field, error)

Returns the fk field of the type to the "field"'s object (another field that references that object)

func (Type) IsGormCustomType

func (t Type) IsGormCustomType() bool

Returns true if the type is a Gorm Custom type (https://gorm.io/docs/data_types.html)

func (Type) IsSQLNullableType

func (t Type) IsSQLNullableType() bool

Returns true if the type is a sql nullable type (sql.NullBool, sql.NullInt, etc.)

func (Type) Name

func (t Type) Name() string

Get the name of the type depending of the internal type

func (Type) Pkg

func (t Type) Pkg() *types.Package

Get the package of the type depending of the internal type

func (Type) WasPointer

func (t Type) WasPointer() bool

Returns true if the type used to be a pointer (pointers are transformed into the pointed type)

Jump to

Keyboard shortcuts

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