MCPcopy Index your code
hub / github.com/Masterminds/squirrel / toSql

Method toSql

expr.go:227–255  ·  view source on GitHub ↗
(opr string)

Source from the content-addressed store, hash-verified

225type Like map[string]interface{}
226
227func (lk Like) toSql(opr string) (sql string, args []interface{}, err error) {
228 var exprs []string
229 for key, val := range lk {
230 expr := ""
231
232 switch v := val.(type) {
233 case driver.Valuer:
234 if val, err = v.Value(); err != nil {
235 return
236 }
237 }
238
239 if val == nil {
240 err = fmt.Errorf("cannot use null with like operators")
241 return
242 } else {
243 if isListType(val) {
244 err = fmt.Errorf("cannot use array or slice with like operators")
245 return
246 } else {
247 expr = fmt.Sprintf("%s %s ?", key, opr)
248 args = append(args, val)
249 }
250 }
251 exprs = append(exprs, expr)
252 }
253 sql = strings.Join(exprs, " AND ")
254 return
255}
256
257func (lk Like) ToSql() (sql string, args []interface{}, err error) {
258 return lk.toSql("LIKE")

Callers 1

ToSqlMethod · 0.95

Calls 2

isListTypeFunction · 0.85
JoinMethod · 0.80

Tested by

no test coverage detected