sqlserve

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sqlserve asks `brevis-sql serve` for a preview or for a query.

THE ENGINE'S FIRST OUTBOUND CALL, and the reason it is a package rather than six lines in a handler: a thing that reaches out has a timeout, a set of failure modes a screen has to show, and a rule about which of the other service's words may be repeated. Those are decisions, and they belong somewhere they can be read and tested.

IT HOLDS NO WAREHOUSE CREDENTIAL AND NO DRIVER. That is the whole point of `serve` existing: the console forwards a question and never learns how to answer it. `engine-weight.sh` is the test of that claim.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConnection = errors.New("no connection is declared for that destination")

ErrNoConnection is `serve` saying nothing is DECLARED for that destination, as opposed to declared and unreachable.

MATCHED ON A CODE AND NEVER ON THE SENTENCE. The service's wording is not its contract -- the next person to improve a message would otherwise break a screen -- and the sentence it sends names nothing, deliberately, because its refusals never echo their input. The page says which database, because the page holds the target.

View Source
var ErrNotConfigured = errors.New("no SQL service is configured for this console")

ErrNotConfigured is "nobody told this console where serve is".

Functions

This section is empty.

Types

type Client

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

Client reaches one `brevis-sql serve`.

func New

func New(base, token string) *Client

New builds a client. An empty base is a console with no service configured, and Preview says so rather than dialling nothing.

func (*Client) Columns

func (c *Client) Columns(ctx context.Context, target, schema, name string) ([]Column, error)

Columns asks what ONE relation holds, for the tree's open node.

LAZY, AND THAT IS THE POINT. `Objects` answers for a whole connection in one call because BigQuery bills a flat floor per metadata query; columns invert it -- a project-wide COLUMNS query is the one metadata answer that is genuinely large. So this console asks only about what somebody opened, and the service holds the answer per relation.

func (*Client) Configured

func (c *Client) Configured() bool

Configured says whether there is a service to ask. The page uses it to decide whether a Preview tab exists at all -- a tab that always answers "not configured" is a tab nobody wants.

func (*Client) Estimate

func (c *Client) Estimate(ctx context.Context, target, statement string) (Price, error)

Estimate prices a statement without running it.

WHAT THIS COSTS AND WHO PAYS. A dry run is free of charge on BigQuery and still counts against the project's API quota, which is the client's. The service holds the rate limit -- `/v1/estimate` is the one endpoint there that spends nothing and so needs one -- and this console holds the pause before asking.

func (*Client) Objects

func (c *Client) Objects(ctx context.Context, target string) (Objects, error)

Objects asks what a connection holds, for the workbench's tree.

IT COSTS MONEY THE FIRST TIME and nothing afterwards: the service holds one answer per connection, because every metadata query on BigQuery is billed at a 10 MiB floor whatever comes back. This console asks on each render and the service decides whether that is a round trip.

func (*Client) Preview

func (c *Client) Preview(ctx context.Context, target string, limit int) (Result, error)

Preview asks for the first rows of a destination.

WHAT IT REPEATS AND WHAT IT SWALLOWS is the decision here. A 400 from `serve` is a sentence written to be read by a person -- "that target is not a table" -- and it already refuses to echo its input, so it is carried through. Everything else is not: a 401 means this console's token is wrong, which is an operator's problem and not a reader's, and a 502 carries a host, a role or a project from a driver. Repeating either tells a browser about a service it cannot reach and should not learn about.

func (*Client) Query

func (c *Client) Query(ctx context.Context, target, statement string, limit int) (Result, error)

Query runs a statement somebody typed.

THE CONSOLE DOES NOT READ THE SQL. It does not classify it, does not count its statements and does not price it: every one of those is a limit, a limit the caller can change is not a limit, and the caller here is a browser. `serve` decides, and what comes back is either rows or a sentence.

type Column

type Column struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

Column is one field of a relation.

type Objects

type Objects struct {
	Relations []Relation `json:"relations"`
	// Truncated says the service cut the answer, which the tree has to draw:
	// a browser silently missing half a warehouse is worse than one that
	// says it is showing part.
	Truncated bool `json:"truncated"`

	// Writable says a statement on THIS connection may change data, which
	// the console draws and never decides. It arrives here rather than on an
	// endpoint of its own because the tree already asks this question about
	// this connection.
	Writable bool `json:"writable"`
}

Objects is what a connection holds.

type Price

type Price struct {
	// State is "priced", "refused" or "unpriced", and the screen draws the
	// three differently: a figure, a warning, and a plain sentence. A
	// warehouse with nothing to say is not a problem with somebody's SQL,
	// and drawing it like one would teach them to ignore the line.
	State string

	// Bytes is what the statement would process, when State is "priced".
	Bytes int64

	// Why is the service's own sentence, when there is no number. It is
	// carried through unchanged: a console that reworded the ceiling's
	// refusal would drift from what actually happens at Run.
	Why string
}

Price is what the service said about a statement before it ran: either a number of bytes or a sentence.

ONE TYPE AND NOT AN ERROR PER CASE. A ceiling's refusal, a syntax error in the warehouse's own words and "this warehouse does not price a query" are three different things to a person and the same thing to this console: a sentence to put under the editor instead of a figure. What is NOT in here is the fourth case -- a service that is busy, rate-limited or unreachable -- because that says nothing about the statement and the line stays quiet.

type Refused

type Refused struct{ Why string }

Refused is the service declining a statement, in its own words: a write, a scan over the ceiling, an exhausted budget. It does not say which -- the service sends no code for these -- so a page titles it once and shows the sentence, and never matches on it.

func (*Refused) Error

func (r *Refused) Error() string

type Relation

type Relation struct {
	Schema string `json:"schema"`
	Name   string `json:"name"`
}

Relation is one thing a SELECT could name, as the tree draws it.

type Result

type Result struct {
	Columns []string `json:"columns"`
	// Rows holds `any` because NULL IS NOT THE EMPTY STRING: one is "nothing
	// was recorded" and the other is a value somebody wrote, and they are
	// drawn differently. A nil cell is NULL, all the way to the template.
	Rows      [][]any `json:"rows"`
	Truncated bool    `json:"truncated"`
	Limit     int     `json:"limit"`

	// Bytes is what the warehouse says it scanned, Millis how long it took.
	// Both are zero for a preview, which does not report them: a preview is
	// a glance and nobody chose its cost. For a query they go UNDER THE GRID,
	// because the difference between the query somebody wrote and the one
	// that was cheap is the thing a query tab can actually teach.
	Bytes  int64 `json:"bytes"`
	Millis int64 `json:"ms"`

	// Wrote says the statement CHANGED data, and Changed how many rows.
	//
	// A POINTER, because zero is an answer and absence is a different one.
	// An UPDATE whose WHERE matched nothing changed zero rows; a CREATE
	// TABLE changes no rows at all. A screen that said "0 rows" for the
	// second would read as a failure, and whoever ran it would run it again.
	//
	// The console still does not read the SQL. It is told what happened by
	// the only thing that can know -- the service that ran it.
	Wrote   bool   `json:"wrote"`
	Changed *int64 `json:"changed"`
}

Result is what came back, as a page needs it.

Jump to

Keyboard shortcuts

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