Documentation
¶
Index ¶
- Constants
- Variables
- type PropertyMapper
- type SQLCompiler
- func (sqlc *SQLCompiler) CompileCondition(annotatedCondition string) (string, error)
- func (sqlc *SQLCompiler) ReplaceIdentifier(swtype, id string) (string, error)
- func (sqlc *SQLCompiler) WithDialect(dialect SQLDialectEnum) *SQLCompiler
- func (sqlc *SQLCompiler) WithLogger(logger *logrus.Logger) *SQLCompiler
- func (sqlc *SQLCompiler) WithTypeMapper(tmpr *TypeMapper) *SQLCompiler
- type SQLDialectEnum
- type TypeMapper
Constants ¶
const ( JSONBObjectOperator = `->` JSONBTextOperator = `->>` JSONBExistsOperator = `?` )
JSONB operators
Variables ¶
var SQLStringLiteralReplacer = strings.NewReplacer(
`'`, `''`,
)
SQLStringLiteralReplacer is string Replacer for converting to SQL string literals
Functions ¶
This section is empty.
Types ¶
type PropertyMapper ¶ added in v0.2.3
type PropertyMapper struct {
TypeMapper *TypeMapper
SEALProperty string
SQLColumn string
JSONBOperator string
JSONBIntKeyFlag bool
}
PropertyMapper contains mapping parameters for Swagger properties
func NewPropertyMapper ¶ added in v0.2.3
func NewPropertyMapper(name string) *PropertyMapper
NewPropertyMapper returns new instance of PropertyMapper for specified property 'name'. The specified property can be "*" to allow matching of any property name, as long as there is no specific match. Note that these two statements are equivalent:
pmpr := NewPropertyMapper("tags")
pmpr := NewPropertyMapper("").WithSEALProperty("tags")
func (*PropertyMapper) ToSQLColumn ¶ added in v0.2.3
func (pmpr *PropertyMapper) ToSQLColumn(name string) *PropertyMapper
ToSQLColumn specifies what column name the property should map to. If column name specified is "*", then the column name will be whatever the input property name is that matched this PropertyMapper. For example, if ToSQLColumn("*") is specified and the input property name is "tags", then the column name in the converted SQL will be "tags".
func (*PropertyMapper) UseJSONBIntKeyFlag ¶ added in v0.2.3
func (pmpr *PropertyMapper) UseJSONBIntKeyFlag(flag bool) *PropertyMapper
UseJSONBIntKeyFlag specifies the JSONB integer index flag to use for converting indexed properties. The default is false. Only the DialectPostgres SQL dialect supports JSONB conversion.
func (*PropertyMapper) UseJSONBOperator ¶ added in v0.2.3
func (pmpr *PropertyMapper) UseJSONBOperator(op string) *PropertyMapper
UseJSONBOperator specifies the JSONB operator to use for converting indexed properties. The default is JSONBObjectOperator (ie: "->"). Only the DialectPostgres SQL dialect supports JSONB conversion.
func (*PropertyMapper) WithSEALProperty ¶ added in v0.2.3
func (pmpr *PropertyMapper) WithSEALProperty(name string) *PropertyMapper
WithSEALProperty specifies the property name, overriding the previously set name. Property name can be "*" to match any property. However a PropertyMapper with a more specific match takes precedence over "*".
type SQLCompiler ¶ added in v0.2.3
type SQLCompiler struct {
Logger *logrus.Logger
Dialect SQLDialectEnum
TypeMappers map[string]*TypeMapper
}
SQLCompiler contains SQL conversion parameters
func NewSQLCompiler ¶ added in v0.2.3
func NewSQLCompiler() *SQLCompiler
NewSQLCompiler returns new instance of SQLCompiler.
func (*SQLCompiler) CompileCondition ¶ added in v0.2.3
func (sqlc *SQLCompiler) CompileCondition(annotatedCondition string) (string, error)
CompileCondition compiles the given SEAL annotated condition string into an SQL condition string. Internally calls ReplaceIdentifier to perform type and property SQL mapping on SEAL identifiers.
func (*SQLCompiler) ReplaceIdentifier ¶ added in v0.2.3
func (sqlc *SQLCompiler) ReplaceIdentifier(swtype, id string) (string, error)
ReplaceIdentifier performs type and property SQL mapping on the given SEAL identifier "id". "swtype" is the swagger type for this identifier. If there is no mapping that matches "swtype" or "id", then original "id" is returned with nil error. Always returns original id on error.
For example, TypeMapper("ddi.ipam") will match swtype "ddi.ipam". TypeMapper("ddi.*") will also match swtype "ddi.ipam" if there is no TypeMapper("ddi.ipam").
For example, PropertyMapper("tags") will match id "ctx.tags". PropertyMapper("*") will also match id "ctx.tags" if there is no PropertyMapper("tags").
func (*SQLCompiler) WithDialect ¶ added in v0.2.3
func (sqlc *SQLCompiler) WithDialect(dialect SQLDialectEnum) *SQLCompiler
WithDialect specifies the SQL dialect for this compiler. Default is DialectUnknown.
func (*SQLCompiler) WithLogger ¶ added in v0.2.3
func (sqlc *SQLCompiler) WithLogger(logger *logrus.Logger) *SQLCompiler
WithLogger specifies the Logrus logger for this compiler. Default is logrus.StandardLogger().
func (*SQLCompiler) WithTypeMapper ¶ added in v0.2.3
func (sqlc *SQLCompiler) WithTypeMapper(tmpr *TypeMapper) *SQLCompiler
WithTypeMapper adds TypeMapper to this compiler. TypeMapper must be name-unique within compiler. When adding multiple TypeMapper with the same name, the most recent add wins.
type SQLDialectEnum ¶ added in v0.2.3
type SQLDialectEnum int
SQLDialectEnum enumerates SQL dialects
const ( DialectUnknown SQLDialectEnum = iota DialectPostgres )
SQL dialects
func (SQLDialectEnum) String ¶ added in v0.2.3
func (dia SQLDialectEnum) String() string
String satisfies fmt.Stringer interface
type TypeMapper ¶ added in v0.2.3
type TypeMapper struct {
SQLCompiler *SQLCompiler
SwaggerType string
SQLTable string
PptyMappers map[string]*PropertyMapper
}
TypeMapper contains mapping parameters for Swagger types
func NewTypeMapper ¶ added in v0.2.3
func NewTypeMapper(name string) *TypeMapper
NewTypeMapper returns new instance of NewTypeMapper for specified swagger type 'name'. The specified type can be "app.*" to allow matching of any application-specific swagger type name, as long as there is no specific match. Note that these two statements are equivalent:
tmpr := NewTypeMapper("ddi.ipam")
tmpr := NewTypeMapper("").WithSwaggerType("ddi.ipam")
func (*TypeMapper) ReplaceIdentifier ¶ added in v0.2.3
func (tmpr *TypeMapper) ReplaceIdentifier(swtype string, id string) (string, error)
ReplaceIdentifier performs type and property SQL mapping on the given SEAL identifier "id". "swtype" is the swagger type for this identifier. If there is no mapping that matches "swtype" or "id", then original "id" is returned with nil error. Always returns original id on error.
For example, TypeMapper("ddi.ipam") will match swtype "ddi.ipam". TypeMapper("ddi.*") will also match swtype "ddi.ipam" if there is no TypeMapper("ddi.ipam").
For example, PropertyMapper("tags") will match id "ctx.tags". PropertyMapper("*") will also match id "ctx.tags" if there is no PropertyMapper("tags").
func (*TypeMapper) ToSQLTable ¶ added in v0.2.3
func (tmpr *TypeMapper) ToSQLTable(name string) *TypeMapper
ToSQLTable specifies what table name the swagger type should map to. If table name specified is "*", then the table name will be whatever the input swagger type name is that matched this TypeMapper. For example, if ToSQLTable("*") is specified and the input swagger type name is "ddi.ipam", then the table name in the converted SQL will be "ipam".
func (*TypeMapper) WithPropertyMapper ¶ added in v0.2.3
func (tmpr *TypeMapper) WithPropertyMapper(pmpr *PropertyMapper) *TypeMapper
WithPropertyMapper adds PropertyMapper to this TypeMapper. PropertyMapper must be name-unique within TypeMapper. When adding multiple PropertyMapper with the same name, the most recent add wins.
func (*TypeMapper) WithSwaggerType ¶ added in v0.2.3
func (tmpr *TypeMapper) WithSwaggerType(name string) *TypeMapper
WithSwaggerType specifies the swagger type name, overriding the previously set name. Swagger type name can be "app.*" to match any application-specific swagger type. However a TypeMapper with a more specific match takes precedence over "app.*".