tui

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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.

View Source
const DefaultOutputPath = "config/schema.sql"

DefaultOutputPath is used when SetOutputPath is never called.

Variables

View Source
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

type ExportFunc func() (sql string, err error)

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 New

func New() *Handler

New creates a new DDLC TUI handler.

func (*Handler) Execute

func (h *Handler) Execute()

Execute triggers the DDL export. Implements devtui.HandlerExecution structurally.

func (*Handler) ExecuteErr

func (h *Handler) ExecuteErr() error

ExecuteErr executes the export, writes the result to outputPath, and returns the error for test assertion.

func (*Handler) Label

func (h *Handler) Label() string

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) Name

func (h *Handler) Name() string

Name returns the TUI handler identifier.

func (*Handler) SetExport

func (h *Handler) SetExport(fn ExportFunc)

SetExport injects the DDL export logic.

func (*Handler) SetLog

func (h *Handler) SetLog(fn func(messages ...any))

SetLog injects the logging function.

func (*Handler) SetOutputPath

func (h *Handler) SetOutputPath(path string)

SetOutputPath overrides the file the generated DDL is written to. Empty path resets to DefaultOutputPath.

func (*Handler) SetRootDir added in v0.0.8

func (h *Handler) SetRootDir(path string)

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL