column.go 684 B

123456789101112131415161718192021222324252627282930313233
  1. package orm
  2. // column is a column in a table
  3. type column struct {
  4. field
  5. ref string
  6. }
  7. // GetName returns the name. If relation is given, it
  8. // will return `tbl`.`col` retpr
  9. func (c column) getName(q bool, rel ...interface{}) string {
  10. if len(rel) > 0 {
  11. switch rel[0].(type) {
  12. case relation:
  13. return ((rel[0]).(relation)).getAlias(q) + "." + c.getName(q)
  14. case *table:
  15. return ((rel[0]).(*table)).getAlias(q) + "." + c.getName(q)
  16. }
  17. }
  18. if q {
  19. return SqlFlavor.Quote(c.ref)
  20. }
  21. return c.ref
  22. }
  23. func (c column) GetAs(q bool, rel ...interface{}) string {
  24. return c.getName(q, rel) + " AS "
  25. }
  26. // columns is the collection of all columns in a table
  27. type columns []column