Documentation ¶
Index ¶
Constants ¶
const (
ImplicitDb = "__mem__" // reserved scheme name for in-memory database. All tables are stored in this database for each page render.
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
Handler is will wrap fileserver and render any esqlo templates returned. If a file is not html, it is served unmodified like a normal filesystem http server. If a file is html, it is parsed as a esqlo template and rendered with the sql statements automatically resolved using the configured database connections.
type LineCounter ¶
type LineCounter struct {
// contains filtered or unexported fields
}
LineCounter wraps an io.Reader and records line information to allow converting offsets into line numbers. Line feed (ASCII 10, '\n') is used as the line ending (files using CRLF line termination will of course count correctly as well).
func NewLineCounter ¶
func NewLineCounter(r io.Reader) *LineCounter
NewLineCounter returns a new LineCounter reading from r.
func (*LineCounter) LineCol ¶
func (l *LineCounter) LineCol(offset int) (line, col int)
LineCol returns, give a byte offset of the input, the line number and that line's byte offset in the input. Line numbers are 1-based, i.e. passing 0 returns line number 1. Offsets beyond the last recorded line will return the last recorded line.
type Renderer ¶
type Renderer struct { Databases map[string]Database Errors []*Err // any errors that occurred while processing the document (can be ignored gracefully) // contains filtered or unexported fields }
func NewRenderer ¶
func NewRenderer() *Renderer
func (*Renderer) RenderHTML ¶
/ RenderHTML renders an HTML document with embedded SQL statements. The SQL statements are resolved using the provided / database connections. The rendered HTML is written to the provided writer.
The SQL statements are embedded in the HTML using the following syntax:
<!-- Define a table for this HTML document that can be used in later in the document to inject live data. --> <!-- The src must be a defined database with name persons, and the query must be a valid SQL query for that database type. --> <sql src="sqlite://persons.sqlite" name="famous_persons">SELECT name, age FROM persons WHERE is_famous={{query.is_famous}} LIMIT {{query.page_size}}"</sql> <p>Here is a list of famous people:</p> <p>{{persons.name[0]}} is {{persons.age[0]}} years old</p> <p>{{persons.name[1]}} is {{persons.age[1]}} years old</p> <p>{{persons.name[2]}} is {{persons.age[2]}} years old</p>
RenderHTML does not modify the tree, besides removing the <sql> tags at the start of the html document.
Replacement values are injected into the HTML document afterwards using the Mustache template syntax.
type SqlTag ¶
type SqlTag struct {
Offset, End int // the offset in the source file where this tag starts
Src string // the database connection to use
Database Database // the database connection to use
TableName string // the name to store this table as
Query string // the sql query to execute
Result *Result // the result of the query
}