Documentation
¶
Overview ¶
Package sql_adaptor provides functions to convert a goven query to a valid and safe SQL query.
Index ¶
- func FieldParseValidatorFromStruct(gorm reflect.Value) map[string]ParseValidateFunc
- func IntegerValidator(s string) error
- func NullValidator(_ string) error
- func NumericValidator(s string) error
- func StringSliceToInterfaceSlice(slice []string) []interface{}
- type ParseValidateFunc
- type SqlAdaptor
- type SqlResponse
- type ValidatorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldParseValidatorFromStruct ¶
func FieldParseValidatorFromStruct(gorm reflect.Value) map[string]ParseValidateFunc
FieldParseValidatorFromStruct takes the reflection of your database object and returns a map of fieldnames to ParseValidateFuncs. Don't panic - reflection is only used once on initialisation.
func IntegerValidator ¶
IntegerValidator validates that the input is an integer.
func NullValidator ¶
NullValidator is a no-op validator on a string, always returns nil error.
func NumericValidator ¶
NumericValidator validates that the input is a number.
func StringSliceToInterfaceSlice ¶
func StringSliceToInterfaceSlice(slice []string) []interface{}
StringSliceToInterfaceSlice is a helper function for making gorm queries.
Types ¶
type ParseValidateFunc ¶
type ParseValidateFunc = func(ex *parser.Expression) (*SqlResponse, error)
ParseValidateFunc takes an Expression from the AST and returns a templated SQL query.
func DefaultMatcherWithValidator ¶
func DefaultMatcherWithValidator(validate ValidatorFunc) ParseValidateFunc
DefaultMatcherWithValidator wraps the default matcher with validation on the value.
type SqlAdaptor ¶
type SqlAdaptor struct {
// contains filtered or unexported fields
}
SqlAdaptor represents the adaptor tailored to your database schema.
func NewDefaultAdaptorFromStruct ¶
func NewDefaultAdaptorFromStruct(gorm reflect.Value) *SqlAdaptor
NewDefaultAdaptorFromStruct returns a new basic SqlAdaptor from the reflection of your database object.
func NewSqlAdaptor ¶
func NewSqlAdaptor(fieldMappings map[string]string, defaultFields map[string]ParseValidateFunc, matchers map[*regexp.Regexp]ParseValidateFunc) *SqlAdaptor
NewSqlAdaptor returns a SqlAdaptor populated with the provided arguments.
func (*SqlAdaptor) Parse ¶
func (s *SqlAdaptor) Parse(str string) (*SqlResponse, error)
Parse takes a string goven query and returns a SqlResponse that can be executed against your database.
type SqlResponse ¶
SqlResponse is an object that stores the raw query, and the values to interpolate.
func DefaultMatcher ¶
func DefaultMatcher(ex *parser.Expression) *SqlResponse
DefaultMatcher takes an expression and spits out the default SqlResponse.
type ValidatorFunc ¶
ValidatorFunc takes a field name and validates that it is a legal/correct format.