Contract¶
🧩 Overview¶
The contract package defines small, reusable behavioral contracts (interfaces)
that core tokens (Field, Table, Join, Condition, etc.) and builders implement
to enable polymorphic behavior without tight coupling between packages.
Contracts are intentionally minimalistic, composable, and auditable.
They focus on clear identity, safe mutation, and consistent rendering across tokens,
while leaving implementation details to each package.
Available Contracts (strict order)¶
| Contract | Purpose | Methods |
|---|---|---|
| Identifiable | Raw input and normalized expression identity (alias-free). | Input() stringExpr() string |
| Aliasable | Alias surface for tokens. | Alias() stringIsAliased() bool |
| BaseToken | Core identity for tokens, including alias. | Input() stringExpr() stringAlias() stringIsAliased() bool |
| Clonable | Semantic cloning for safe mutation. | Clone() T |
| Debuggable | Developer-facing diagnostic output. | Debug() string |
| Errorable | Error state inspection and propagation. | IsErrored() boolError() errorSetError(err error) T |
| Rawable | Generic SQL fragments, dialect-agnostic. | Raw() stringIsRaw() bool |
| Renderable | Canonical, dialect-aware SQL output. | Render() string |
| Stringable | Human-facing audit/log output. | String() string |
| Validable | Structural validation. | IsValid() bool |
Examples¶
See example_test.go for runnable examples of all contracts:
t := table.New("users", "u")
var k contract.Kindable[myKind] = &myToken{}
k.SetKind(Custom)
fmt.Println("Kind=", k.Kind()) // classification
var id contract.Identifiable = t
fmt.Println(id.Input(), id.Expr()) // identity only
var al contract.Aliasable = t
fmt.Println(al.Alias(), al.IsAliased()) // alias surface
var bt contract.BaseToken = t
fmt.Println(bt.Input(), bt.Expr(), bt.Alias(), bt.IsAliased())
// Output: users users u true
var c contract.Clonable[*table.Table] = t
fmt.Println(c.Clone()) // safe copy
var d contract.Debuggable = t
fmt.Println(d.Debug()) // developer diagnostic
var e contract.Errorable[*table.Table] = t
fmt.Println(e.IsErrored(), e.Error()) // error state
var w contract.Rawable = t
fmt.Println(w.Raw()) // generic SQL
var r contract.Renderable = t
fmt.Println(r.Render()) // dialect-aware SQL
var s contract.Stringable = t
fmt.Println(s.String()) // audit/log
var v contract.Validable = t
fmt.Println(v.IsValid()) // structural validation
Note:
- Use Kindable for classification enums (e.g., condition.Type, identifier.Type).
- Use Identifiable when aliasing must be excluded (e.g., in Condition tokens).
📄 License¶
MIT — © Entiqon Project