Iter
iter is a zero-based row counter available inside every generator function. It represents the record index currently being generated for a model.
Create a file named users.dg:
model users { fields { id() int name() string }
gens { func id() { return iter + 1 }
func name() { return Name() } }}Key Points
Section titled “Key Points”iterstarts at 0 and increases by 1 for each record.- The same
itervalue is used across all fields of a model for a given record.
How to Run
Section titled “How to Run”$ datagenc gen . -n 3Output
Section titled “Output”users{id:1 name:Eino Mayert}users{id:2 name:Savannah Casper}users{id:3 name:Keven Steuber}Notice how the id field uses iter + 1 to IDs starting from 1, while name generates random names for each record.