Token System Guide¶
This guide explains how internal tokens like token are structured, parsed, validated, and consumed by query builders.
All tokens (e.g.,
token,Table,Condition) embedBaseToken, making them bothErrorable(viaGetError/IsErrored/SetError) andKindable(viaGetKind/SetKind). All these methods are nilโsafe: calling any of them on aniltoken will not panic and returns a safe default (e.g.,IsErrored()โfalse,GetKind()โUnknownKind).
๐ Principles¶
- Tokens are internal, immutable, and selfโvalidating.
- Each token may carry an
Error(via the Errorable contract).- Calling
IsErrored()on a token with no error (or on aniltoken) returnsfalse. - Calling
GetError()on a token with no error (or on aniltoken) returnsnil.
- Calling
- Tokens also expose a
Kind(via the Kindable contract).- Calling
GetKind()on a token with no kind set (or on aniltoken) returnsUnknownKind. - Calling
SetKind(...)on aniltoken is a noโop (nilโsafe).
- Calling
- Tokens do not handle dialect quoting or full SQL rendering beyond their own
RenderName()/RenderAlias(). BaseTokenprovides name, alias, error, and kind logic for all tokens, ensuring it is reusable and consistent.
๐งฉ Core Behaviors¶
- Input normalization
- Alias resolution
- Error tracking
- Dialect-safe rendering
๐ Qualification & Validation¶
A generic token may become invalid under any of the following scenarios. All tokens embed BaseToken, so these apply
universally (token, Table, Condition, etc.):
- Empty input: An input string that is blank or only whitespace sets an error.
- Comma-separated expression: Inputs containing commas (
,) are rejected (aliases must not be comma-separated). - Starts with
AS: Inputs beginning withASor whose base resolves toASonly are invalid (missing identifier beforeAS). - Alias conflict: When both inline and explicit aliases are provided but do not match (e.g.,
"users.id AS uid", "other_uid"), an error is set. - Qualifier conflict: For tokens that parse qualifiers (e.g.,
users.id), if the qualifier does not match an attached context (e.g., a mismatched table alias), the token becomes invalid. - Reserved word misuse: If the parsed base identifier itself is a reserved word (e.g.,
"AS"only), the token is invalid.
All of the above conditions will cause IsErrored() to return true, with details accessible via GetError(). You can
check IsValid() (equivalent to !IsErrored() && Name != "") before including a token in any generated SQL.
๐งฑ Related Tokens¶
The following core token is the base for all SQL tokens in Entiqon:
| Name | Description | Access | |
|---|---|---|---|
| ๐ | BaseToken | Is the abstract foundational structure used by all SQL tokens in Entiqon (such as token, Table, and Condition) |
Private |
This modular reference allows isolated testing and future reuse for other token types.
2025 โ ยฉ Entiqon Project