Documentation
¶
Index ¶
- Constants
- Variables
- func DataType(n *plugin.Identifier) string
- func MatchString(pat, target string) bool
- type Choice
- type Choices
- type CodeGenerator
- type CodeGeneratorOptions
- type Field
- type GoStructTag
- type GoType
- type Import
- type Override
- type ParsedGoType
- type ShimGoType
- type ShimOverride
- type Struct
- type TemplateObject
Constants ¶
View Source
const ( GenerateDefinerTemplate = "attrs_definer.tmpl" GenerateModelsTemplate = "models_interface.tmpl" GenerateAdminTemplate = "admin_setup.tmpl" )
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
Types ¶
type CodeGenerator ¶
type CodeGenerator struct {
// contains filtered or unexported fields
}
func New ¶
func New(req *plugin.GenerateRequest, opts *CodeGeneratorOptions) (*CodeGenerator, error)
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
GoType string
}
func (*Field) GetHelpText ¶ added in v1.6.8
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 (*GoType) UnmarshalJSON ¶ added in v1.6.8
func (*GoType) UnmarshalYAML ¶ added in v1.6.8
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:"-"`
}
type ParsedGoType ¶ added in v1.6.8
type ShimGoType ¶ added in v1.6.8
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 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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.