generators

package
v3.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: LGPL-2.1 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CassandraTypeMapping = SqlTypeMapping{
	StringType:           `VARCHAR`,
	IntegerType:          `INT`,
	FloatType:            `FLOAT`,
	BooleanType:          `TINYINT`,
	BooleanTypeLength:    1,
	DateTimeType:         `DATETIME`,
	ObjectType:           `MAP`,
	RawType:              `BLOB`,
	SubtypeFormat:        `%s<%v>`,
	MultiSubtypeFormat:   `%s<%v,%v>`,
	PlaceholderFormat:    `TODO`,
	PlaceholderArgument:  `TODO`,
	TableNameFormat:      "%s",
	FieldNameFormat:      "%s",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var DefaultSqlTypeMapping = GenericTypeMapping
View Source
var GenericTypeMapping = SqlTypeMapping{
	StringType:           `VARCHAR`,
	StringTypeLength:     255,
	IntegerType:          `BIGINT`,
	FloatType:            `DECIMAL`,
	FloatTypeLength:      10,
	FloatTypePrecision:   8,
	BooleanType:          `BOOL`,
	DateTimeType:         `DATETIME`,
	ObjectType:           `BLOB`,
	RawType:              `BLOB`,
	PlaceholderFormat:    `?`,
	PlaceholderArgument:  ``,
	TableNameFormat:      "%s",
	FieldNameFormat:      "%s",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var MysqlTypeMapping = SqlTypeMapping{
	StringType:           `VARCHAR`,
	StringTypeLength:     255,
	IntegerType:          `BIGINT`,
	FloatType:            `DECIMAL`,
	FloatTypeLength:      10,
	FloatTypePrecision:   8,
	BooleanType:          `BOOL`,
	DateTimeType:         `DATETIME`,
	ObjectType:           `BLOB`,
	RawType:              `BLOB`,
	PlaceholderFormat:    `?`,
	PlaceholderArgument:  ``,
	TableNameFormat:      "`%s`",
	FieldNameFormat:      "`%s`",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var NoTypeMapping = SqlTypeMapping{}
View Source
var PostgresJsonTypeMapping = SqlTypeMapping{
	StringType:   `TEXT`,
	IntegerType:  `BIGINT`,
	FloatType:    `NUMERIC`,
	BooleanType:  `BOOLEAN`,
	DateTimeType: `TIMESTAMP`,

	ObjectType:           `VARCHAR`,
	RawType:              `BYTEA`,
	PlaceholderFormat:    `$%d`,
	PlaceholderArgument:  `index1`,
	TableNameFormat:      "%q",
	FieldNameFormat:      "%q",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var PostgresTypeMapping = SqlTypeMapping{
	StringType:           `TEXT`,
	IntegerType:          `BIGINT`,
	FloatType:            `NUMERIC`,
	BooleanType:          `BOOLEAN`,
	DateTimeType:         `TIMESTAMP`,
	ObjectType:           `VARCHAR`,
	RawType:              `BYTEA`,
	PlaceholderFormat:    `$%d`,
	PlaceholderArgument:  `index1`,
	TableNameFormat:      "%q",
	FieldNameFormat:      "%q",
	NestedFieldSeparator: `.`,
	NestedFieldJoiner:    `.`,
}
View Source
var SqlObjectTypeDecode = func(in []byte, out interface{}) error {
	return json.NewDecoder(bytes.NewReader(in)).Decode(out)
}
View Source
var SqlObjectTypeEncode = func(in interface{}) ([]byte, error) {
	var buf bytes.Buffer
	err := json.NewEncoder(&buf).Encode(in)
	return buf.Bytes(), err
}
View Source
var SqliteTypeMapping = SqlTypeMapping{
	StringType:           `TEXT`,
	IntegerType:          `INTEGER`,
	FloatType:            `REAL`,
	BooleanType:          `INTEGER`,
	BooleanTypeLength:    1,
	DateTimeType:         `INTEGER`,
	ObjectType:           `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) 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) 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 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 {
	StringType            string
	StringTypeLength      int
	IntegerType           string
	FloatType             string
	FloatTypeLength       int
	FloatTypePrecision    int
	BooleanType           string
	BooleanTypeLength     int
	DateTimeType          string
	ObjectType            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
}

func GetSqlTypeMapping

func GetSqlTypeMapping(name string) (SqlTypeMapping, error)

Jump to

Keyboard shortcuts

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