codegen

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: GPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GenerateDefinerTemplate = "attrs_definer.tmpl"
	GenerateModelsTemplate  = "models_interface.tmpl"
	GenerateAdminTemplate   = "admin_setup.tmpl"
)
View Source
const (
	RelNone relationType = iota
	RelOneToOne
	RelForeignKey
	RelManyToMany
)

Variables

View Source
var (
	Prefixes = map[string]string{
		GenerateDefinerTemplate: "godjango_definer",
		GenerateModelsTemplate:  "godjango_models",
		GenerateAdminTemplate:   "godjango_admin",
	}
)

Functions

func DataType added in v1.6.8

func DataType(n *plugin.Identifier) string

func MatchString added in v1.6.8

func MatchString(pat, target string) bool

Types

type Attribute added in v1.6.9

type Attribute struct {
	Key   string
	Value string
}

type Choice

type Choice struct {
	Name  string
	Value string
}

type Choices

type Choices struct {
	Name    string
	Choices []Choice
}

type CodeGenerator

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

func (*CodeGenerator) BuildTemplateObject

func (c *CodeGenerator) BuildTemplateObject(schema *plugin.Schema) *TemplateObject

func (*CodeGenerator) Render

func (c *CodeGenerator) Render(w io.Writer, name string, obj *TemplateObject) error

type CodeGeneratorOptions

type CodeGeneratorOptions struct {
	Initialisms           []string          `json:"initialisms"`
	Rename                map[string]string `json:"rename"`
	PackageName           string            `json:"package"`
	InflectionExclusions  []string          `json:"inflection_exclusions"`
	OutFile               string            `json:"out"`
	EmitPointersForNull   bool              `json:"emit_pointers_for_null"`
	GenerateAdminSetup    bool              `json:"generate_admin_setup"`
	GenerateModelsMethods bool              `json:"generate_models_methods"`
	Overrides             []*Override       `json:"overrides"`
	// contains filtered or unexported fields
}

func (*CodeGeneratorOptions) GoName

func (c *CodeGeneratorOptions) GoName(name string) string

func (*CodeGeneratorOptions) InflectSingular

func (s *CodeGeneratorOptions) InflectSingular(name string) string

type Field

type Field struct {
	Name                         string
	ColumnName                   string
	Null                         bool
	Blank                        bool
	ReadOnly                     bool
	Primary                      bool
	Choices                      string
	Label                        string
	HelpText                     string
	RelatedObjectName            string
	RelatedObjectPackage         string
	RelatedObjectPackageAdressor string
	RelationType                 relationType
	WidgetAttrs                  []Attribute
	GoType                       string
}

func (*Field) GetHelpText added in v1.6.8

func (f *Field) GetHelpText() string

func (*Field) GetLabel added in v1.6.8

func (f *Field) GetLabel() string

func (*Field) IsForeignKey added in v1.6.9

func (f *Field) IsForeignKey() bool

func (*Field) IsManyToMany added in v1.6.9

func (f *Field) IsManyToMany() bool

func (*Field) IsOneToOne added in v1.6.9

func (f *Field) IsOneToOne() bool

type GoStructTag added in v1.6.8

type GoStructTag string

GoStructTag is a raw Go struct tag.

type GoType added in v1.6.8

type GoType struct {
	Path    string `json:"import" yaml:"import"`
	Package string `json:"package" yaml:"package"`
	Name    string `json:"type" yaml:"type"`
	Pointer bool   `json:"pointer" yaml:"pointer"`
	Slice   bool   `json:"slice" yaml:"slice"`
	Spec    string `json:"-"`
	BuiltIn bool   `json:"-"`
}

func (*GoType) MarshalJSON added in v1.6.8

func (o *GoType) MarshalJSON() ([]byte, error)

func (*GoType) UnmarshalJSON added in v1.6.8

func (o *GoType) UnmarshalJSON(data []byte) error

func (*GoType) UnmarshalYAML added in v1.6.8

func (o *GoType) UnmarshalYAML(unmarshal func(interface{}) error) error

type Import added in v1.6.8

type Import struct {
	Package string
	Alias   string
}

func (*Import) String added in v1.6.8

func (i *Import) String() string

type Override added in v1.6.8

type Override struct {
	// name of the golang type to use, e.g. `github.com/segmentio/ksuid.KSUID`
	GoType GoType `json:"go_type" yaml:"go_type"`

	// additional Go struct tags to add to this field, in raw Go struct tag form, e.g. `validate:"required" x:"y,z"`
	// see https://github.com/sqlc-dev/sqlc/issues/534
	GoStructTag GoStructTag `json:"go_struct_tag" yaml:"go_struct_tag"`

	// fully qualified name of the Go type, e.g. `github.com/segmentio/ksuid.KSUID`
	DBType                  string `json:"db_type" yaml:"db_type"`
	Deprecated_PostgresType string `json:"postgres_type" yaml:"postgres_type"`

	// for global overrides only when two different engines are in use
	Engine string `json:"engine,omitempty" yaml:"engine"`

	// True if the GoType should override if the matching type is nullable
	Nullable bool `json:"nullable" yaml:"nullable"`

	// True if the GoType should override if the matching type is unsiged.
	Unsigned bool `json:"unsigned" yaml:"unsigned"`

	// Deprecated. Use the `nullable` property instead
	Deprecated_Null bool `json:"null" yaml:"null"`

	// fully qualified name of the column, e.g. `accounts.id`
	Column string `json:"column" yaml:"column"`

	ColumnName   *pattern.Match `json:"-"`
	TableCatalog *pattern.Match `json:"-"`
	TableSchema  *pattern.Match `json:"-"`
	TableRel     *pattern.Match `json:"-"`
	GoImportPath string         `json:"-"`
	GoPackage    string         `json:"-"`
	GoTypeName   string         `json:"-"`
	GoBasicType  bool           `json:"-"`

	// Parsed form of GoStructTag, e.g. {"validate:", "required"}
	GoStructTags map[string]string `json:"-"`
	ShimOverride *ShimOverride     `json:"-"`
}

func (*Override) Matches added in v1.6.8

func (o *Override) Matches(n *plugin.Identifier, defaultSchema string) bool

type ParsedGoType added in v1.6.8

type ParsedGoType struct {
	ImportPath string
	Package    string
	TypeName   string
	BasicType  bool
	StructTag  string
}

type ShimGoType added in v1.6.8

type ShimGoType struct {
	ImportPath string
	Package    string
	TypeName   string
	BasicType  bool
	StructTags map[string]string
}

type ShimOverride added in v1.6.8

type ShimOverride struct {
	DbType     string
	Nullable   bool
	Column     string
	Table      *plugin.Identifier
	ColumnName string
	Unsigned   bool
	GoType     *ShimGoType
}

The ShimOverride struct exists to bridge the gap between the Override struct and the previous Override struct defined in codegen.proto. Eventually these shim structs should be removed in favor of using the existing Override and GoType structs, but it's easier to provide these shim structs to not change the existing, working code.

type Struct

type Struct struct {
	Name               string
	PluralName         string
	PrimaryField       Field
	PrimaryFieldColumn string
	TableName          string
	Fields             []Field
	InsertableFields   []Field
}

type TemplateObject

type TemplateObject struct {
	PackageName string
	SQLCVersion string
	Structs     []*Struct
	Choices     []*Choices
	// contains filtered or unexported fields
}

func (*TemplateObject) AddImport added in v1.6.8

func (t *TemplateObject) AddImport(imp Import)

func (*TemplateObject) Imports added in v1.6.8

func (t *TemplateObject) Imports() []Import

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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