The Go ORM ant uses pointers to fields on a model “probe” as column identifiers, aiming to combine readable, chainable queries with compile-time checks and no code generation. For example, a query can filter with `ant.Gt(&Users.Age, 18)` and sort with `OrderBy(&Users.Name)`: misspelled fields and values of the wrong type fail during compilation, as do misspelled relations. Go 1.27’s generic methods make this chainable API possible; earlier Go versions required nested package-level functions or weaker type checks. Unlike schema-driven tools such as ent and sqlc, ant derives its metadata from ordinary Go structs.
At runtime, ant identifies a field pointer by comparing its address with cached probe objects, then matching the field’s offset and type. This takes about 21 nanoseconds with no allocations in the reported test, but relies on Go’s current non-moving garbage collector and uses an unsafe-pointer registry. Compile-time checking is incomplete: pointers from ordinary values, fields from the wrong model, and some column/relation mix-ups fail only at query execution, though antvet catches several cases. Ant also snapshots loaded entities so `SaveChanges` writes changed fields even when set to zero values, reducing accidental overwrites. In benchmarks, tracking made 1,000-row reads about 1.7 times slower and used three times the memory; without tracking, reads were close to plain SQL. Single-row operations were broadly comparable to other libraries, though ant had relatively high allocation counts.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.