pginfer

package
v0.0.0-...-c2f4e09 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Inferrer

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

func NewInferrer

func NewInferrer(conn *pgx.Conn) *Inferrer

NewInferrer infers information about a query by running the query on Postgres and extracting information from the catalog tables.

func (*Inferrer) InferTypes

func (inf *Inferrer) InferTypes(query *ast.SourceQuery) (TypedQuery, error)

type InputParam

type InputParam struct {
	// Name of the param, like 'FirstName' in pggen.arg('FirstName').
	PgName string
	// Default value to use for the param when executing the query on Postgres.
	// Like 'joe' in pggen.arg('FirstName', 'joe').
	DefaultVal string
	// The postgres type of this param as reported by Postgres.
	PgType pg.Type
}

InputParam is an input parameter for a prepared query.

type OutputColumn

type OutputColumn struct {
	// Name of an output column, named by Postgres, like "foo" in "SELECT 1 as foo".
	PgName string
	// The postgres type of the column as reported by Postgres.
	PgType pg.Type
	// If the type can be null; depends on the query. A column defined
	// with a NOT NULL constraint can still be null in the output with a left
	// join. Nullability is determined using rudimentary control-flow analysis.
	Nullable bool
}

OutputColumn is a single column output from a select query or returning clause in an update, insert, or delete query.

type Plan

type Plan struct {
	Type     PlanType
	Relation string   // target relation if any
	Outputs  []string // the output expressions if any
}

Plan is the plan output from an EXPLAIN query.

type PlanType

type PlanType string

PlanType is the top-level node plan type that Postgres plans for executing query. https://www.postgresql.org/docs/13/executor.html

const (
	PlanResult      PlanType = "Result"      // select statement
	PlanLimit       PlanType = "Limit"       // select statement with a limit
	PlanModifyTable PlanType = "ModifyTable" // update, insert, or delete statement
)

type TypedQuery

type TypedQuery struct {
	// Name of the query, from the comment preceding the query. Like 'FindAuthors'
	// in the source SQL: "-- name: FindAuthors :many"
	Name string
	// The result output kind, :one, :many, or :exec.
	ResultKind ast.ResultKind
	// The comment lines preceding the query, without the SQL comment syntax and
	// excluding the :name line.
	Doc []string
	// The SQL query, with pggen functions replaced with Postgres syntax. Ready
	// to run on Postgres with the PREPARE statement.
	PreparedSQL string
	// The input parameters to the query.
	Inputs []InputParam
	// The output columns of the query.
	Outputs []OutputColumn
	// Qualified protocol buffer message type to use for each output row, like
	// "erp.api.Product". If empty, generate our own Row type.
	ProtobufType string
}

TypedQuery is an enriched form of ast.SourceQuery after running it on Postgres to get information about the ast.SourceQuery.

Jump to

Keyboard shortcuts

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