@factory when you want to create many similar tasks, assets, loaders, or checks from a list, a config, or a loop, rather than hand-writing each one.
Factories are an advanced feature. Most projects author nodes directly; reach for a factory when you find yourself copy-pasting near-identical node definitions.
Defining a factory
A@factory function takes no arguments and returns one or more decorated node functions:
@task, @asset, @loader, or @check function.
Folder rules
Where a factory lives determines what it is allowed to emit:| Location | May emit |
|---|---|
loaders/ | loaders only |
tasks/ | tasks only |
assets/ | assets only |
checks/ | checks only |
factories/ | any kind, including a mix |
- A single-kind factory can live in that kind’s folder (e.g. an asset-only factory in
assets/), keeping it next to the nodes it generates. It can also live infactories/. - A factory that emits more than one kind must live in
factories/.
assets/, whether hand-written or factory-generated, is an asset.
SQLBuild enforces this at discovery time. A factory in a kind folder that returns a foreign kind raises an error pointing you to factories/:
factories/ folder is not created by sqb init - add it when you need it.
Mixed-kind factories
A factory infactories/ can generate a whole related pipeline at once - a loader, the asset that reads it, and a check on the result:
Naming
Generated nodes need unique names across the project. Pass an explicitname= to each node a factory creates (factories almost always generate names from a loop variable or config), since relying on the function’s own name would produce duplicates.
