oracle

package
v1.2.0 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: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

oracle

Real PostgreSQL (embedded-postgres, one release per supported major version: binaries in oracle.go) as the ground truth for the pure-Go analyzer.

  • Start(ctx, schemaSQL) boots a fresh instance of the default version in a temp dir; StartVersion(ctx, v, schemaSQL) one of another major version (binaries and an initialized template data directory are cached per release under ~/.cache/sqlshape/pg-<release>, ~0.3 s start after the first download)
  • Describe(ctx, sql) = anonymous PREPARE. Returns parameter types, result column types (as format_type prints them), and table-column provenance with attnotnull. PG rejections come back as *PgError with SQLSTATE and position
  • testdata/queries/*.sql + .golden: the contract the analyzer must reproduce. Regenerate with go test ./internal/oracle -update

Not used at lint time.

Documentation

Overview

Package oracle runs a real PostgreSQL (embedded-postgres) and answers "what does PG say about this statement?" via PREPARE / Describe.

It is the ground truth for differential tests of the pure-Go analyzer. It is not used at lint time.

Index

Constants

This section is empty.

Variables

View Source
var Version = binaries[pgparse.Default]

Version is the release the oracle runs for the default major version.

Functions

func Release added in v1.2.0

func Release(v pgparse.Version) string

Release is the PostgreSQL release run for a major version ("17.5.0").

Types

type Column

type Column struct {
	Name string
	Type Type
	// Source is set when the column comes straight from a table column.
	Source *Source
}

Column is one result column of a described statement.

type Description

type Description struct {
	Params  []Type
	Columns []Column
}

Description is PG's answer for one statement.

func (*Description) String

func (d *Description) String() string

String renders a Description in the golden-file format used by differential tests.

type Oracle

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

Oracle owns one embedded PostgreSQL instance and one connection to it.

func Start

func Start(ctx context.Context, schemaSQL string) (*Oracle, error)

Start boots a fresh PostgreSQL, applies schemaSQL, and returns a ready Oracle.

Booting is made cheap by a cache (see cacheDir): the binaries are extracted once, and the data directory is a copy of one initialized once, so a Start costs a directory copy and a server start rather than an archive extraction and an initdb (~0.3s instead of ~4s). Data lives in a temp dir removed by Close.

func StartVersion added in v1.2.0

func StartVersion(ctx context.Context, v pgparse.Version, schemaSQL string) (*Oracle, error)

StartVersion is Start on the PostgreSQL major version v.

func (*Oracle) Close

func (o *Oracle) Close() error

Close stops PostgreSQL and removes its data directory.

func (*Oracle) Conn

func (o *Oracle) Conn() *pgx.Conn

Conn exposes the underlying connection for tooling (catalog dump). Tests use Describe.

func (*Oracle) ConnString

func (o *Oracle) ConnString() string

ConnString is the connection string of the running server (for pools and other clients).

func (*Oracle) Describe

func (o *Oracle) Describe(ctx context.Context, sql string) (*Description, error)

Describe prepares sql (anonymous statement, nothing persists server-side) and returns PG's parameter and result-column types. A statement PG rejects returns a *PgError.

func (*Oracle) Reconnect

func (o *Oracle) Reconnect(ctx context.Context, database string) error

Reconnect closes the current connection and opens one to another database on the same server. Used by the regress probe, which isolates each test file in its own database created from a template.

func (*Oracle) Session

func (o *Oracle) Session(ctx context.Context, database string) (*Oracle, error)

Session opens another connection to the same server, to the given database, for callers that work in parallel. Closing a session closes only its connection.

func (*Oracle) Version added in v1.2.0

func (o *Oracle) Version() pgparse.Version

Version is the PostgreSQL major version this oracle runs.

type PgError

type PgError struct {
	Code     string // SQLSTATE
	Message  string
	Position int32 // 1-based byte offset into the SQL, 0 if none
}

PgError is the PostgreSQL error for a statement that fails to prepare.

func (*PgError) Error

func (e *PgError) Error() string

type Source

type Source struct {
	Table   string // schema-qualified unless public
	Column  string
	NotNull bool
}

Source is the table column a result column originates from (from Describe's TableOID/attnum).

type Type

type Type struct {
	OID    uint32
	Typmod int32
	// Name is format_type(OID, Typmod), e.g. "numeric(12,2)", "order_status", "bigint[]".
	Name string
}

Type is a PostgreSQL type as PG itself prints it (format_type), plus the raw OID / typmod.

Jump to

Keyboard shortcuts

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