converter

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Mongo_Stage_Lookup       = "$lookup"
	Mongo_Stage_Group        = "$group"
	Mongo_Stage_Replace_Root = "$replaceRoot"
	Mongo_Stage_Unwind       = "$unwind"
	Mongo_Stage_Macth        = "$match"
	Mongo_Stage_Sort         = "$sort"
	Mongo_Stage_Skip         = "$skip"
	Mongo_Stage_Limit        = "$limit"
	Mongo_Stage_AddFields    = "$addFields"

	Mongo_Operator_Gte          = "$gte"
	Mongo_Operator_Gt           = "$gt"
	Mongo_Operator_Lte          = "$lte"
	Mongo_Operator_Lt           = "$lt"
	Mongo_Operator_Eq           = "$eq"
	Mongo_Operator_Ne           = "$ne"
	Mongo_Operator_And          = "$and"
	Mongo_Operator_Or           = "$or"
	Mongo_Operator_In           = "$in"
	Mongo_Operator_Not          = "$not"
	Mongo_Operator_Expr         = "$expr"
	Mongo_Operator_Regex        = "$regex"
	Mongo_Operator_Sum          = "$sum"
	Mongo_Operator_Cond         = "$cond"
	Mongo_Operator_IfNull       = "$ifNull"
	Mongo_Operator_Avg          = "$avg"
	Mongo_Operator_AddToSet     = "$addToSet"
	Mongo_Operator_Size         = "$size"
	Mongo_Operator_Year         = "$year"
	Mongo_Operator_Month        = "$month"
	Mongo_Operator_DayOfMonth   = "$dayOfMonth"
	Mongo_Operator_Hour         = "$hour"
	Mongo_Operator_Minute       = "$minute"
	Mongo_Operator_Second       = "$second"
	Mongo_Operator_DateToString = "$dateToString"
	Mongo_Operator_Add          = "$add"
	Mongo_Operator_Subtract     = "$subtract"
	Mongo_Operator_Multiply     = "$multiply"
	Mongo_Operator_Divide       = "$divide"
	Mongo_Operator_Round        = "$round"
	Mongo_Operator_Switch       = "$switch"
	Mongo_Operator_Type         = "$type"
	Mongo_Operator_Now          = "$$NOW"
	Mongo_Operator_To_Double    = "$toDouble"
	Mongo_Operator_Floor        = "$floor"
	Mongo_Operator_Push         = "$push"
	Mongo_Operator_ArrayElemAt  = "$arrayElemAt"
	Mongo_Operator_Split        = "$split"
	Mongo_Operator_Date_Trunc   = "$dateTrunc"

	Mongo_Arg_If       = "if"
	Mongo_Arg_Then     = "then"
	Mongo_Arg_Else     = "else"
	Mongo_Arg_Let      = "let"
	Mongo_Arg_Pipeline = "pipeline"
	Mongo_Arg_Branches = "branches"
	Mongo_Arg_Case     = "case"
	Mongo_Arg_Default  = "default"
	Mongo_Arg_Missing  = "missing"
	Mongo_Arg_Date     = "date"
	Mongo_Arg_Unit     = "unit"
)

Variables

Functions

func ParseTime added in v1.0.4

func ParseTime(layout, value string) (timeVal time.Time, err error)

解析时间 layout 时间格式,未指定则默认使用RFC3339 时间字符串,长度为10说明只包含日期,使用DateOnly格式

Types

type ConverterValidator

type ConverterValidator interface {
	// 校验SQL是否可转化
	Validate(parser.SQL) error
}

type MongoPipeline

type MongoPipeline struct {
	ResultView string
	Pipeline   bson.A
}

type MongoQuery

type MongoQuery struct {
	Sql parser.SQL
	// 最终查询字段
	SelectFields []*parser.Column
	// 聚合起始view
	StartView string
	// 最终生成的view
	Pipeline bson.A
}

func (MongoQuery) OriginalSQL

func (query MongoQuery) OriginalSQL() parser.SQL

type MongoQueryConverter

type MongoQueryConverter struct {
	// contains filtered or unexported fields
}

mongo查询语句转化器

func (*MongoQueryConverter) Convert

func (conv *MongoQueryConverter) Convert(strictMode bool) (query Query, err error)

type MongoQueryConverterValidator

type MongoQueryConverterValidator struct{}

mongo查询语句转化校验器

func (*MongoQueryConverterValidator) Validate

func (validator *MongoQueryConverterValidator) Validate(sql parser.SQL) (err error)

type Query

type Query interface {
	// 获取原始SQL
	OriginalSQL() parser.SQL
}

type SelectConverter

type SelectConverter interface {
	// 转化为目标查询语句
	Convert(strictMode bool) (Query, error)
}

func NewMongoQueryConverter

func NewMongoQueryConverter(sql parser.SQL, sourceView map[string]string) SelectConverter

Jump to

Keyboard shortcuts

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