Documentation
¶
Index ¶
- func EnumReplace(value string) string
- func EnumValueName(value string) string
- func Generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error)
- func IsReserved(s string) bool
- func JSONTagName(name string, options *opts.Options) string
- func SetCaseStyle(name string, style string) string
- func SetJSONCaseStyle(name string, style string, idUppercase bool) string
- func StructName(name string, options *opts.Options) string
- func TagsToString(tags map[string]string) string
- type Argument
- type Constant
- type DynFilterInfo
- type Enum
- type Field
- type FlagParam
- type ImportSpec
- type Query
- type QueryValue
- func (v QueryValue) ColumnNames() []string
- func (v QueryValue) ColumnNamesAsGoSlice() string
- func (v QueryValue) CopyFromMySQLFields() []Fielddeprecated
- func (v *QueryValue) DefineType() string
- func (v QueryValue) EmitStruct() bool
- func (v QueryValue) HasSqlcSlices() bool
- func (v QueryValue) IsPointer() bool
- func (v QueryValue) IsStruct() bool
- func (v QueryValue) Pair() string
- func (v QueryValue) Pairs() []Argument
- func (v QueryValue) Params() string
- func (v *QueryValue) ReturnName() string
- func (v QueryValue) Scan() string
- func (v QueryValue) SlicePair() string
- func (v QueryValue) Type() string
- func (v QueryValue) UniqueFields() []Field
- func (v QueryValue) VariableForField(f Field) string
- type Struct
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnumReplace ¶
EnumReplace removes all non ident symbols (all but letters, numbers and underscore) and returns valid ident name for provided name.
func EnumValueName ¶
EnumValueName removes all non ident symbols (all but letters, numbers and underscore) and converts snake case ident to camel case.
func Generate ¶
func Generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error)
func IsReserved ¶
func SetCaseStyle ¶
func TagsToString ¶
Types ¶
type DynFilterInfo ¶ added in v1.7.3
type DynFilterInfo struct {
// AnnotatedSQL is the SQL with -- :if replaced by -- :dynif N markers.
// N is the 0-based index into the full args slice passed to DynamicSQL.
// For SQL params: N = paramNumber - 1 (matches $N position in args).
// For flag-only params: N = numSQLParams + flagOffset.
AnnotatedSQL string
// ConditionalParamNumbers contains the $N numbers (1-based) of SQL params
// that are conditional and should become pointer types.
ConditionalParamNumbers []int
// FlagParams are extra bool params that need to be added to the params struct
// (params referenced in :if that are not actual SQL params).
FlagParams []FlagParam
// OrderedArgNames is the full ordered list of param names for the DynamicSQL
// call, indexed by their :dynif N value.
// Positions 0..numSQLParams-1 are SQL params (in $N order, all of them).
// Positions numSQLParams.. are flag-only params (in appearance order).
OrderedArgNames []string
}
DynFilterInfo holds the result of parsing :if annotations from a SQL query.
func ParseDynFilter ¶ added in v1.7.3
func ParseDynFilter(sql string, params []*plugin.Parameter) (*DynFilterInfo, error)
ParseDynFilter parses -- :if @param [... @paramN] annotations from SQL query text. params is the list of ALL SQL parameters (from sqlc).
The :dynif N index assigned to each annotation equals paramNumber-1 for SQL params, so that the DynamicSQL runtime can directly use args[N] ↔ $N+1. Flag-only params (ORDER BY flags not in SQL) get indices starting at len(params), and are appended to the DynamicSQL args after the SQL params.
Both inline and block syntax are supported:
AND b = $2 -- :if @b (inline, single) AND b = $2 -- :if @b @c (inline, multi — line removed if any is inactive) -- :if @b (block: applies to next line) AND b = $2
type Enum ¶
type Field ¶
type Field struct {
Name string // CamelCased name for Go
DBName string // Name as used in the DB
Type string
Tags map[string]string
Comment string
Column *plugin.Column
// EmbedFields contains the embedded fields that require scanning.
EmbedFields []Field
}
func (Field) HasSqlcSlice ¶
type FlagParam ¶ added in v1.7.3
type FlagParam struct {
// Name is the original @name from the :if annotation.
Name string
// GoName is the CamelCase Go field name.
GoName string
}
FlagParam represents a flag-only bool parameter (used in ORDER BY :if).
type ImportSpec ¶
func (ImportSpec) String ¶
func (s ImportSpec) String() string
type Query ¶
type Query struct {
Cmd string
Comments []string
MethodName string
FieldName string
ConstantName string
SQL string
SourceName string
Ret QueryValue
Arg QueryValue
// Used for :copyfrom
Table *plugin.Identifier
// HasDynFilter is true when the query has -- :if annotations and
// emit_dynamic_filter is enabled.
HasDynFilter bool
// DynFilterArgs is the pre-rendered args expression for the DynamicSQL call,
// e.g. "arg.A, arg.B, arg.C, arg.IdAsc, arg.IdDesc"
DynFilterArgs string
}
A struct used to generate methods and fields on the Queries struct
func (Query) TableIdentifierAsGoSlice ¶
func (Query) TableIdentifierForMySQL ¶
type QueryValue ¶
type QueryValue struct {
Emit bool
EmitPointer bool
Name string
DBName string // The name of the field in the database. Only set if Struct==nil.
Struct *Struct
Typ string
SQLDriver opts.SQLDriver
// Column is kept so late in the generation process around to differentiate
// between mysql slices and pg arrays
Column *plugin.Column
}
func (QueryValue) ColumnNames ¶
func (v QueryValue) ColumnNames() []string
func (QueryValue) ColumnNamesAsGoSlice ¶
func (v QueryValue) ColumnNamesAsGoSlice() string
func (QueryValue) CopyFromMySQLFields
deprecated
func (v QueryValue) CopyFromMySQLFields() []Field
Deprecated: This method does not respect the Emit field set on the QueryValue. It's used by the go-sql-driver-mysql/copyfromCopy.tmpl and should not be used other places.
func (*QueryValue) DefineType ¶
func (v *QueryValue) DefineType() string
func (QueryValue) EmitStruct ¶
func (v QueryValue) EmitStruct() bool
func (QueryValue) HasSqlcSlices ¶
func (v QueryValue) HasSqlcSlices() bool
When true, we have to build the arguments to q.db.QueryContext in addition to munging the SQL
func (QueryValue) IsPointer ¶
func (v QueryValue) IsPointer() bool
func (QueryValue) IsStruct ¶
func (v QueryValue) IsStruct() bool
func (QueryValue) Pair ¶
func (v QueryValue) Pair() string
func (QueryValue) Pairs ¶
func (v QueryValue) Pairs() []Argument
Return the argument name and type for query methods. Should only be used in the context of method arguments.
func (QueryValue) Params ¶
func (v QueryValue) Params() string
func (*QueryValue) ReturnName ¶
func (v *QueryValue) ReturnName() string
func (QueryValue) Scan ¶
func (v QueryValue) Scan() string
func (QueryValue) SlicePair ¶
func (v QueryValue) SlicePair() string
func (QueryValue) Type ¶
func (v QueryValue) Type() string
func (QueryValue) UniqueFields ¶
func (v QueryValue) UniqueFields() []Field
func (QueryValue) VariableForField ¶
func (v QueryValue) VariableForField(f Field) string