endtoend

package
v0.0.0-...-bdbe55d Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package endtoend finds the analyze cases under internal/endtoend/testdata and compares an engine's own answer with the output a case committed, the way the dialect package compares a generated dialect with the committed one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rewrite

func Rewrite(sql string, bind func(name, lastWord string) string) string

Rewrite replaces every parameter reference in a query — ?, sqlc.arg(name), sqlc.narg(name), sqlc.slice(name) and ClickHouse's {name:Type} — with what bind returns for it, in order of appearance, skipping string literals, quoted identifiers and comments. bind is handed the name, empty for a ?, and the word before the reference, so that a LIMIT or OFFSET can be bound differently from a value; the second count of a LIMIT ?, ? is handed LIMIT as well. Each engine decides what a reference becomes and how the references are numbered.

func Testdata

func Testdata() (string, error)

Testdata returns the end-to-end testdata directory, found relative to this source file so the working directory does not matter.

Types

type Case

type Case struct {
	Name    string // analyze_params/clickhouse
	Dir     string
	Schema  string
	Query   string
	Fixture string // empty when the case has no fixture.sql
	Output  string
}

Case is one analyze case: the files sqlc analyze ran with, the fixture loaded before the queries run against a real database, and the output sqlc committed.

func Cases

func Cases(engine string) ([]Case, error)

Cases lists the analyze cases for an engine: every analyze_*/<engine> directory whose exec.json runs the analyze command. A case that asks for the AST is skipped, since only sqlc can print that.

func (Case) Compare

func (c Case) Compare(got []byte) (string, error)

Compare checks an engine's answer against the case's committed output byte for byte and returns a line diff when they differ, or "" when they match.

func (Case) Queries

func (c Case) Queries() ([]Query, error)

Queries reads the case's query file and splits it into its queries.

type Query

type Query struct {
	Name string
	Cmd  string
	SQL  string
}

Query is one entry of a sqlc query file.

func ParseQueries

func ParseQueries(src string) ([]Query, error)

ParseQueries splits a sqlc query file on its `-- name: X :cmd` headers.

Jump to

Keyboard shortcuts

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