...

Source file src/github.com/doug-martin/goqu/v9/exp/exp.go

Documentation: github.com/doug-martin/goqu/v9/exp

     1  package exp
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/doug-martin/goqu/v9/internal/sb"
     7  )
     8  
     9  // Behaviors
    10  type (
    11  
    12  	// Interface that an expression should implement if it can be aliased.
    13  	Aliaseable interface {
    14  		// Returns an AliasedExpression
    15  		//    I("col").As("other_col") //"col" AS "other_col"
    16  		//    I("col").As(I("other_col")) //"col" AS "other_col"
    17  		As(interface{}) AliasedExpression
    18  	}
    19  
    20  	// Interface that an expression should implement if it can be casted to another SQL type .
    21  	Castable interface {
    22  		// Casts an expression to the specified type
    23  		//   I("a").Cast("numeric")//CAST("a" AS numeric)
    24  		Cast(val string) CastExpression
    25  	}
    26  
    27  	Inable interface {
    28  		// Creates a Boolean expression for IN clauses
    29  		//    I("col").In([]string{"a", "b", "c"}) //("col" IN ('a', 'b', 'c'))
    30  		In(...interface{}) BooleanExpression
    31  		// Creates a Boolean expression for NOT IN clauses
    32  		//    I("col").NotIn([]string{"a", "b", "c"}) //("col" NOT IN ('a', 'b', 'c'))
    33  		NotIn(...interface{}) BooleanExpression
    34  	}
    35  
    36  	Isable interface {
    37  		// Creates an Boolean expression IS clauses
    38  		//   ds.Where(I("a").Is(nil)) //("a" IS NULL)
    39  		//   ds.Where(I("a").Is(true)) //("a" IS TRUE)
    40  		//   ds.Where(I("a").Is(false)) //("a" IS FALSE)
    41  		Is(interface{}) BooleanExpression
    42  		// Creates an Boolean expression IS NOT clauses
    43  		//   ds.Where(I("a").IsNot(nil)) //("a" IS NOT NULL)
    44  		//   ds.Where(I("a").IsNot(true)) //("a" IS NOT TRUE)
    45  		//   ds.Where(I("a").IsNot(false)) //("a" IS NOT FALSE)
    46  		IsNot(interface{}) BooleanExpression
    47  		// Shortcut for Is(nil)
    48  		IsNull() BooleanExpression
    49  		// Shortcut for IsNot(nil)
    50  		IsNotNull() BooleanExpression
    51  		// Shortcut for Is(true)
    52  		IsTrue() BooleanExpression
    53  		// Shortcut for IsNot(true)
    54  		IsNotTrue() BooleanExpression
    55  		// Shortcut for Is(false)
    56  		IsFalse() BooleanExpression
    57  		// Shortcut for IsNot(false)
    58  		IsNotFalse() BooleanExpression
    59  	}
    60  
    61  	Likeable interface {
    62  		// Creates an Boolean expression for LIKE clauses
    63  		//   ds.Where(I("a").Like("a%")) //("a" LIKE 'a%')
    64  		Like(interface{}) BooleanExpression
    65  		// Creates an Boolean expression for NOT LIKE clauses
    66  		//   ds.Where(I("a").NotLike("a%")) //("a" NOT LIKE 'a%')
    67  		NotLike(interface{}) BooleanExpression
    68  		// Creates an Boolean expression for case insensitive LIKE clauses
    69  		//   ds.Where(I("a").ILike("a%")) //("a" ILIKE 'a%')
    70  		ILike(interface{}) BooleanExpression
    71  		// Creates an Boolean expression for case insensitive NOT LIKE clauses
    72  		//   ds.Where(I("a").NotILike("a%")) //("a" NOT ILIKE 'a%')
    73  		NotILike(interface{}) BooleanExpression
    74  
    75  		// Creates an Boolean expression for REGEXP LIKE clauses
    76  		//   ds.Where(I("a").RegexpLike("a%")) //("a" ~ 'a%')
    77  		RegexpLike(interface{}) BooleanExpression
    78  		// Creates an Boolean expression for REGEXP NOT LIKE clauses
    79  		//   ds.Where(I("a").RegexpNotLike("a%")) //("a" !~ 'a%')
    80  		RegexpNotLike(interface{}) BooleanExpression
    81  		// Creates an Boolean expression for case insensitive REGEXP ILIKE clauses
    82  		//   ds.Where(I("a").RegexpILike("a%")) //("a" ~* 'a%')
    83  		RegexpILike(interface{}) BooleanExpression
    84  		// Creates an Boolean expression for case insensitive REGEXP NOT ILIKE clauses
    85  		//   ds.Where(I("a").RegexpNotILike("a%")) //("a" !~* 'a%')
    86  		RegexpNotILike(interface{}) BooleanExpression
    87  	}
    88  
    89  	// Interface that an expression should implement if it can be compared with other values.
    90  	Comparable interface {
    91  		// Creates a Boolean expression comparing equality
    92  		//    I("col").Eq(1) //("col" = 1)
    93  		Eq(interface{}) BooleanExpression
    94  		// Creates a Boolean expression comparing in-equality
    95  		//    I("col").Neq(1) //("col" != 1)
    96  		Neq(interface{}) BooleanExpression
    97  		// Creates a Boolean expression for greater than comparisons
    98  		//    I("col").Gt(1) //("col" > 1)
    99  		Gt(interface{}) BooleanExpression
   100  		// Creates a Boolean expression for greater than or equal to than comparisons
   101  		//    I("col").Gte(1) //("col" >= 1)
   102  		Gte(interface{}) BooleanExpression
   103  		// Creates a Boolean expression for less than comparisons
   104  		//    I("col").Lt(1) //("col" < 1)
   105  		Lt(interface{}) BooleanExpression
   106  		// Creates a Boolean expression for less than or equal to comparisons
   107  		//    I("col").Lte(1) //("col" <= 1)
   108  		Lte(interface{}) BooleanExpression
   109  	}
   110  
   111  	// Interface that an expression should implement if it can be used in a DISTINCT epxression.
   112  	Distinctable interface {
   113  		// Creates a DISTINCT clause
   114  		//   I("a").Distinct() //DISTINCT("a")
   115  		Distinct() SQLFunctionExpression
   116  	}
   117  
   118  	// Interface that an expression should implement if it can be ORDERED.
   119  	Orderable interface {
   120  		// Creates an Ordered Expression for sql ASC order
   121  		//   ds.Order(I("a").Asc()) //ORDER BY "a" ASC
   122  		Asc() OrderedExpression
   123  		// Creates an Ordered Expression for sql DESC order
   124  		//   ds.Order(I("a").Desc()) //ORDER BY "a" DESC
   125  		Desc() OrderedExpression
   126  	}
   127  
   128  	Rangeable interface {
   129  		// Creates a Range expression for between comparisons
   130  		//    I("col").Between(RangeVal{Start:1, End:10}) //("col" BETWEEN 1 AND 10)
   131  		Between(RangeVal) RangeExpression
   132  		// Creates a Range expression for between comparisons
   133  		//    I("col").NotBetween(RangeVal{Start:1, End:10}) //("col" NOT BETWEEN 1 AND 10)
   134  		NotBetween(RangeVal) RangeExpression
   135  	}
   136  
   137  	Updateable interface {
   138  		// Used internally by update sql
   139  		Set(interface{}) UpdateExpression
   140  	}
   141  
   142  	Bitwiseable interface {
   143  		// Creates a Bit Operation Expresion for sql ~
   144  		// I("col").BitiInversion() // (~ "col")
   145  		BitwiseInversion() BitwiseExpression
   146  		// Creates a Bit Operation Expresion for sql |
   147  		// I("col").BitOr(1) // ("col" | 1)
   148  		BitwiseOr(interface{}) BitwiseExpression
   149  		// Creates a Bit Operation Expresion for sql &
   150  		// I("col").BitAnd(1) // ("col" & 1)
   151  		BitwiseAnd(interface{}) BitwiseExpression
   152  		// Creates a Bit Operation Expresion for sql ^
   153  		// I("col").BitXor(1) // ("col" ^ 1)
   154  		BitwiseXor(interface{}) BitwiseExpression
   155  		// Creates a Bit Operation Expresion for sql <<
   156  		// I("col").BitLeftShift(1) // ("col" << 1)
   157  		BitwiseLeftShift(interface{}) BitwiseExpression
   158  		// Creates a Bit Operation Expresion for sql >>
   159  		// I("col").BitRighttShift(1) // ("col" >> 1)
   160  		BitwiseRightShift(interface{}) BitwiseExpression
   161  	}
   162  )
   163  
   164  type (
   165  	Vals []interface{}
   166  	// Parent of all expression types
   167  	Expression interface {
   168  		Clone() Expression
   169  		Expression() Expression
   170  	}
   171  	// An Expression that generates its own sql (e.g Dataset)
   172  	SQLExpression interface {
   173  		Expression
   174  		ToSQL() (string, []interface{}, error)
   175  		IsPrepared() bool
   176  	}
   177  
   178  	AppendableExpression interface {
   179  		Expression
   180  		AppendSQL(b sb.SQLBuilder)
   181  		// Returns the alias value as an identiier expression
   182  		GetAs() IdentifierExpression
   183  
   184  		// Returns true if this expression returns columns.
   185  		// Used to determine if a Select, Update, Insert, or Delete query returns columns
   186  		ReturnsColumns() bool
   187  	}
   188  	// Expression for Aliased expressions
   189  	//   I("a").As("b") -> "a" AS "b"
   190  	//   SUM("a").As(I("a_sum")) -> SUM("a") AS "a_sum"
   191  	AliasedExpression interface {
   192  		Expression
   193  		// Returns the Epxression being aliased
   194  		Aliased() Expression
   195  		// Returns the alias value as an identiier expression
   196  		GetAs() IdentifierExpression
   197  
   198  		// Returns a new IdentifierExpression with the specified schema
   199  		Schema(string) IdentifierExpression
   200  		// Returns a new IdentifierExpression with the specified table
   201  		Table(string) IdentifierExpression
   202  		// Returns a new IdentifierExpression with the specified column
   203  		Col(interface{}) IdentifierExpression
   204  		// Returns a new IdentifierExpression with the column set to *
   205  		//   I("my_table").All() //"my_table".*
   206  		All() IdentifierExpression
   207  	}
   208  
   209  	BooleanOperation  int
   210  	BooleanExpression interface {
   211  		Expression
   212  		Aliaseable
   213  		// Returns the operator for the expression
   214  		Op() BooleanOperation
   215  		// The left hand side of the expression (e.g. I("a")
   216  		LHS() Expression
   217  		// The right hand side of the expression could be a primitive value, dataset, or expression
   218  		RHS() interface{}
   219  	}
   220  
   221  	BitwiseOperation  int
   222  	BitwiseExpression interface {
   223  		Expression
   224  		Aliaseable
   225  		Comparable
   226  		Isable
   227  		Inable
   228  		Likeable
   229  		Rangeable
   230  		Orderable
   231  		Distinctable
   232  		// Returns the operator for the expression
   233  		Op() BitwiseOperation
   234  		// The left hand side of the expression (e.g. I("a")
   235  		LHS() Expression
   236  		// The right hand side of the expression could be a primitive value, dataset, or expression
   237  		RHS() interface{}
   238  	}
   239  
   240  	// An Expression that represents another Expression casted to a SQL type
   241  	CastExpression interface {
   242  		Expression
   243  		Aliaseable
   244  		Comparable
   245  		Inable
   246  		Isable
   247  		Likeable
   248  		Orderable
   249  		Distinctable
   250  		Rangeable
   251  		// The exression being casted
   252  		Casted() Expression
   253  		// The the SQL type to cast the expression to
   254  		Type() LiteralExpression
   255  	}
   256  	// A list of columns. Typically used internally by Select, Order, From
   257  	ColumnListExpression interface {
   258  		Expression
   259  		// Returns the list of columns
   260  		Columns() []Expression
   261  		// Returns true if the column list is empty
   262  		IsEmpty() bool
   263  		// Returns a new ColumnListExpression with the columns appended.
   264  		Append(...Expression) ColumnListExpression
   265  	}
   266  	CompoundType       int
   267  	CompoundExpression interface {
   268  		Expression
   269  		Type() CompoundType
   270  		RHS() AppendableExpression
   271  	}
   272  	// An Expression that the ON CONFLICT/ON DUPLICATE KEY portion of an INSERT statement
   273  	ConflictAction     int
   274  	ConflictExpression interface {
   275  		Expression
   276  		Action() ConflictAction
   277  	}
   278  	ConflictUpdateExpression interface {
   279  		ConflictExpression
   280  		TargetColumn() string
   281  		Where(expressions ...Expression) ConflictUpdateExpression
   282  		WhereClause() ExpressionList
   283  		Update() interface{}
   284  	}
   285  	CommonTableExpression interface {
   286  		Expression
   287  		IsRecursive() bool
   288  		// Returns the alias name for the extracted expression
   289  		Name() LiteralExpression
   290  		// Returns the Expression being extracted
   291  		SubQuery() Expression
   292  	}
   293  	ExpressionListType int
   294  	// A list of expressions that should be joined together
   295  	//    And(I("a").Eq(10), I("b").Eq(11)) //(("a" = 10) AND ("b" = 11))
   296  	//    Or(I("a").Eq(10), I("b").Eq(11)) //(("a" = 10) OR ("b" = 11))
   297  	ExpressionList interface {
   298  		Expression
   299  		// Returns type (e.g. OR, AND)
   300  		Type() ExpressionListType
   301  		// Slice of expressions that should be joined together
   302  		Expressions() []Expression
   303  		// Returns a new expression list with the given expressions appended to the current Expressions list
   304  		Append(...Expression) ExpressionList
   305  
   306  		IsEmpty() bool
   307  	}
   308  	// An Identifier that can contain schema, table and column identifiers
   309  	IdentifierExpression interface {
   310  		Expression
   311  		Aliaseable
   312  		Comparable
   313  		Inable
   314  		Isable
   315  		Likeable
   316  		Rangeable
   317  		Orderable
   318  		Updateable
   319  		Distinctable
   320  		Castable
   321  		Bitwiseable
   322  		// returns true if this identifier has more more than on part (Schema, Table or Col)
   323  		//	"schema" -> true //cant qualify anymore
   324  		//	"schema.table" -> true
   325  		//	"table" -> false
   326  		// "schema"."table"."col" -> true
   327  		// "table"."col" -> true
   328  		// "col" -> false
   329  		IsQualified() bool
   330  		// Returns a new IdentifierExpression with the specified schema
   331  		Schema(string) IdentifierExpression
   332  		// Returns the current schema
   333  		GetSchema() string
   334  		// Returns a new IdentifierExpression with the specified table
   335  		Table(string) IdentifierExpression
   336  		// Returns the current table
   337  		GetTable() string
   338  		// Returns a new IdentifierExpression with the specified column
   339  		Col(interface{}) IdentifierExpression
   340  		// Returns the current column
   341  		GetCol() interface{}
   342  		// Returns a new IdentifierExpression with the column set to *
   343  		//   I("my_table").All() //"my_table".*
   344  		All() IdentifierExpression
   345  
   346  		// Returns true if schema table and identifier are all zero values.
   347  		IsEmpty() bool
   348  	}
   349  	InsertExpression interface {
   350  		Expression
   351  		IsEmpty() bool
   352  		IsInsertFrom() bool
   353  		From() AppendableExpression
   354  		Cols() ColumnListExpression
   355  		SetCols(cols ColumnListExpression) InsertExpression
   356  		Vals() [][]interface{}
   357  		SetVals([][]interface{}) InsertExpression
   358  	}
   359  
   360  	JoinType       int
   361  	JoinExpression interface {
   362  		Expression
   363  		JoinType() JoinType
   364  		IsConditioned() bool
   365  		Table() Expression
   366  	}
   367  	// Parent type for join expressions
   368  	ConditionedJoinExpression interface {
   369  		JoinExpression
   370  		Condition() JoinCondition
   371  		IsConditionEmpty() bool
   372  	}
   373  	LateralExpression interface {
   374  		Expression
   375  		Aliaseable
   376  		Table() AppendableExpression
   377  	}
   378  
   379  	// Expression for representing "literal" sql.
   380  	//  L("col = 1") -> col = 1)
   381  	//  L("? = ?", I("col"), 1) -> "col" = 1
   382  	LiteralExpression interface {
   383  		Expression
   384  		Aliaseable
   385  		Comparable
   386  		Isable
   387  		Inable
   388  		Likeable
   389  		Rangeable
   390  		Orderable
   391  		Bitwiseable
   392  		// Returns the literal sql
   393  		Literal() string
   394  		// Arguments to be replaced within the sql
   395  		Args() []interface{}
   396  	}
   397  
   398  	NullSortType  int
   399  	SortDirection int
   400  	// An expression for specifying sort order and options
   401  	OrderedExpression interface {
   402  		Expression
   403  		// The expression being sorted
   404  		SortExpression() Expression
   405  		// Sort direction (e.g. ASC, DESC)
   406  		IsAsc() bool
   407  		// If the adapter supports it null sort type (e.g. NULLS FIRST, NULLS LAST)
   408  		NullSortType() NullSortType
   409  		// Returns a new OrderedExpression with NullSortType set to NULLS_FIRST
   410  		NullsFirst() OrderedExpression
   411  		// Returns a new OrderedExpression with NullSortType set to NULLS_LAST
   412  		NullsLast() OrderedExpression
   413  	}
   414  
   415  	RangeOperation  int
   416  	RangeExpression interface {
   417  		Expression
   418  		// Returns the operator for the expression
   419  		Op() RangeOperation
   420  		// The left hand side of the expression (e.g. I("a")
   421  		LHS() Expression
   422  		// The right hand side of the expression could be a primitive value, dataset, or expression
   423  		RHS() RangeVal
   424  	}
   425  	RangeVal interface {
   426  		Start() interface{}
   427  		End() interface{}
   428  	}
   429  
   430  	Windowable interface {
   431  		Over(WindowExpression) SQLWindowFunctionExpression
   432  		OverName(IdentifierExpression) SQLWindowFunctionExpression
   433  	}
   434  
   435  	// Expression for representing a SQLFunction(e.g. COUNT, SUM, MIN, MAX...)
   436  	SQLFunctionExpression interface {
   437  		Expression
   438  		Aliaseable
   439  		Rangeable
   440  		Comparable
   441  		Orderable
   442  		Isable
   443  		Inable
   444  		Likeable
   445  		Windowable
   446  		// The function name
   447  		Name() string
   448  		// Arguments to be passed to the function
   449  		Args() []interface{}
   450  	}
   451  
   452  	UpdateExpression interface {
   453  		Col() IdentifierExpression
   454  		Val() interface{}
   455  	}
   456  
   457  	SQLWindowFunctionExpression interface {
   458  		Expression
   459  		Aliaseable
   460  		Rangeable
   461  		Comparable
   462  		Orderable
   463  		Isable
   464  		Inable
   465  		Likeable
   466  		Func() SQLFunctionExpression
   467  
   468  		Window() WindowExpression
   469  		WindowName() IdentifierExpression
   470  
   471  		HasWindow() bool
   472  		HasWindowName() bool
   473  	}
   474  
   475  	WindowExpression interface {
   476  		Expression
   477  
   478  		Name() IdentifierExpression
   479  		HasName() bool
   480  
   481  		Parent() IdentifierExpression
   482  		HasParent() bool
   483  		PartitionCols() ColumnListExpression
   484  		HasPartitionBy() bool
   485  		OrderCols() ColumnListExpression
   486  		HasOrder() bool
   487  
   488  		Inherit(parent string) WindowExpression
   489  		PartitionBy(cols ...interface{}) WindowExpression
   490  		OrderBy(cols ...interface{}) WindowExpression
   491  	}
   492  	CaseElse interface {
   493  		Result() interface{}
   494  	}
   495  	CaseWhen interface {
   496  		Condition() interface{}
   497  		Result() interface{}
   498  	}
   499  	CaseExpression interface {
   500  		Expression
   501  		Aliaseable
   502  		Orderable
   503  		GetValue() interface{}
   504  		GetWhens() []CaseWhen
   505  		GetElse() CaseElse
   506  		Value(val interface{}) CaseExpression
   507  		When(condition, result interface{}) CaseExpression
   508  		Else(result interface{}) CaseExpression
   509  	}
   510  )
   511  
   512  const (
   513  	UnionCompoundType CompoundType = iota
   514  	UnionAllCompoundType
   515  	IntersectCompoundType
   516  	IntersectAllCompoundType
   517  
   518  	DoNothingConflictAction ConflictAction = iota
   519  	DoUpdateConflictAction
   520  
   521  	AndType ExpressionListType = iota
   522  	OrType
   523  
   524  	InnerJoinType JoinType = iota
   525  	FullOuterJoinType
   526  	RightOuterJoinType
   527  	LeftOuterJoinType
   528  	FullJoinType
   529  	RightJoinType
   530  	LeftJoinType
   531  	NaturalJoinType
   532  	NaturalLeftJoinType
   533  	NaturalRightJoinType
   534  	NaturalFullJoinType
   535  	CrossJoinType
   536  
   537  	UsingJoinCondType JoinConditionType = iota
   538  	OnJoinCondType
   539  
   540  	// Default null sort type with no null sort order
   541  	NoNullsSortType NullSortType = iota
   542  	// NULLS FIRST
   543  	NullsFirstSortType
   544  	// NULLS LAST
   545  	NullsLastSortType
   546  	// ASC
   547  	AscDir SortDirection = iota
   548  	// DESC
   549  	DescSortDir
   550  
   551  	// BETWEEN
   552  	BetweenOp RangeOperation = iota
   553  	// NOT BETWEEN
   554  	NotBetweenOp
   555  
   556  	// =
   557  	EqOp BooleanOperation = iota
   558  	// != or <>
   559  	NeqOp
   560  	// IS
   561  	IsOp
   562  	// IS NOT
   563  	IsNotOp
   564  	// >
   565  	GtOp
   566  	// >=
   567  	GteOp
   568  	// <
   569  	LtOp
   570  	// <=
   571  	LteOp
   572  	//  IN
   573  	InOp
   574  	//  NOT IN
   575  	NotInOp
   576  	//  LIKE, LIKE BINARY...
   577  	LikeOp
   578  	//  NOT LIKE, NOT LIKE BINARY...
   579  	NotLikeOp
   580  	//  ILIKE, LIKE
   581  	ILikeOp
   582  	//  NOT ILIKE, NOT LIKE
   583  	NotILikeOp
   584  	// ~, REGEXP BINARY
   585  	RegexpLikeOp
   586  	// !~, NOT REGEXP BINARY
   587  	RegexpNotLikeOp
   588  	// ~*, REGEXP
   589  	RegexpILikeOp
   590  	// !~*, NOT REGEXP
   591  	RegexpNotILikeOp
   592  
   593  	betweenStr = "between"
   594  
   595  	BitwiseInversionOp BitwiseOperation = iota
   596  	BitwiseOrOp
   597  	BitwiseAndOp
   598  	BitwiseXorOp
   599  	BitwiseLeftShiftOp
   600  	BitwiseRightShiftOp
   601  )
   602  
   603  var (
   604  	ConditionedJoinTypes = map[JoinType]bool{
   605  		InnerJoinType:      true,
   606  		FullOuterJoinType:  true,
   607  		RightOuterJoinType: true,
   608  		LeftOuterJoinType:  true,
   609  		FullJoinType:       true,
   610  		RightJoinType:      true,
   611  		LeftJoinType:       true,
   612  	}
   613  	// used internally for inverting operators
   614  	operatorInversions = map[BooleanOperation]BooleanOperation{
   615  		IsOp:             IsNotOp,
   616  		EqOp:             NeqOp,
   617  		GtOp:             LteOp,
   618  		GteOp:            LtOp,
   619  		LtOp:             GteOp,
   620  		LteOp:            GtOp,
   621  		InOp:             NotInOp,
   622  		LikeOp:           NotLikeOp,
   623  		ILikeOp:          NotILikeOp,
   624  		RegexpLikeOp:     RegexpNotLikeOp,
   625  		RegexpILikeOp:    RegexpNotILikeOp,
   626  		IsNotOp:          IsOp,
   627  		NeqOp:            EqOp,
   628  		NotInOp:          InOp,
   629  		NotLikeOp:        LikeOp,
   630  		NotILikeOp:       ILikeOp,
   631  		RegexpNotLikeOp:  RegexpLikeOp,
   632  		RegexpNotILikeOp: RegexpILikeOp,
   633  	}
   634  )
   635  
   636  func (bo BooleanOperation) String() string {
   637  	switch bo {
   638  	case EqOp:
   639  		return "eq"
   640  	case NeqOp:
   641  		return "neq"
   642  	case IsOp:
   643  		return "is"
   644  	case IsNotOp:
   645  		return "isnot"
   646  	case GtOp:
   647  		return "gt"
   648  	case GteOp:
   649  		return "gte"
   650  	case LtOp:
   651  		return "lt"
   652  	case LteOp:
   653  		return "lte"
   654  	case InOp:
   655  		return "in"
   656  	case NotInOp:
   657  		return "notin"
   658  	case LikeOp:
   659  		return "like"
   660  	case NotLikeOp:
   661  		return "notlike"
   662  	case ILikeOp:
   663  		return "ilike"
   664  	case NotILikeOp:
   665  		return "notilike"
   666  	case RegexpLikeOp:
   667  		return "regexplike"
   668  	case RegexpNotLikeOp:
   669  		return "regexpnotlike"
   670  	case RegexpILikeOp:
   671  		return "regexpilike"
   672  	case RegexpNotILikeOp:
   673  		return "regexpnotilike"
   674  	}
   675  	return fmt.Sprintf("%d", bo)
   676  }
   677  
   678  func (bi BitwiseOperation) String() string {
   679  	switch bi {
   680  	case BitwiseInversionOp:
   681  		return "Inversion"
   682  	case BitwiseOrOp:
   683  		return "OR"
   684  	case BitwiseAndOp:
   685  		return "AND"
   686  	case BitwiseXorOp:
   687  		return "XOR"
   688  	case BitwiseLeftShiftOp:
   689  		return "Left Shift"
   690  	case BitwiseRightShiftOp:
   691  		return "Right Shift"
   692  	}
   693  	return fmt.Sprintf("%d", bi)
   694  }
   695  
   696  func (ro RangeOperation) String() string {
   697  	switch ro {
   698  	case BetweenOp:
   699  		return betweenStr
   700  	case NotBetweenOp:
   701  		return "not between"
   702  	}
   703  	return fmt.Sprintf("%d", ro)
   704  }
   705  
   706  func (jt JoinType) String() string {
   707  	switch jt {
   708  	case InnerJoinType:
   709  		return "InnerJoinType"
   710  	case FullOuterJoinType:
   711  		return "FullOuterJoinType"
   712  	case RightOuterJoinType:
   713  		return "RightOuterJoinType"
   714  	case LeftOuterJoinType:
   715  		return "LeftOuterJoinType"
   716  	case FullJoinType:
   717  		return "FullJoinType"
   718  	case RightJoinType:
   719  		return "RightJoinType"
   720  	case LeftJoinType:
   721  		return "LeftJoinType"
   722  	case NaturalJoinType:
   723  		return "NaturalJoinType"
   724  	case NaturalLeftJoinType:
   725  		return "NaturalLeftJoinType"
   726  	case NaturalRightJoinType:
   727  		return "NaturalRightJoinType"
   728  	case NaturalFullJoinType:
   729  		return "NaturalFullJoinType"
   730  	case CrossJoinType:
   731  		return "CrossJoinType"
   732  	}
   733  	return fmt.Sprintf("%d", jt)
   734  }
   735  

View as plain text