config

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidQueryParameterLimit = errors.New("invalid query parameter limit")
View Source
var ErrMissingEngine = errors.New("unknown engine")
View Source
var ErrMissingVersion = errors.New("no version number")
View Source
var ErrNoOutPath = errors.New("no output path")
View Source
var ErrNoPackageName = errors.New("missing package name")
View Source
var ErrNoPackagePath = errors.New("missing package path")
View Source
var ErrNoPackages = errors.New("no packages")
View Source
var ErrNoQuerierType = errors.New("no querier emit type enabled")
View Source
var ErrPluginBothTypes = errors.New("plugin: both `process` and `wasm` cannot both be defined")
View Source
var ErrPluginBuiltin = errors.New("a built-in plugin with that name already exists")
View Source
var ErrPluginExists = errors.New("a plugin with that name already exists")
View Source
var ErrPluginNoName = errors.New("missing plugin name")
View Source
var ErrPluginNoType = errors.New("plugin: field `process` or `wasm` required")
View Source
var ErrPluginNotFound = errors.New("no plugin found")
View Source
var ErrPluginProcessNoCmd = errors.New("plugin: missing process command")
View Source
var ErrUnknownEngine = errors.New("invalid engine")
View Source
var ErrUnknownVersion = errors.New("invalid version number")

Functions

func Validate added in v1.11.0

func Validate(c *Config) error

Types

type Cloud added in v1.18.0

type Cloud struct {
	Organization string `json:"organization" yaml:"organization"`
	Project      string `json:"project" yaml:"project"`
	Hostname     string `json:"hostname" yaml:"hostname"`
}

type Codegen added in v1.14.0

type Codegen struct {
	Out     string    `json:"out" yaml:"out"`
	Plugin  string    `json:"plugin" yaml:"plugin"`
	Options yaml.Node `json:"options" yaml:"options"`
}

TODO: Figure out a better name for this

type CombinedSettings

type CombinedSettings struct {
	Global    Config
	Package   SQL
	Go        SQLGo
	JSON      SQLJSON
	Rename    map[string]string
	Overrides []Override

	// TODO: Combine these into a more usable type
	Codegen Codegen
}

func Combine

func Combine(conf Config, pkg SQL) CombinedSettings

type Config

type Config struct {
	Version string   `json:"version" yaml:"version"`
	Project Project  `json:"project" yaml:"project"`
	Cloud   Cloud    `json:"cloud" yaml:"cloud"`
	SQL     []SQL    `json:"sql" yaml:"sql"`
	Gen     Gen      `json:"overrides,omitempty" yaml:"overrides"`
	Plugins []Plugin `json:"plugins" yaml:"plugins"`
	Rules   []Rule   `json:"rules" yaml:"rules"`
}

func ParseConfig

func ParseConfig(rd io.Reader) (Config, error)

type Database added in v1.19.0

type Database struct {
	URI string `json:"uri" yaml:"uri"`
}

type Engine

type Engine string
const (
	EngineMySQL      Engine = "mysql"
	EnginePostgreSQL Engine = "postgresql"
	EngineSQLite     Engine = "sqlite"
)

type Gen

type Gen struct {
	Go *GenGo `json:"go,omitempty" yaml:"go"`
}

type GenGo

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

type GoStructTag added in v1.14.0

type GoStructTag string

GoStructTag is a raw Go struct tag.

func (GoStructTag) Parse added in v1.14.0

func (s GoStructTag) Parse() (map[string]string, error)

Parse parses and validates a GoStructTag. The output is in a form convenient for codegen.

Sample valid inputs/outputs:

In Out empty string {} `a:"b"` {"a": "b"} `a:"b" x:"y,z"` {"a": "b", "x": "y,z"}

type GoType added in v1.6.0

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
	BuiltIn bool
}

func (GoType) Parse added in v1.6.0

func (gt GoType) Parse() (*ParsedGoType, error)

validate GoType

func (*GoType) UnmarshalJSON added in v1.6.0

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

func (*GoType) UnmarshalYAML added in v1.6.0

