pggen

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 16 Imported by: 0

README

Test Lint GoReportCard

Notice

This is a temporary fork that I have been working on with the intention of backporting the changes to the upstream pggen. It is not fully functional.

Features Supported

The following examples compile, and are implemented.

  • example/author
  • example/domain
  • example/go_pointer_types
  • example/inline_param_count
  • example/pgcrypto
  • example/slices
  • example/syntax
  • example/custom_types
  • example/enums
  • example/device
  • example/function
  • example/nested
  • example/separate_out_dir/out
  • example/erp/order
  • example/ltree
  • example/void

Feature Unsupported

  • example/composite
  • example/complex_params

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts GenerateOptions) (mErr error)

Generate generates language specific code to safely wrap each SQL ast.SourceQuery in opts.QueryFiles.

Generate must only be called once per output directory.

Types

type GenerateOptions

type GenerateOptions struct {
	// What language to generate code in.
	Language Lang
	// The connection string to the running Postgres database to use to get type
	// information for each query in QueryFiles.
	//
	// Must be parseable by pgconn.ParseConfig, like:
	//
	//   # Example DSN
	//   user=jack password=secret host=pg.example.com port=5432 dbname=foo_db sslmode=verify-ca
	//
	//   # Example URL
	//   postgres://jack:secret@pg.example.com:5432/foo_db?sslmode=verify-ca
	ConnString string
	// Generate code for each of the SQL query file paths.
	QueryFiles []string
	// Schema files to run on Postgres init. Can be *.sql, *.sql.gz, or executable
	// *.sh files .
	SchemaFiles []string
	// The name of the Go package for the file. If empty, defaults to the
	// directory name.
	GoPackage string
	// Directory to write generated files. Writes one file for each query file.
	// If more than one query file, also writes querier.go.
	OutputDir string
	// A map of lowercase acronyms to the upper case equivalent, like:
	// "api" => "API", or "apis" => "APIs".
	Acronyms map[string]string
	// A map from a Postgres type name to a fully qualified Go type.
	TypeOverrides map[string]string
	// What log level to log at.
	LogLevel slog.Level
	// How many params to inline when calling querier methods.
	// Set to 0 to always create a struct for params.
	InlineParamCount int
}

GenerateOptions are the unparsed options that controls the generated Go code.

type Lang

type Lang string

Lang is a supported codegen language.

const (
	LangGo Lang = "go"
)

Directories

Path Synopsis
cmd
example
internal
ast
codegen
Package codegen contains common code shared between codegen and language specific code generators.
Package codegen contains common code shared between codegen and language specific code generators.
gomod
Package gomod provides utilities for getting information about the current Go module.
Package gomod provides utilities for getting information about the current Go module.
parser
Package parser contains the exported entry points for invoking the parser.
Package parser contains the exported entry points for invoking the parser.
pg
pgdocker
Package pgdocker creates one-off Postgres docker images to use so pggen can introspect the schema.
Package pgdocker creates one-off Postgres docker images to use so pggen can introspect the schema.

Jump to

Keyboard shortcuts

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