Skip to content

Table Token

Part of Entiqon / Database / Token

🌱 Overview

The token.Table type represents a SQL table (or subquery) token with optional alias.
It delegates parsing and classification to the shared resolver and expression_kind modules,
enforcing strict construction rules and exposing multiple forms for logging, debugging, and SQL rendering.


Construction Rules

Tables are created using table.New(...):

  1. Plain table
  2. table.New("users")users

  3. Aliased (inline)

  4. table.New("users u")users AS u
  5. table.New("users AS u")users AS u

  6. Aliased (explicit arguments)

  7. table.New("users", "u")users AS u
  8. Alias may also be any fmt.Stringer implementation
  9. Always validated via resolver

  10. Subquery

  11. table.New("(SELECT COUNT(*) FROM users) AS t") → subquery with alias
  12. table.New("(SELECT COUNT(*) FROM users)", "t") → subquery with alias
    ⚠️ Subqueries must have an alias, otherwise the token is errored.

  13. Errors

  14. Empty input → errored
  15. Invalid alias (including reserved keywords such as AS, FROM, SELECT) → errored
  16. Passing a token directly (e.g. table.New(table.New("users"))) → errored, with hint to use Clone()
  17. Invalid types (e.g. table.New(123)) → errored
  18. Too many tokens or malformed input → errored

Contracts Implemented

  • TableToken
  • ClonableClone() (safe duplication)
  • DebuggableDebug() (developer diagnostics with flags)
  • ErrorableIsErrored(), Error()
  • RawableRaw() (generic SQL fragment), IsRaw()
  • RenderableRender() (canonical SQL form)
  • StringableString() (human-facing logs)
  • ValidableIsValid() (validity check based on resolver rules)

Logging

  • String()
    Concise, log-friendly:
    text ✅ table(users AS u) ❌ table("users AS"): invalid format "users AS"

  • Debug()
    Verbose developer output with flags:
    text ✅ table("users AS u"): [raw:false, aliased:true, errored:false] ❌ table("users AS"): [raw:false, aliased:false, errored:true] {err=invalid format "users AS"}


📄 License

MIT — © Entiqon Project