func (o *GoType) UnmarshalYAML(unmarshal func(interface{}) error) 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/kyleconroy/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 Engine `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
	TableCatalog *pattern.Match
	TableSchema  *pattern.Match
	TableRel     *pattern.Match
	GoImportPath string
	GoPackage    string
	GoTypeName   string
	GoBasicType  bool

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

func (*Override) Matches added in v1.11.0

func (o *Override) Matches(n *ast.TableName, defaultSchema string) bool

func (*Override) Parse

func (o *Override) Parse() (err error)

type ParsedGoType added in v1.6.0

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

type Paths added in v1.2.0

type Paths []string

func (*Paths) UnmarshalJSON added in v1.2.0

func (p *Paths) UnmarshalJSON(data []byte) error

func (*Paths) UnmarshalYAML added in v1.2.0

func (p *Paths) UnmarshalYAML(unmarshal func(interface{}) error) error

type Plugin added in v1.14.0

type Plugin struct {
	Name    string `json:"name" yaml:"name"`
	Process *struct {
		Cmd string `json:"cmd" yaml:"cmd"`
	} `json:"process" yaml:"process"`
	WASM *struct {
		URL    string `json:"url" yaml:"url"`
		SHA256 string `json:"sha256" yaml:"sha256"`
	} `json:"wasm" yaml:"wasm"`
}

type Project added in v1.13.0

type Project struct {
	ID string `json:"id" yaml:"id"`
}

type PythonType added in v1.8.0

type PythonType struct {
	Module string `json:"module" yaml:"module"`
	Name   string `json:"name" yaml:"name"`
}

func (PythonType) IsSet added in v1.8.0

func (t PythonType) IsSet() bool

func (PythonType) TypeString added in v1.8.0

func (t PythonType) TypeString() string

type Rule added in v1.19.0

type Rule struct {
	Name string `json:"name" yaml:"name"`
	Rule string `json:"rule" yaml:"rule"`
	Msg  string `json:"message" yaml:"message"`
}

type SQL

type SQL struct {
	Engine               Engine    `json:"engine,omitempty" yaml:"engine"`
	Schema               Paths     `json:"schema" yaml:"schema"`
	Queries              Paths     `json:"queries" yaml:"queries"`
	Database             *Database `json:"database" yaml:"database"`
	StrictFunctionChecks bool      `json:"strict_function_checks" yaml:"strict_function_checks"`
	StrictOrderBy        *bool     `json:"strict_order_by" yaml:"strict_order_by"`
	Gen                  SQLGen    `json:"gen" yaml:"gen"`
	Codegen              []Codegen `json:"codegen" yaml:"codegen"`
	Rules                []string  `json:"rules" yaml:"rules"`
}

type SQLGen

type SQLGen struct {
	Go   *SQLGo   `json:"go,omitempty" yaml:"go"`
	JSON *SQLJSON `json:"json,omitempty" yaml:"json"`
}

type SQLGo

type SQLGo 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"`
	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"`
	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"`
	OmitUnusedStructs           bool              `json:"omit_unused_structs,omitempty" yaml:"omit_unused_structs"`
}

type SQLJSON added in v1.14.0

type SQLJSON struct {
	Out      string `json:"out" yaml:"out"`
	Indent   string `json:"indent,omitempty" yaml:"indent"`
	Filename string `json:"filename,omitempty" yaml:"filename"`
}

type V1GenerateSettings

type V1GenerateSettings struct {
	Version   string              `json:"version" yaml:"version"`
	Cloud     Cloud               `json:"cloud" yaml:"cloud"`
	Project   Project             `json:"project" yaml:"project"`
	Packages  []v1PackageSettings `json:"packages" yaml:"packages"`
	Overrides []Override          `json:"overrides,omitempty" yaml:"overrides,omitempty"`
	Rename    map[string]string   `json:"rename,omitempty" yaml:"rename,omitempty"`
	Rules     []Rule              `json:"rules" yaml:"rules"`
}

func (*V1GenerateSettings) Translate

func (c *V1GenerateSettings) Translate() Config

func (*V1GenerateSettings) ValidateGlobalOverrides

func (c *V1GenerateSettings) ValidateGlobalOverrides() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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