Documentation
¶
Overview ¶
Package codegen renders every generator-owned file kind (session, field-identifier constants, model, collection, internal store/record adapters) plus the one-time developer-owned extension file, from a GenerationPlan. Every rendered file is formatted and import-fixed before being placed in the plugin's response.
Index ¶
- func CollectionFieldName(row string) string
- func RecordTypeName(row string) string
- func Render(p *plan.Plan, outputRoot string) ([]*pb.File, []diagnostics.Diagnostic)
- func RenderCollection(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
- func RenderEager(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
- func RenderFields(ctx plan.ResolvedContext) ([]byte, []diagnostics.Diagnostic)
- func RenderModel(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
- func RenderRecord(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
- func RenderRelation(ctx plan.ResolvedContext, m plan.ResolvedModel, rel plan.ResolvedRelation) ([]byte, []diagnostics.Diagnostic)
- func RenderSession(ctx plan.ResolvedContext) ([]byte, []diagnostics.Diagnostic)
- func RenderStore(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
- func StoreTypeName(row string) string
- type ExtensionFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectionFieldName ¶
CollectionFieldName is the exported Session field name for a model's collection, e.g. "Users" for a model named "User" (naive English pluralization: append "s"; irregular plurals are not special-cased).
func RecordTypeName ¶
RecordTypeName is the unexported record struct name for a model, e.g. "userRecord" for a model whose Row is "User".
func Render ¶
func Render(p *plan.Plan, outputRoot string) ([]*pb.File, []diagnostics.Diagnostic)
Render renders every generator-owned file for p, plus each model's developer-owned extension file when it doesn't already exist in outputRoot (FR-015). The returned file list is sorted by path (FR-018, SC-002); a nil result means at least one error-severity diagnostic occurred and no output should be emitted for this run (FR-017).
func RenderCollection ¶
func RenderCollection(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
RenderCollection renders <model>_collection_gen.go: the New/Find entrypoints, per quickstart.md's `sess.Users.New()`/`sess.Users.Find(...)`.
func RenderEager ¶
func RenderEager(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
RenderEager renders <model>_eager_gen.go: the eager-load option types and batch-loading entry point for every one of m's eager-loadable relations, per contracts/relation-api.md. Aggregated per model (not per relation) because the plan/option types are shared across all of a model's eager-loadable relations.
func RenderFields ¶
func RenderFields(ctx plan.ResolvedContext) ([]byte, []diagnostics.Diagnostic)
RenderFields renders fields_gen.go for one context: one <Model>Field enum per model, one constant per field in declared order, regardless of each field's policy (contracts/generated-model-api.md "Field identifiers").
func RenderModel ¶
func RenderModel(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
RenderModel renders <model>_gen.go: the full generated model API per contracts/generated-model-api.md.
func RenderRecord ¶
func RenderRecord(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
RenderRecord renders <model>_record_gen.go: the internal record shape the model's store adapter scans query results into (plan.md's "internal store/record adapters"). Generated as an unexported type in the context package itself, not a nested internal/<model> package, because this plugin has no way to know the consuming project's own Go module path for a nested package's import statement — see internal/codegen/store.go for the same reasoning applied to the store adapter.
func RenderRelation ¶
func RenderRelation(ctx plan.ResolvedContext, m plan.ResolvedModel, rel plan.ResolvedRelation) ([]byte, []diagnostics.Diagnostic)
RenderRelation renders <model>_<relation>_relation_gen.go: the lazy relation builder for one relation, per contracts/relation-api.md.
func RenderSession ¶
func RenderSession(ctx plan.ResolvedContext) ([]byte, []diagnostics.Diagnostic)
RenderSession renders session_gen.go for one context (one per context, contracts/generated-model-api.md and quickstart.md's `content.New(pool)`).
func RenderStore ¶
func RenderStore(ctx plan.ResolvedContext, m plan.ResolvedModel) ([]byte, []diagnostics.Diagnostic)
RenderStore renders <model>_store_gen.go: the adapter that executes m's configured sqlc queries. Generated as an unexported type in the context package itself rather than a nested internal/<model> package — this plugin has no way to know the consuming project's own Go module path (needed for a nested package's import statement) at generation time, since sqlc-gen-go's own output doesn't exist yet during this invocation (contracts/plugin-io.md) and nothing in the plugin request communicates the target module path.
func StoreTypeName ¶
StoreTypeName is the unexported store struct name for a model, e.g. "userStore" for a model whose Row is "User".
Types ¶
type ExtensionFile ¶
type ExtensionFile struct {
// Path is relative to the plugin's output root, e.g. "content/user.go".
Path string
// Contents is the minimal stub to emit — only meaningful when the file
// does not already exist on disk.
Contents []byte
}
ExtensionFile is a developer-owned file the generator creates exactly once and never overwrites (FR-015, FR-016; data-model.md "Developer-Owned Extension File").
func PlanExtensionFile ¶
func PlanExtensionFile(outputRoot string, ctx plan.ResolvedContext, m plan.ResolvedModel) (ExtensionFile, bool)
PlanExtensionFile determines whether m's extension file already exists in outputRoot. If it does, the returned ExtensionFile's Contents is nil and the caller MUST NOT include this path in the response at all — including it, even with identical stub contents, would overwrite whatever the developer has already added (FR-015). outputRoot is the plugin's configured `out` directory; if empty (e.g. under test, where no real filesystem check is meaningful) the file is always treated as absent.