Documentation
¶
Overview ¶
Package report renders tabular results to HTML or PDF through facet.
Index ¶
Constants ¶
const ( // PropertyURL names the facet server used when a report does not name one. PropertyURL = "facet.url" // PropertyConnection names the facet connection used when neither the // report nor facet.url names a server. PropertyConnection = "facet.connection" )
const EntryFile = "QueryReport.tsx"
EntryFile is the TSX component the embedded template renders with.
Variables ¶
var SourceDir = os.Getenv("QUERY_REPORT_SOURCE_DIR")
SourceDir overrides the extracted template with a directory on disk, for developing the TSX without rebuilding the binary.
Functions ¶
func Render ¶
func Render( ctx context.Context, server facet.Server, data any, format, srcDir, entryFile string, ) ([]byte, error)
Render sends the render to the configured server, falling back to the local facet binary only when none is configured.
func ResolveServer ¶
ResolveServer picks the facet render service, preferring what the report asks for and falling back to the facet.url and facet.connection properties. A zero Server means none is configured and the local binary is used.
func TemplateDir ¶
TemplateDir returns a directory holding the report template, extracting the embedded copy on first use.
The location is content-addressed by the template's own hash, so the pnpm install and Vite build cached under .facet/ survive across renders and across restarts — a cold render costs roughly ten times a warm one — while a change to the template lands in a different directory and is never served stale.
Types ¶
type Column ¶
type Column struct {
Name string `json:"name"`
Type string `json:"type"`
Unit string `json:"unit,omitempty"`
}
Column is one facet DynamicTable column. Type drives the cell renderer, and must be one of facet's own names.
type Payload ¶
type Payload struct {
// Name is what facet writes the file as when the output path is a
// directory, so it doubles as the report's slug.
Name string `json:"name"`
Title string `json:"title"`
Subtitle string `json:"subtitle,omitempty"`
GeneratedAt string `json:"generatedAt"`
RowCount int `json:"rowCount"`
Truncated bool `json:"truncated,omitempty"`
Columns []Column `json:"columns"`
Rows []query.Row `json:"rows"`
}
Payload is what the TSX template is called with. It mirrors ReportData in QueryReport.tsx.