github.com/RevenueMonster/sqlike@v1.0.6/sqlike/primitive/primitive.go (about) 1 package primitive 2 3 import ( 4 "fmt" 5 "reflect" 6 "strings" 7 ) 8 9 // Raw : 10 type Raw struct { 11 Value string 12 } 13 14 // JSONColumn : 15 type JSONColumn struct { 16 Column string 17 Nested []string 18 UnquoteResult bool 19 } 20 21 // WithQuote : 22 func (x JSONColumn) WithQuote() JSONColumn { 23 x.UnquoteResult = true 24 return x 25 } 26 27 func (x JSONColumn) String() string { 28 nested := strings.Join(x.Nested, ".") 29 operator := "->" 30 if strings.HasPrefix(nested, "$.") { 31 nested = "$." + nested 32 } 33 if x.UnquoteResult { 34 operator += ">" 35 } 36 return fmt.Sprintf("`%s`%s'$.%s'", x.Column, operator, nested) 37 } 38 39 // Column : 40 type Column struct { 41 Table string 42 Name string 43 } 44 45 // Alias : 46 type Alias struct { 47 Name string 48 Alias string 49 } 50 51 // CastAs : 52 type CastAs struct { 53 Value interface{} 54 DataType DataType 55 } 56 57 // Func : 58 type Func struct { 59 Name string 60 Args []interface{} 61 } 62 63 // Encoding : 64 type Encoding struct { 65 Charset *string 66 Column interface{} 67 Collate string 68 } 69 70 // TypeSafe : 71 type TypeSafe struct { 72 Type reflect.Kind 73 Value interface{} 74 } 75 76 // JSONFunc : 77 type JSONFunc struct { 78 Prefix interface{} 79 Type jsonFunction 80 Args []interface{} 81 } 82 83 // Group : 84 type Group struct { 85 Values []interface{} 86 } 87 88 // R : 89 type R struct { 90 From interface{} 91 To interface{} 92 } 93 94 // Field : 95 type Field struct { 96 Name string 97 Values []interface{} 98 } 99 100 // L : 101 type L struct { 102 Field interface{} 103 IsNot bool 104 Value interface{} 105 } 106 107 // C : 108 type C struct { 109 Field interface{} 110 Operator Operator 111 Value interface{} 112 } 113 114 // KV : 115 type KV struct { 116 Field string 117 Value interface{} 118 } 119 120 type operator int 121 122 // operators : 123 const ( 124 Add operator = iota 125 Deduct 126 ) 127 128 // Math : 129 type Math struct { 130 Field string 131 Mode operator 132 Value int 133 } 134 135 type order int 136 137 // orders : 138 const ( 139 Ascending order = iota 140 Descending 141 ) 142 143 // Nil : 144 type Nil struct { 145 Field interface{} 146 IsNot bool 147 } 148 149 // Sort : 150 type Sort struct { 151 Field interface{} 152 Order order 153 } 154 155 // Value : 156 type Value struct { 157 Raw interface{} 158 } 159 160 type aggregate int 161 162 // aggregation : 163 const ( 164 Sum aggregate = iota + 1 165 Count 166 Average 167 Max 168 Min 169 ) 170 171 // Aggregate : 172 type Aggregate struct { 173 Field interface{} 174 By aggregate 175 } 176 177 // As : 178 type As struct { 179 Field interface{} 180 Name string 181 }