MCPcopy
hub / github.com/sqlc-dev/sqlc / convertFuncCallExpr

Method convertFuncCallExpr

internal/engine/dolphin/convert.go:419–479  ·  view source on GitHub ↗
(n *pcast.FuncCallExpr)

Source from the content-addressed store, hash-verified

417}
418
419func (c *cc) convertFuncCallExpr(n *pcast.FuncCallExpr) ast.Node {
420 schema := n.Schema.String()
421 name := strings.ToLower(n.FnName.String())
422
423 // TODO: Deprecate the usage of Funcname
424 items := []ast.Node{}
425 if schema != "" {
426 items = append(items, NewIdentifier(schema))
427 }
428 items = append(items, NewIdentifier(name))
429
430 // Handle DATE_ADD/DATE_SUB specially to construct INTERVAL expressions
431 // These functions have args: [date, interval_value, TimeUnitExpr]
432 if (name == "date_add" || name == "date_sub") && len(n.Args) == 3 {
433 if timeUnit, ok := n.Args[2].(*pcast.TimeUnitExpr); ok {
434 args := &ast.List{
435 Items: []ast.Node{
436 c.convert(n.Args[0]),
437 &ast.IntervalExpr{
438 Value: c.convert(n.Args[1]),
439 Unit: timeUnit.Unit.String(),
440 },
441 },
442 }
443 return &ast.FuncCall{
444 Args: args,
445 Func: &ast.FuncName{
446 Schema: schema,
447 Name: name,
448 },
449 Funcname: &ast.List{
450 Items: items,
451 },
452 Location: n.OriginTextPosition(),
453 }
454 }
455 }
456
457 args := &ast.List{}
458 for _, arg := range n.Args {
459 args.Items = append(args.Items, c.convert(arg))
460 }
461
462 if schema == "" && name == "coalesce" {
463 return &ast.CoalesceExpr{
464 Args: args,
465 }
466 } else {
467 return &ast.FuncCall{
468 Args: args,
469 Func: &ast.FuncName{
470 Schema: schema,
471 Name: name,
472 },
473 Funcname: &ast.List{
474 Items: items,
475 },
476 Location: n.OriginTextPosition(),

Callers 1

convertMethod · 0.95

Calls 3

convertMethod · 0.95
NewIdentifierFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected