opts

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLPackagePGXV4    string = "pgx/v4"
	SQLPackagePGXV5    string = "pgx/v5"
	SQLPackageStandard string = "database/sql"
)
View Source
const (
	SQLDriverPGXV4            SQLDriver = "github.com/jackc/pgx/v4"
	SQLDriverPGXV5                      = "github.com/jackc/pgx/v5"
	SQLDriverLibPQ                      = "github.com/lib/pq"
	SQLDriverGoSQLDriverMySQL           = "github.com/go-sql-driver/mysql"
)

Variables

This section is empty.

Functions

func ValidateOpts

func ValidateOpts(opts *Options) error

Types

type GlobalOptions

type GlobalOptions struct {
	Overrides []Override        `json:"overrides,omitempty" yaml:"overrides"`
	Rename    map[string]string `json:"rename,omitempty" yaml:"rename"`
}

type GoStructTag

type GoStructTag string

GoStructTag is a raw Go struct tag.

type GoType

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

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

func (*GoType) UnmarshalJSON

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

func (*GoType) UnmarshalYAML

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

type Options

type Options struct {
	EmitInterface               bool              `json:"emit_interface" yaml:"emit_interface"`
	EmitJsonTags                bool              `json:"emit_json_tags" yaml:"emit_json_tags"`
	JsonTagsIdUppercase         bool              `json:"json_tags_id_uppercase" yaml:"json_tags_id_uppercase"`
	EmitDbTags                  bool              `json:"emit_db_tags" yaml:"emit_db_tags"`
	EmitPreparedQueries         bool              `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
	EmitExactTableNames         bool              `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
	EmitEmptySlices             bool              `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
	EmitExportedQueries         bool              `json:"emit_exported_queries" yaml:"emit_exported_queries"`
	EmitResultStructPointers    bool              `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
	EmitParamsStructPointers    bool              `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
	EmitMethodsWithDbArgument   bool              `json:"emit_methods_with_db_argument,omitempty" yaml:"emit_methods_with_db_argument"`
	EmitPointersForNullTypes    bool              `json:"emit_pointers_for_null_types" yaml:"emit_pointers_for_null_types"`
	EmitEnumValidMethod         bool              `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
	EmitAllEnumValues           bool              `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
	EmitSqlAsComment            bool              `json:"emit_sql_as_comment,omitempty" yaml:"emit_sql_as_comment"`
	JsonTagsCaseStyle           string            `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
	Package                     string            `json:"package" yaml:"package"`
	Out                         string            `json:"out" yaml:"out"`
	Overrides                   []Override        `json:"overrides,omitempty" yaml:"overrides"`
	Rename                      map[string]string `json:"rename,omitempty" yaml:"rename"`
	SqlPackage                  string            `json:"sql_package" yaml:"sql_package"`
	SqlDriver                   string            `json:"sql_driver" yaml:"sql_driver"`
	OutputBatchFileName         string            `json:"output_batch_file_name,omitempty" yaml:"output_batch_file_name"`
	OutputDbFileName            string            `json:"output_db_file_name,omitempty" yaml:"output_db_file_name"`
	OutputModelsFileName        string            `json:"output_models_file_name,omitempty" yaml:"output_models_file_name"`
	OutputQuerierFileName       string            `json:"output_querier_file_name,omitempty" yaml:"output_querier_file_name"`
	OutputCopyfromFileName      string            `json:"output_copyfrom_file_name,omitempty" yaml:"output_copyfrom_file_name"`
	OutputFilesSuffix           string            `json:"output_files_suffix,omitempty" yaml:"output_files_suffix"`
	InflectionExcludeTableNames []string          `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names"`
	QueryParameterLimit         *int32            `json:"query_parameter_limit,omitempty" yaml:"query_parameter_limit"`
	OmitSqlcVersion             bool              `json:"omit_sqlc_version,omitempty" yaml:"omit_sqlc_version"`
	OmitUnusedStructs           bool              `json:"omit_unused_structs,omitempty" yaml:"omit_unused_structs"`
	BuildTags                   string            `json:"build_tags,omitempty" yaml:"build_tags"`
	Initialisms                 *[]string         `json:"initialisms,omitempty" yaml:"initialisms"`

	InitialismsMap map[string]struct{} `json:"-" yaml:"-"`
}

func Parse

func Parse(req *plugin.GenerateRequest) (*Options, error)

type Override

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

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

type ParsedGoType

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

type SQLDriver added in v1.26.0

type SQLDriver string

func (SQLDriver) IsGoSQLDriverMySQL added in v1.26.0

func (d SQLDriver) IsGoSQLDriverMySQL() bool

func (SQLDriver) IsPGX added in v1.26.0

func (d SQLDriver) IsPGX() bool

func (SQLDriver) Package added in v1.26.0

func (d SQLDriver) Package() string

type ShimGoType

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

type ShimOverride

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.

Jump to

Keyboard shortcuts

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