Documentation ¶
Overview ¶
Package pkg is the public lib of SQLTemplate. SQLTemplate is a simple template engine for writing dynamic SQL queries.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBindingEngine ¶ added in v0.12.0
func NewBindingEngine() bindingEngine
NewBindingEngine build a binding engine based on the default binding engine.
Types ¶
type DefaultBindingEngine ¶ added in v0.12.0
type DefaultBindingEngine struct {
// contains filtered or unexported fields
}
DefaultBindingEngine is a base engine to handle bindings (placeholder "?" for MySQL-like dbe). It can be oveload to provide other type if bindings (placeholder "$i" for PostgreSQL-like dbe).
func (*DefaultBindingEngine) SetPlaceholderFunc ¶ added in v0.12.0
func (b *DefaultBindingEngine) SetPlaceholderFunc(placeholderfunc placeholderFunc)
SetPlaceholderFunc allows to set custom placeholder function.
type Option ¶
type Option func(*templateEngine)
Option definition.
func WithBindingEngine ¶ added in v0.12.0
func WithBindingEngine(bEngine bindingEngine) Option
WithBindingEngine creates an Option func to set custom binding engine. nolint:deadcode
func WithPlaceholderFunc ¶ added in v0.12.0
func WithPlaceholderFunc(placeholderfunc placeholderFunc) Option
WithPlaceholderFunc creates an Option func to set custom placeholder function. nolint:deadcode
func WithTemplateFunctions ¶
func WithTemplateFunctions(funcMap txtTemplate.FuncMap) Option
WithTemplateFunctions creates an Option func to set template functions. nolint:deadcode
type QueryTemplate ¶
type QueryTemplate = Template
QueryTemplate is for backwards compatibility. Deprecated: use Template.
type QueryTemplateEngine ¶
type QueryTemplateEngine = TemplateEngine
QueryTemplateEngine is for backwards compatibility. Deprecated: use TemplateEngine.
type Template ¶ added in v0.13.0
type Template interface { // GetQuery returns the query containing named values. GetQuery() string // GetParams returns the values in order. GetParams() []interface{} }
Template is the interface implemented by types that holds the parsed template sql context.
type TemplateEngine ¶ added in v0.13.0
type TemplateEngine interface { // Parse parses a sql template and returns the 'Template'. Parse(namespace string, templateName string) (Template, error) // ParseWithValuesFromMap parses a sql template with values from a map and returns the 'Template'. ParseWithValuesFromMap(namespace string, templateName string, parameters map[string]interface{}) (Template, error) // ParseWithValuesFromStruct parses a sql template with values from a struct and returns the 'Template'. ParseWithValuesFromStruct(namespace string, templateName string, parameters interface{}) (Template, error) // Register registers a new namespace by template filesystem and extension. Register(namespace string, filesystem fs.FS, extensions string) error }
TemplateEngine is the interface implemented by types that can parse sql templates.
func NewQueryTemplateEngine
deprecated
func NewQueryTemplateEngine(options ...Option) TemplateEngine
Deprecated: use NewTemplateEngine.
func NewTemplateEngine ¶ added in v0.13.0
func NewTemplateEngine(options ...Option) TemplateEngine
NewTemplateEngine returns a new instance of 'TemplateEngine'.