generators

package
v3.3.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2020 License: LGPL-2.1 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CassandraTypeMapping = SqlTypeMapping{
	Name:                 `cassandra`,
	StringType:           `VARCHAR`,
	IntegerType:          `INT`,
	FloatType:            `FLOAT`,
	BooleanType:          `TINYINT`,
	BooleanTypeLength:    1,
	DateTimeType:         `DATETIME`,
	ObjectType:           `MAP`,
	ArrayType:            `LIST`,
	RawType:              `BLOB`,
	SubtypeFormat:        `%s<%v>`,
	MultiSubtypeFormat:   `%s<%v,%v>`,
	PlaceholderFormat:    `TODO`,
	PlaceholderArgument:  `TODO`,
	TableNameFormat:      "%s",
	FieldNameFormat:      "%s",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var DefaultMinVersionCompat = float64(6)

Elasticsearch Generator

View Source
var DefaultSqlTypeMapping = GenericTypeMapping
View Source
var ElasticsearchExactMatchQueryType = `term`
View Source
var ElasticsearchFulltextDefaultConjunctionAnd = true
View Source
var GenericTypeMapping = SqlTypeMapping{
	Name:                 `generic`,
	StringType:           `VARCHAR`,
	StringTypeLength:     255,
	IntegerType:          `BIGINT`,
	FloatType:            `DECIMAL`,
	FloatTypeLength:      10,
	FloatTypePrecision:   8,
	BooleanType:          `BOOL`,
	DateTimeType:         `DATETIME`,
	ObjectType:           `BLOB`,
	ArrayType:            `BLOB`,
	RawType:              `BLOB`,
	PlaceholderFormat:    `?`,
	PlaceholderArgument:  ``,
	TableNameFormat:      "%s",
	FieldNameFormat:      "%s",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var MysqlTypeMapping = SqlTypeMapping{
	Name:                 `mysql`,
	StringType:           `VARCHAR`,
	StringTypeLength:     255,
	IntegerType:          `BIGINT`,
	FloatType:            `DECIMAL`,
	FloatTypeLength:      10,
	FloatTypePrecision:   8,
	BooleanType:          `BOOL`,
	DateTimeType:         `DATETIME`,
	ObjectType:           `MEDIUMBLOB`,
	ArrayType:            `MEDIUMBLOB`,
	RawType:              `MEDIUMBLOB`,
	PlaceholderFormat:    `?`,
	PlaceholderArgument:  ``,
	TableNameFormat:      "`%s`",
	FieldNameFormat:      "`%s`",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var NoTypeMapping = SqlTypeMapping{}
View Source
var PostgresJsonTypeMapping = SqlTypeMapping{
	Name:         `postgres-json`,
	StringType:   `TEXT`,
	IntegerType:  `BIGINT`,
	FloatType:    `NUMERIC`,
	BooleanType:  `BOOLEAN`,
	DateTimeType: `TIMESTAMP`,

	ObjectType:           `VARCHAR`,
	ArrayType:            `VARCHAR`,
	RawType:              `BYTEA`,
	PlaceholderFormat:    `$%d`,
	PlaceholderArgument:  `index1`,
	TableNameFormat:      "%q",
	FieldNameFormat:      "%q",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var PostgresTypeMapping = SqlTypeMapping{
	Name:                 `postgres`,
	StringType:           `TEXT`,
	IntegerType:          `BIGINT`,
	FloatType:            `NUMERIC`,
	BooleanType:          `BOOLEAN`,
	DateTimeType:         `TIMESTAMP`,
	ObjectType:           `VARCHAR`,
	ArrayType:            `VARCHAR`,
	RawType:              `BYTEA`,
	PlaceholderFormat:    `$%d`,
	PlaceholderArgument:  `index1`,
	TableNameFormat:      "%q",
	FieldNameFormat:      "%q",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var SqlJsonTypeDecoder = func(in []byte, out interface{}) error {
	return json.NewDecoder(bytes.NewReader(in)).Decode(out)
}
View Source
var SqlJsonTypeEncoder = func(in interface{}) ([]byte, error) {
	var buf bytes.Buffer
	err := json.NewEncoder(&buf).Encode(in)
	return buf.Bytes(), err
}
View Source
var SqlMaxPlaceholders = 16384
View Source
var SqliteTypeMapping = SqlTypeMapping{
	Name:                 `sqlite`,
	StringType:           `TEXT`,
	IntegerType:          `INTEGER`,
	FloatType:            `REAL`,
	BooleanType:          `INTEGER`,
	BooleanTypeLength:    1,
	DateTimeType:         `INTEGER`,
	ObjectType:           `BLOB`,
	ArrayType:            `BLOB`,
	RawType:              `BLOB`,
	PlaceholderFormat:    `?`,
	PlaceholderArgument:  ``,
	TableNameFormat:      "%q",
	FieldNameFormat:      "%q",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}

Functions

This section is empty.

Types

type Elasticsearch

type Elasticsearch struct {
	filter.Generator
	// contains filtered or unexported fields
}

func NewElasticsearchGenerator

func NewElasticsearchGenerator() *Elasticsearch

func (*Elasticsearch) AggregateByField

func (self *Elasticsearch) AggregateByField(agg filter.Aggregation, field string) error

func (*Elasticsearch) Finalize

func (self *Elasticsearch) Finalize(flt *filter.Filter) error

func (*Elasticsearch) GetValues

func (self *Elasticsearch) GetValues() []interface{}

func (*Elasticsearch) GroupByField

func (self *Elasticsearch) GroupByField(field string) error

func (*Elasticsearch) Initialize

func (self *Elasticsearch) Initialize(collectionName string) error

func (*Elasticsearch) SetMinimumVersion added in v3.1.12

func (self *Elasticsearch) SetMinimumVersion(v float64)

func (*Elasticsearch) SetOption

func (self *Elasticsearch) SetOption(key string, value interface{}) error

func (*Elasticsearch) WithCriterion

func (self *Elasticsearch) WithCriterion(criterion filter.Criterion) error

func (*Elasticsearch) WithField

func (self *Elasticsearch) WithField(field string) error

type MongoDB

type MongoDB struct {
	filter.Generator
	// contains filtered or unexported fields
}

func NewMongoDBGenerator

func NewMongoDBGenerator() *MongoDB

func (*MongoDB) AggregateByField

func (self *MongoDB) AggregateByField(agg filter.Aggregation, field string) error

func (*MongoDB) Finalize

func (self *MongoDB) Finalize(f *filter.Filter) error

func (*MongoDB) GetValues

func (self *MongoDB) GetValues() []interface{}

func (*MongoDB) GroupByField

func (self *MongoDB) GroupByField(field string) error

func (*MongoDB) Initialize

func (self *MongoDB) Initialize(collectionName string) error

func (*MongoDB) SetOption

func (self *MongoDB) SetOption(key string, value interface{}) error

func (*MongoDB) WithCriterion

func (self *MongoDB) WithCriterion(criterion filter.Criterion) error

func (*MongoDB) WithField

func (self *MongoDB) WithField(field string) error

type Sql

type Sql struct {
	filter.Generator
	FieldWrappers    map[string]string      // map of field name-format strings to wrap specific fields in after FieldNameFormat is applied
	NormalizeFields  []string               // a list of field names that should have the NormalizerFormat applied to them and their corresponding values
	NormalizerFormat string                 // format string used to wrap fields and value clauses for the purpose of doing fuzzy searches
	UseInStatement   bool                   // whether multiple values in a criterion should be tested using an IN() statement
	Distinct         bool                   // whether a DISTINCT clause should be used in SELECT statements
	Count            bool                   // whether this query is being used to count rows, which means that SELECT fields are discarded in favor of COUNT(1)
	TypeMapping      SqlTypeMapping         // provides mapping information between DAL types and native SQL types
	Type             SqlStatementType       // what type of SQL statement is being generated
	InputData        map[string]interface{} // key-value data for statement types that require input data (e.g.: inserts, updates)
	// contains filtered or unexported fields
}

func NewSqlGenerator

func NewSqlGenerator() *Sql

func (*Sql) AggregateByField

func (self *Sql) AggregateByField(agg filter.Aggregation, field string) error

func (*Sql) ApplyNormalizer

func (self *Sql) ApplyNormalizer(fieldName string, in string) string

func (*Sql) ArrayTypeDecode added in v3.1.0

func (self *Sql) ArrayTypeDecode(in []byte, out interface{}) error

func (*Sql) ArrayTypeEncode added in v3.1.0

func (self *Sql) ArrayTypeEncode(in interface{}) ([]byte, error)

func (*Sql) Finalize

func (self *Sql) Finalize(f *filter.Filter) error

Takes all the information collected so far and generates a SQL statement from it

func (*Sql) GetPlaceholder

func (self *Sql) GetPlaceholder(fieldName string) string

func (*Sql) GetValues

func (self *Sql) GetValues() []interface{}

func (*Sql) GroupByField

func (self *Sql) GroupByField(field string) error

func (*Sql) Initialize

func (self *Sql) Initialize(collectionName string) error

func (*Sql) ObjectTypeDecode

func (self *Sql) ObjectTypeDecode(in []byte, out interface{}) error

func (*Sql) ObjectTypeEncode

func (self *Sql) ObjectTypeEncode(in interface{}) ([]byte, error)

func (*Sql) PrepareInputValue

func (self *Sql) PrepareInputValue(f string, value interface{}) (interface{}, error)

func (*Sql) SetOption

func (self *Sql) SetOption(_ string, _ interface{}) error

func (*Sql) SplitTypeLength

func (self *Sql) SplitTypeLength(in string) (string, int, int)

func (*Sql) ToAggregatedFieldName

func (self *Sql) ToAggregatedFieldName(agg filter.Aggregation, field string) string

func (*Sql) ToFieldName

func (self *Sql) ToFieldName(field string) string

func (*Sql) ToNativeType

func (self *Sql) ToNativeType(in dal.Type, subtypes []dal.Type, length int) (string, error)

func (*Sql) ToNativeValue

func (self *Sql) ToNativeValue(t dal.Type, subtypes []dal.Type, in interface{}) string

func (*Sql) ToTableName

func (self *Sql) ToTableName(table string) string

func (*Sql) WithCriterion

func (self *Sql) WithCriterion(criterion filter.Criterion) error

func (*Sql) WithField

func (self *Sql) WithField(field string) error

type SqlArrayTypeDecodeFunc added in v3.1.0

type SqlArrayTypeDecodeFunc func(in []byte, out interface{}) error

type SqlArrayTypeEncodeFunc added in v3.1.0

type SqlArrayTypeEncodeFunc func(in interface{}) ([]byte, error)

type SqlObjectTypeDecodeFunc

type SqlObjectTypeDecodeFunc func(in []byte, out interface{}) error

type SqlObjectTypeEncodeFunc

type SqlObjectTypeEncodeFunc func(in interface{}) ([]byte, error)

type SqlStatementType

type SqlStatementType int
const (
	SqlSelectStatement SqlStatementType = iota
	SqlInsertStatement
	SqlUpdateStatement
	SqlDeleteStatement
)

type SqlTypeMapping

type SqlTypeMapping struct {
	Name                  string
	StringType            string
	StringTypeLength      int
	IntegerType           string
	FloatType             string
	FloatTypeLength       int
	FloatTypePrecision    int
	BooleanType           string
	BooleanTypeLength     int
	DateTimeType          string
	ObjectType            string
	ArrayType             string
	RawType               string
	SubtypeFormat         string
	MultiSubtypeFormat    string
	PlaceholderFormat     string                  // if using placeholders, the format string used to insert them
	PlaceholderArgument   string                  // if specified, either "index", "index1" or "field"
	TableNameFormat       string                  // format string used to wrap table names
	FieldNameFormat       string                  // format string used to wrap field names
	NestedFieldNameFormat string                  // map of field name-format strings to wrap fields addressing nested map keys. supercedes FieldNameFormat
	NestedFieldSeparator  string                  // the string used to denote nesting in a nested field name
	NestedFieldJoiner     string                  // the string used to re-join all but the first value in a nested field when interpolating into NestedFieldNameFormat
	ObjectTypeEncodeFunc  SqlObjectTypeEncodeFunc // function used for encoding objects to a native representation
	ObjectTypeDecodeFunc  SqlObjectTypeDecodeFunc // function used for decoding objects from native into a destination map
	ArrayTypeEncodeFunc   SqlArrayTypeEncodeFunc  // function used for encoding arrays to a native representation
	ArrayTypeDecodeFunc   SqlArrayTypeDecodeFunc  // function used for decoding arrays from native into a destination map
}

func GetSqlTypeMapping

func GetSqlTypeMapping(name string) (SqlTypeMapping, error)

func (SqlTypeMapping) String added in v3.1.0

func (self SqlTypeMapping) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL