httpsource

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package httpsource translates a datatug project's HTTP-type QueryDefs into a dalgo2http-backed dal.DB: one dalgo2http.Collection per query (see BuildCollection for the translation and its sensible-default policy for RowsPath/KeyField, since the QueryDef JSON schema does not yet carry those explicitly), snapshot fallback wired to the project's fixtures/http/ directory (see fixtureFS for how its flatly-named fixture files are bridged to dalgo2http's per-request snapshot keying), live-then-snapshot mode.

This package is pkg/dbcopy/url.go's http:// / https:// backend (see parseHTTPSource there); it has no dependency on dbcopy and can also be used directly by a caller — a server endpoint handler, a future datatug-cli command — that wants an HTTP-sourced dal.DB for a project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCollection

func BuildCollection(def *datatug.QueryDef, urlTemplate string, sample map[string]any) (dalgo2http.Collection, error)

BuildCollection translates one HTTP QueryDef into a dalgo2http.Collection.

urlTemplate is the sibling .query.http file's content (see LoadURLTemplate). sample, when non-nil, is the query's recorded fixture body (see readFixtureSample) decoded as JSON; it is used ONLY to infer the RowsPath and KeyField defaults documented on inferRowsPath/inferKeyField — never to shape any other field of the returned descriptor, and a nil sample degrades to those functions' no-sample answers rather than failing.

func LoadURLTemplate

func LoadURLTemplate(projectDir, folderPath, id string) (string, error)

LoadURLTemplate reads the URL template for the HTTP query id found in folderPath (as returned by LoadHTTPQueries), trimming surrounding whitespace (the sibling .query.http files in the demo project end with a trailing newline).

func Open

func Open(_ context.Context, projectDir string) (dal.DB, error)

Open builds a dal.DB from every HTTP QueryDef declared under <projectDir>/queries/**. It fails with an error naming projectDir when no HTTP QueryDef is found there: an http(s):// db-copy source with nothing to serve is a configuration mistake (the wrong project path, most often), not a validly-empty database.

Types

type LoadedQuery

type LoadedQuery struct {
	Def        *datatug.QueryDef
	FolderPath string
}

LoadedQuery is one HTTP-type QueryDef found by LoadHTTPQueries, together with the folder it was found in (relative to <projectDir>/queries) — needed to locate its sibling URL-template file alongside it.

func LoadHTTPQueries

func LoadHTTPQueries(projectDir string) ([]LoadedQuery, error)

LoadHTTPQueries scans <projectDir>/queries/** for *.query.json files declaring "type": "HTTP", parsing each into a datatug.QueryDef.

This reads project files directly with encoding/json rather than going through pkg/datatug-core/storage/filestore's generic project-item store, for two reasons: that store's loader does not read a query's sibling text-body file back into QueryDef.Text (only the SAVE path writes it — see store_queries_saver.go; LoadURLTemplate below is this package's own replacement for that missing read), and pulling in the full store abstraction (which also knows about SQL/GraphQL queries, folders, and project-wide caching) for a read-only, HTTP-only scan would add a much larger dependency surface than this package needs.

type Result

type Result struct {
	Records    []record.Record
	Provenance dalgo2http.Provenance
}

Result is what ExecuteQuery returns: the rows a query produced, and the Provenance (live vs snapshot) dalgo2http observed while producing them.

pkg/secureread's Result.Limitations is the natural home for this once it lands (per the stream brief); until then this is the small bridge value a caller — a server endpoint handler, a future secureread integration — reads and forwards into whatever its own result/Limitations shape needs.

func ExecuteQuery

func ExecuteQuery(ctx context.Context, db dal.DB, q dal.Query) (Result, error)

ExecuteQuery runs q against db and returns both its rows and the Provenance dalgo2http observed while running it.

db need not be a database Open returned — ExecuteQuery works against any dal.DB — but Provenance is only ever populated when the backend actually reports one (today, only a dalgo2http-backed db does). Result's zero Provenance value is indistinguishable from "not observed" by design: a caller forwarding it into a Limitations-style note should treat an unpopulated Provenance as "nothing to report", not as "this was live".

Jump to

Keyboard shortcuts

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