Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compiler ¶
type Compiler interface {
CompileBody(m *Method) (body string, needsStrconv bool, err error)
// Dialect returns the SQL dialect this Compiler was constructed for, so the generator
// can pick a dialect-specific method template (e.g. Postgres INSERT needs
// "RETURNING id" + QueryRowContext instead of ExecContext + LastInsertId).
Dialect() Dialect
}
Compiler compiles SQL template strings into Go source fragments.
func NewCompiler ¶
NewCompiler returns a Compiler for the given dialect.
type Config ¶
type Config struct {
Dialect Dialect `yaml:"dialect"`
Repositories map[string]*RepositoryEntry `yaml:"repositories"`
}
type ConfigPath ¶
type ConfigPath string
ConfigPath is the path to the simplesql config file, provided for DI.
type Import ¶
Import is a Go import referenced by a parsed interface's param/return types: a path with an optional local name — "" for a normal (unaliased) import, "_" for blank, "." for dot, or any other identifier for an explicit alias.
type Method ¶
type Method struct {
Name string
SQL string // raw SQL template text extracted from comments
QueryKind QueryKind
Params []Param
ReturnKind ReturnKind
ReturnType string // element type for single/slice, e.g. "User" (the "*"/"[]" markers are stripped)
ReturnIsPtr bool // for ReturnSlice: true for []*T, false for []T. Always true for ReturnSingle (*T is the only supported shape).
}
Method holds everything the generator needs about one interface method.
type Param ¶
type Param struct {
Name string
Type string // Go type expression, e.g. "*bool", "string", "[]*User"
IsPtr bool
}
Param is a method parameter.
type QueryKind ¶
type QueryKind string
QueryKind is the SQL statement type detected from the first keyword.
type RepositoryEntry ¶
type RepositoryEntry struct {
Output string `yaml:"output"`
StructName string `yaml:"struct_name"`
}
func (*RepositoryEntry) UnmarshalYAML ¶
func (r *RepositoryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML supports shorthand ("output.go") and full struct form.
type ReturnKind ¶
type ReturnKind string
ReturnKind describes what the method returns.
const ( ReturnNothing ReturnKind = "nothing" // () ReturnError ReturnKind = "error" // (error) ReturnSingle ReturnKind = "single" // (*T, error) ReturnSlice ReturnKind = "slice" // ([]*T, error) or ([]T, error) ReturnRowsOrID ReturnKind = "rows_or_id" // (int, error) )
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner orchestrates parsing and code generation for all repositories in a config.