meta

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg struct {
	// The 1-based index of this argument
	Idx int
	// The golang name of this argument
	GoName string
	// The postgres name of this argument
	PgName string
	// Information about the go version of this type
	TypeInfo types.Info
}

Arg represents an argument to both a postgres query and the golang shim which wraps that query.

fields are only public for template reflection

type ColMeta

type ColMeta struct {
	// postgres's internal column number for this column
	ColNum int32
	// the name of the field in the go struct which corresponds to this column
	GoName string
	// the name of this column in postgres
	PgName string
	// name of the type of this column
	PgType string
	// a more descriptive record of the type of this column
	TypeInfo types.Info
	// true if this column can be null
	Nullable bool
	// the postgres default value for this column
	DefaultExpr string
	// true if this column is the primary key for this table
	IsPrimary bool
	// true if this column has a UNIQUE index on it
	IsUnique bool
	// the tags to attach to the generated field (a combination of fields
	// that pggen computes and user provided tags)
	Tags string
}

ColMeta contains metadata about postgres table columns such column names, types, nullability, default...

type PgTableInfo

type PgTableInfo struct {
	PgName       string
	GoName       string
	PluralGoName string
	// metadata for the primary key column
	PkeyCol *ColMeta
	// Metadata about the tables columns
	Cols []ColMeta
	// A list of the postgres names of tables which reference this one
	IncomingReferences []RefMeta
	// The 0-based index of the primary key column
	PkeyColIdx int
}

PgTableInfo contains metadata about a postgres table that we get directly from postgres. Contrast with the `TableMeta` struct which also contains computed fields that are needed for codegen.

type QueryMeta

type QueryMeta struct {
	// The configuation data for this query from the .toml file
	ConfigData config.QueryConfig
	// The metadata for the arguments to this query
	Args []Arg
	// The metadata for the return values of this function
	ReturnCols []ColMeta
	// Flag indicating if there are multiple columns.
	// Included for the convenience of templates.
	MultiReturn bool
	// The name of the return type for a row returned by this query
	ReturnTypeName string
	// A golang comment derived from the Comment field from the query
	// config.
	Comment string
}

type RefMeta

type RefMeta struct {
	// The metadata for the table that holds the foreign key
	PointsTo *TableMeta
	// The names of the fields in the referenced table that are used as keys
	// (usually the primary keys of that table). Order matters.
	PointsToField *ColMeta
	// The metadata for the table is being referred to
	PointsFrom *TableMeta
	// The names of the fields that are being used to refer to the key fields
	// for the referenced table. Order matters.
	PointsFromField *ColMeta
	// The name of the field that should be generated in the model being pointed
	// to by the foreign key (parent model).
	GoPointsFromFieldName string
	// A snake_case version of GoPointsFromFieldName
	PgPointsFromFieldName string
	// The name of the field that should be generated in the model being pointed
	// from by the foreign key (child model).
	GoPointsToFieldName string
	// A snake_case version of GoPointsToFieldName.
	PgPointsToFieldName string
	// Indicates that there can be at most one of these references between
	// the two tables.
	OneToOne bool
	// Indicates whether or not the foreign key associated with this reference
	// is nullable.
	Nullable bool
}

RefMeta contains metadata for a reference between two tables (a foreign key relationship)

type RegTypeArray

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

func (*RegTypeArray) Scan

func (r *RegTypeArray) Scan(src interface{}) error

Scan implements the `sql.Scanner` interface

type Resolver

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

Resolver knows how to query postgres for metadata about the database schema

func NewResolver

func NewResolver(
	l *log.Logger,
	db *sql.DB,
	typeResolver *types.Resolver,
	registerImport func(string),
) *Resolver

func (*Resolver) Close

func (r *Resolver) Close() error

Close closes the database connection that the resolver holds

func (*Resolver) FuncArgs

func (mc *Resolver) FuncArgs(funcName names.PgName) ([]Arg, error)

Given the name of a postgres stored function, return a list describing its arguments

func (*Resolver) QueryMeta

func (mc *Resolver) QueryMeta(
	config *config.QueryConfig,
	inferArgTypes bool,
) (ret QueryMeta, err error)

func (*Resolver) Resolve

func (r *Resolver) Resolve(conf *config.DbConfig) error

Resolve the metadata for the given database config that needs to be resolved ahead of time.

This method _must_ be called before any of the query methods can be called.

func (*Resolver) StmtMeta

func (mc *Resolver) StmtMeta(
	config *config.StmtConfig,
) (ret StmtMeta, err error)

func (*Resolver) TableMeta

func (r *Resolver) TableMeta(pgName string) (*TableMeta, bool)

Get gen information about the given table

The second return value indicates if the value was found

type StmtMeta

type StmtMeta struct {
	// The configuation data for this stmt from the .toml file
	ConfigData config.StmtConfig
	// The comment as it should be emitted in the generated code
	Comment string
	// The metadata for the arguments to this query
	Args []Arg
}

type TableGenCtx

type TableGenCtx struct {
	// taken from Meta
	PgName string
	// taken from Meta
	GoName string
	// taken from Meta
	PkeyCol *ColMeta
	// taken from Meta
	PkeyColIdx     int
	AllIncludeSpec string
	Meta           *TableMeta
}

This genctx duplicates info already stored in the Meta member, but it is a nice quality of life improvement to have some of the really commonly refered to data bubbled up to the top level.

type TableMeta

type TableMeta struct {
	Config *config.TableConfig
	// All references to this table from other tables (both infered and configured).
	AllIncomingReferences []RefMeta
	// All references from this table to other tables (both infered and configured).
	AllOutgoingReferences []RefMeta
	// The include spec which represents the transitive closure of
	// this tables family
	AllIncludeSpec *include.Spec

	// If true, this table does have an update timestamp field
	HasUpdatedAtField bool
	// True if the update at field can be null
	UpdatedAtFieldIsNullable bool
	// True if the updated at field has a time zone
	UpdatedAtHasTimezone bool
	// The name of the updated at field
	GoUpdatedAtField string

	// If true, this table does have a create timestamp field
	HasCreatedAtField bool
	// True if the created at field can be null
	CreatedAtFieldIsNullable bool
	// True if the created at field has a time zone
	CreatedAtHasTimezone bool
	// The name of the created at field
	GoCreatedAtField string

	// If true, this table has a nullable soft-delete timestamp field
	HasDeletedAtField bool
	// True if the deleleted at timestamp has a timezone
	DeletedAtHasTimezone bool
	// The name of the deleted at field
	PgDeletedAtField string

	// The table metadata as postgres reports it
	Info PgTableInfo
}

TableMeta contains information about a single table required for code generation.

The reason there is both a *Meta and *Info struct for tables is that `PgTableInfo` is meant to be narrowly focused on metadata that postgres provides us, while things in `TableMeta` are more specific to `pggen`'s internal needs and contain some computed fields.

Jump to

Keyboard shortcuts

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