MCPcopy Index your code
hub / github.com/upper/db / As

Method As

internal/sqlbuilder/select.go:410–425  ·  view source on GitHub ↗
(alias string)

Source from the content-addressed store, hash-verified

408}
409
410func (sel *selector) As(alias string) db.Selector {
411 return sel.frame(func(sq *selectorQuery) error {
412 if sq.table == nil {
413 return errors.New("Cannot use As() without a preceding From() expression")
414 }
415 last := len(sq.table.Columns) - 1
416 if raw, ok := sq.table.Columns[last].(*exql.Raw); ok {
417 compiled, err := exql.ColumnWithName(alias).Compile(sel.template())
418 if err != nil {
419 return err
420 }
421 sq.table.Columns[last] = &exql.Raw{Value: raw.Value + " AS " + compiled}
422 }
423 return nil
424 })
425}
426
427func (sel *selector) statement() *exql.Statement {
428 sq, _ := sel.build()

Callers

nothing calls this directly

Calls 5

frameMethod · 0.95
templateMethod · 0.95
ColumnWithNameFunction · 0.92
NewMethod · 0.65
CompileMethod · 0.65

Tested by

no test coverage detected