Documentation
¶
Overview ¶
Package crud generates a resource from a schema.lidza model: the sqlc queries, the Create and Update types, a handlers file with the five typed routes, and the registration in routes.go. The output is ordinary app code, generated once and edited freely.
A resource is signed-in by default: its routes are registered on a group behind auth.Require(). An owned model (schema.Schema.Owner) is scoped to the signed-in user as well: every statement filters by the owner column, create sets it from auth.CurrentUser, the Create and Update types leave it out, and another user's row is a 404. A model marked @public (or generated with --public, which marks it) is neither.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Model is the model name in schema.lidza.
Model string
// Module is the app's Go module path.
Module string
// Force overwrites an existing handlers file.
Force bool
// Public marks the model @public in schema.lidza: its routes are open
// to visitors and its rows are not scoped to a user.
Public bool
// signed-in user shares, not scoped to one.
Shared bool
// Auth is true when the app enables the auth pack, which a resource
// that is not public needs.
Auth bool
// AppDir is lidza.json's appDir: the directory of the app's package,
// whose routes.go gets the registration. Empty is the root.
AppDir string
}
Options for Generate.
type Resource ¶
type Resource struct {
Schema *schema.Schema
Model *schema.Model
Module string
// Workspace is true when Owner is a workspace field (schema
// Schema.Workspace): its value is auth.WorkspaceID(ctx), the routes
// sit behind auth.RequireWorkspace().
Workspace bool
// Owner is the field scoping the rows to the signed-in user, nil for
// a model that is not owned.
Owner *schema.Field
}
Resource is one model with the derived names.
type Result ¶
type Result struct {
Files []string
// RoutesLine is the registration code, one or two lines, for a
// routes.go the generator could not edit.
RoutesLine string
Registered bool
// Owner is the owner field of an owned model, "" otherwise; Public and
// Shared are true for a @public or @shared model. Workspace is true
// when Owner is the workspace field: rows scoped to the request's
// workspace (auth.RequireWorkspace), not to the user.
Owner string
Workspace bool
// StaleInputs are the Create and Update types in schema.lidza that
// still take the owner field (written before the model was scoped);
// the handlers ignore it, and the field should go.
StaleInputs []string
}
Result lists what was written.