engine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package engine orchestrates a dfetch query: parse the SQL, resolve each referenced schema to a connector, fetch and load each table into a per-request local SQLite database (pushing down as much of the query as is safe), then resolve the original query against it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine resolves dfetch queries against configured connectors, keyed by the SQL schema they serve (e.g. "github").

func New

func New(cfg *config.Config) (*Engine, error)

New builds an Engine: the built-in connectors plus any declared in config.

func (*Engine) DescribeTable

func (e *Engine) DescribeTable(ctx context.Context, schema, table string) (source.TableSchema, error)

DescribeTable returns the column schema of one table, resolving it on demand for dynamic connectors (SchemaDescriber) and from Tables() otherwise.

func (*Engine) ListTables

func (e *Engine) ListTables(ctx context.Context, schema, filter string) ([]string, error)

ListTables returns the table names served under schema, filtered by a case-insensitive substring. A dynamic connector (TableLister) lists on demand; a static one lists from Tables().

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, query string) (*Result, error)

Run executes the full pipeline for a SQL query (SQLite syntax).

func (*Engine) RunWithParams

func (e *Engine) RunWithParams(ctx context.Context, query string, params map[string]any) (*Result, error)

RunWithParams executes the full pipeline for a SQL query (SQLite syntax), binding params as named SQLite parameters (referenced as :name in the SQL). A nil or empty params map runs the query with no bound parameters.

The params are also handed to the push-down planner: the planner resolves a bind-parameter RHS (e.g. `service_name = :service`) to its value so the filter can be pushed to the connector, while the final query keeps the :name bind for SQLite. Without this, connectors that require a filter value at fetch time (jaeger.spans needs service_name or trace_id, github.pulls needs owner/repo) would never see the value, since a bind is opaque until SQLite executes.

func (*Engine) SchemaSummaries

func (e *Engine) SchemaSummaries(ctx context.Context) []SchemaSummary

SchemaSummaries returns one summary per connector schema (sorted), for the top-level `dfetch tables` view. A dynamic source's count comes from listing its table names; if that fails (e.g. the source is unreachable) the count is -1 rather than failing the whole listing.

type Result

type Result struct {
	Columns  []string
	Rows     [][]any
	Warnings []string
}

Result holds the columns and rows produced by a resolved query, plus any non-fatal warnings gathered while fetching (e.g. a connector truncated at a cap, so the result may be incomplete).

func (*Result) Project

func (r *Result) Project(cols []string) (*Result, error)

Project returns a copy of the result narrowed to cols, in the given order. An empty cols list returns the result unchanged (all columns). It errors if a requested column is not present, listing the columns that are available, so a stale saved-query projection fails loudly rather than silently dropping data.

func (*Result) Write

func (r *Result) Write(w io.Writer, format string) error

Write renders the result to w in the requested format: "table", "json", or "csv".

type SchemaSummary

type SchemaSummary struct {
	Schema     string
	TableCount int  // number of tables, or -1 when a dynamic source couldn't be listed
	Dynamic    bool // true when the connector lists/describes tables on demand
}

SchemaSummary is one schema's entry in the top-level `dfetch tables` listing.

Jump to

Keyboard shortcuts

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