Documentation
¶
Overview ¶
Package tui provides the DevTUI execution handler for DDL export.
This package is intentionally separate from the ddlc root package: the root stays a WASM-safe leaf contract (Exporter, FieldExt, TopologicalSort) consumed by sqlt/postgres/ormc/sqlmcp, while this package pulls in os/file I/O and the DevTUI execution contract and is only meant to be imported by tinywasm/app's dev console.
Index ¶
- Constants
- Variables
- type ExportFunc
- type Handler
- func (h *Handler) Execute()
- func (h *Handler) ExecuteErr() error
- func (h *Handler) Label() string
- func (h *Handler) Name() string
- func (h *Handler) SetExport(fn ExportFunc)
- func (h *Handler) SetLog(fn func(messages ...any))
- func (h *Handler) SetOutputPath(path string)
- func (h *Handler) SetRootDir(path string)
Constants ¶
const ( MsgPrefix = "ddlc handler: " MsgExporting = "Exporting DDL schema..." MsgExportFailed = "Export failed: " MsgExportSuccess = "Export successful. Written to: " MsgWriteFailed = "Write failed: " MsgNoModels = "No models found — define one in a models.go file (see github.com/tinywasm/model). Nothing exported." ErrNotConfigured = "ddlc handler: export function not configured" )
Log message prefix and message constants to avoid repeating string literals. LogOpen/LogClose come from tinywasm/tui (the shared handler contract) rather than being redeclared here — see tui.LogOpen/tui.LogClose usage below.
const DefaultOutputPath = "config/schema.sql"
DefaultOutputPath is used when SetOutputPath is never called.
Variables ¶
var ErrNothingToExport = fmt.Err("nothing", "to", "export")
ErrNothingToExport signals an ExportFunc found nothing to write (e.g. no models defined in the project). ExecuteErr shows a friendly message instead of the generic failure one, and — like any non-nil error — never writes a file. Kept decoupled from any specific ExportFunc implementation (e.g. tinywasm/ormc): implementations that aren't ormc-based can return this directly; ormc-based ones go through a translation at their wiring site (see tinywasm/app/section-build.go, which knows about both ormc's ErrNoModelsFound and this sentinel).
Functions ¶
This section is empty.
Types ¶
type ExportFunc ¶
ExportFunc produces the DDL SQL for the current project.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements the TUI HandlerExecution and Loggable interfaces structurally.
func (*Handler) Execute ¶
func (h *Handler) Execute()
Execute triggers the DDL export. Implements devtui.HandlerExecution structurally.
func (*Handler) ExecuteErr ¶
ExecuteErr executes the export, writes the result to outputPath, and returns the error for test assertion.
func (*Handler) Label ¶
Label returns the button label for DevTUI. Includes both "SQL" and "DDL" (the acronym alone is opaque to devs without a SQL background) and the actual configured output path, so the button doubles as documentation of where the file lands. The path is shortened relative to rootDir (when set) since outputPath is absolute — see SetOutputPath / SetRootDir.
func (*Handler) SetExport ¶
func (h *Handler) SetExport(fn ExportFunc)
SetExport injects the DDL export logic.
func (*Handler) SetOutputPath ¶
SetOutputPath overrides the file the generated DDL is written to. Empty path resets to DefaultOutputPath.
func (*Handler) SetRootDir ¶ added in v0.0.8
SetRootDir tells the handler the project root, used only to shorten outputPath for display in Label() — outputPath itself stays absolute so writeOutput() is correct regardless of the daemon's own working directory (which does not necessarily track the project root it is currently serving).