core

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConstInteger = "integer"
	ConstFloat   = "float"
	ConstString  = "string"
	ConstBool    = "bool"
)

Constant kinds. A literal in a query has no declared type, so each dialect names the type its literals take on.

View Source
const ArraySuffix = "[]"

ArraySuffix is the suffix a schema appends to an element type's spelling to name an array of it, which ParseTypeExpr reads as one array dimension.

View Source
const ArrayTypeName = "array"

ArrayTypeName is the family every dialect's array is an instance of: an array of integers is array(integer), whatever the dialect spells it.

View Source
const FlagBoolType = "types.bool"

FlagBoolType holds the type a comparison or predicate yields, when it is not the type a boolean literal has: ClickHouse compares to UInt8 while writing true as Bool.

View Source
const FlagCastCategories = "casts.categories"

FlagCastCategories holds the categories whose types are all implicitly castable to one another, as the dialect's seed declared them, so that a type arriving after the seed — an extension's, say — can join its category.

View Source
const FlagComparisonOperators = "operators.comparison"

FlagComparisonOperators holds the dialect's comparison operators as a comma-separated list, so that a type declared by a schema can be given the same ones the seeded types have.

View Source
const FlagDefaultSchema = "schema.default"

FlagDefaultSchema holds the schema the dialect puts an unqualified object in, when that is not the catalog's own default: a type in it is reported without its schema.

View Source
const FlagIdentArgs = "types.ident_args"

FlagIdentArgs holds the argument positions that are identifiers in a family, as "family:1,2;family:1".

View Source
const FlagIdents = "types.idents"

FlagIdents holds the words that are identifiers wherever they stand as a type argument, comma-separated.

View Source
const FlagLimitType = "types.limit"

FlagLimitType holds the type a LIMIT or OFFSET count has, which is what a placeholder in one is typed as.

View Source
const FlagPropagateNullable = "functions.propagate_nullable"

FlagPropagateNullable is set when a function's result is nullable whenever one of its arguments is, the way ClickHouse's ordinary functions behave.

View Source
const FlagQualifyDuplicateColumns = "columns.qualify_duplicates"

FlagQualifyDuplicateColumns is set for a dialect that names a result column after its relation when an earlier result column from another relation has the same name, as ClickHouse names the second id of a join e.id.

View Source
const FlagUntypedType = "types.untyped"

FlagUntypedType holds the type a placeholder takes when nothing in the query constrains it, for a dialect that gives such a placeholder one.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributeDetails

type AttributeDetails struct {
	Schema        string
	Table         string
	Column        string
	Num           int
	DeclType      string
	AutoIncrement bool
	IsPrimaryKey  bool
	IsUnique      bool
	NotNull       bool
}

type AttributeSpec

type AttributeSpec struct {
	ClassOID      int64
	Name          string
	TypeOID       int64
	Num           int
	NotNull       bool
	HasDefault    bool
	DeclType      string
	AutoIncrement bool
	IsPrimaryKey  bool
	IsUnique      bool
	// Hidden columns resolve by name but stay out of a star expansion and
	// the relation's model, like the column an sqlite fts5 table names
	// after itself.
	Hidden bool
}

type CastSpec

type CastSpec struct {
	SourceTypeOID int64
	TargetTypeOID int64
	ProcOID       int64
	Context       string
	DialectOID    int64
}

type Catalog

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

func New

func New(opts ...Option) (*Catalog, error)

func NewCached

func NewCached(dialect string, schema []string, apply func(*Catalog) error, opts ...Option) (*Catalog, error)

NewCached returns the catalog a dialect and a schema produce, restored from the cache when a run has produced it before.

Producing one means seeding the dialect — thousands of rows, since PostgreSQL's functions and system catalogs alone run to five figures — and then parsing the schema and applying its DDL. The result is the same every time, so the finished database is stored in the cache and opened directly on the next run, turning all of that work into opening a file. It is a single action: the dialect and the schema together are what the catalog is, so they are one key, and a hit means apply is never called.

The dialect data is embedded in the sqlc binary, whose digest is an input to every action, so the dialect only has to be named. The schema is hashed in the order it is applied, since DDL order decides what the catalog holds.

A catalog whose apply fails is returned but not cached, so that a caller can report the failure against the catalog it got. A nil catalog means the catalog could not be created at all. A cache that cannot be opened, read or written is not an error: the catalog is simply built the long way.

func (*Catalog) AddTypeAffinity

func (c *Catalog) AddTypeAffinity(ord int, words []string, typeOID int64) error

AddTypeAffinity records the next step of the dialect's affinity rule: a family whose name contains one of words, upper-cased, stands on typeOID. No words is the default that ends the rule.

func (*Catalog) AddTypeRewrite

func (c *Catalog) AddTypeRewrite(ord int, pattern, template, cond string) error

AddTypeRewrite records a rewrite of the catalog's dialect, applied after the ones recorded before it.

func (*Catalog) BoolTypeOID

func (c *Catalog) BoolTypeOID() (int64, error)

BoolTypeOID returns the type a comparison or predicate yields.

func (*Catalog) CastAllowed

func (c *Catalog) CastAllowed(src, tgt int64, ctx string) (bool, error)

func (*Catalog) ClassCodegenColumns

func (c *Catalog) ClassCodegenColumns(classOID int64) ([]CodegenColumn, error)

func (*Catalog) ClassColumns

func (c *Catalog) ClassColumns(classOID int64) ([]ClassColumn, error)

ClassColumns returns a relation's columns in ordinal order.

func (*Catalog) ClassOID

func (c *Catalog) ClassOID(namespaceOID int64, name string) (int64, error)

func (*Catalog) ClassOIDByName

func (c *Catalog) ClassOIDByName(name string) (int64, error)

func (*Catalog) Close

func (c *Catalog) Close() error

func (*Catalog) ConstTypeOID

func (c *Catalog) ConstTypeOID(kind string) (int64, error)

ConstTypeOID returns the type a literal of the given kind takes on.

func (*Catalog) CreateAttribute

func (c *Catalog) CreateAttribute(classOID int64, name string, typeOID int64, notNull bool, hasDefault bool, num int) error

func (*Catalog) CreateAttributeSpec

func (c *Catalog) CreateAttributeSpec(s AttributeSpec) error

func (*Catalog) CreateCast

func (c *Catalog) CreateCast(cs CastSpec) error

func (*Catalog) CreateClass

func (c *Catalog) CreateClass(namespaceOID int64, name string, kind string) (int64, error)

func (*Catalog) CreateConstraint

func (c *Catalog) CreateConstraint(classOID int64, name string, kind string, columns string) error

func (*Catalog) CreateDialect

func (c *Catalog) CreateDialect(name string) (int64, error)

func (*Catalog) CreateNamespace

func (c *Catalog) CreateNamespace(name string) (int64, error)

func (*Catalog) CreateOperator

func (c *Catalog) CreateOperator(o OperatorSpec) (int64, error)

func (*Catalog) CreateProc

func (c *Catalog) CreateProc(p ProcSpec) (int64, error)

func (*Catalog) CreateType

func (c *Catalog) CreateType(name string) (int64, error)

func (*Catalog) CreateTypeSpec

func (c *Catalog) CreateTypeSpec(t TypeSpec) (int64, error)

CreateTypeSpec inserts a type row. It is the raw insert: nothing is canonicalized and no arguments are written, so it is what the seed and ResolveTypeExpr build on rather than what a caller with an expression wants.

func (*Catalog) CreateTypeWithArgs

func (c *Catalog) CreateTypeWithArgs(spec TypeSpec, args []TypeArg) (int64, error)

CreateTypeWithArgs registers a declared type that has arguments of its own — a composite's fields, an enum's labels — as a family row carrying them. The arguments' types are interned first.

func (*Catalog) CreateUserType

func (c *Catalog) CreateUserType(name, category string) (int64, error)

CreateUserType registers a type family a schema declared rather than the dialect, such as an enum or a name the dialect's seed does not list. The type gains the dialect's comparison operators, so a column of it can be compared.

func (*Catalog) DB

func (c *Catalog) DB() *sql.DB

func (*Catalog) DefaultNamespaces

func (c *Catalog) DefaultNamespaces() []string

DefaultNamespaces lists the namespaces a type is reported from without qualification: the catalog's default, PostgreSQL's system catalog, and the dialect's own default schema when it names one.

func (*Catalog) DialectFlag

func (c *Catalog) DialectFlag(dialectOID int64, key string) (string, error)

func (*Catalog) DialectOID

func (c *Catalog) DialectOID(name string) (int64, error)

func (*Catalog) DropAttribute

func (c *Catalog) DropAttribute(classOID int64, name string) error

DropAttribute removes a column from a relation.

func (*Catalog) DropClass

func (c *Catalog) DropClass(classOID int64) error

func (*Catalog) FindCast

func (c *Catalog) FindCast(src, tgt int64) (CastSpec, bool, error)

func (*Catalog) FindOperators

func (c *Catalog) FindOperators(name string, leftTypeOID, rightTypeOID int64) ([]OperatorOverload, error)

FindOperators returns the overloads of name matching the given operand types, where a zero OID means "any".

func (*Catalog) FindProcs

func (c *Catalog) FindProcs(name string, namespaceOIDs []int64) ([]ProcOverload, error)

FindProcs returns the overloads of name, optionally restricted to the given namespaces.

func (*Catalog) IsComparisonOperator

func (c *Catalog) IsComparisonOperator(name string) bool

IsComparisonOperator reports whether the dialect counts name among the operators that compare two values and yield a boolean.

func (*Catalog) LimitTypeOID

func (c *Catalog) LimitTypeOID() (int64, error)

LimitTypeOID returns the type a LIMIT or OFFSET count has, falling back to the type of an integer literal.

func (*Catalog) LoadExtension

func (c *Catalog) LoadExtension(name string) error

LoadExtension applies the named extension's seed to the catalog. An extension already applied, or a dialect with no loader, contributes nothing; an extension the loader does not know is the loader's to ignore.

func (*Catalog) LookupAttribute

func (c *Catalog) LookupAttribute(attOID int64) (AttributeDetails, error)

func (*Catalog) LookupType

func (c *Catalog) LookupType(oid int64) (TypeInfo, error)

LookupType returns what the catalog holds about a type row.

func (*Catalog) LookupTypeExpr

func (c *Catalog) LookupTypeExpr(t *TypeExpr) (TypeLookup, bool)

LookupTypeExpr finds the row an expression names without writing, and reports false when the family is not one the catalog holds.

func (*Catalog) NamespaceOID

func (c *Catalog) NamespaceOID(name string) (int64, error)

func (*Catalog) Namespaces

func (c *Catalog) Namespaces() ([]NamespaceInfo, error)

func (*Catalog) NextAttributeNum

func (c *Catalog) NextAttributeNum(classOID int64) (int, error)

NextAttributeNum is the ordinal a column added to the relation takes.

func (*Catalog) PropagatesNullable

func (c *Catalog) PropagatesNullable() bool

PropagatesNullable reports whether a function's result is nullable whenever one of its arguments is.

func (*Catalog) QualifiesDuplicateColumns

func (c *Catalog) QualifiesDuplicateColumns() bool

QualifiesDuplicateColumns reports whether a result column that repeats an earlier one's name from another relation is named after its relation.

func (*Catalog) RenameAttribute

func (c *Catalog) RenameAttribute(classOID int64, name, newName string) error

RenameAttribute renames a column.

func (*Catalog) RenameClass

func (c *Catalog) RenameClass(classOID int64, name string) error

func (*Catalog) ResolutionChain

func (c *Catalog) ResolutionChain(oid int64) []int64

ResolutionChain lists the type and every row resolution falls back to, in order, ending with the family everything about the type is registered on.

func (*Catalog) ResolutionOID

func (c *Catalog) ResolutionOID(oid int64) int64

ResolutionOID is the row an operator, function or cast over the type is looked up on when none is registered on the type itself: an instance's family, an alias's canonical type, a domain's or wrapper's base. It returns 0 when there is nothing further to fall back to.

func (*Catalog) ResolveColumn

func (c *Catalog) ResolveColumn(table, column string) (*ColumnInfo, error)

func (*Catalog) ResolvePseudoTypeExpr

func (c *Catalog) ResolvePseudoTypeExpr(t *TypeExpr) (int64, error)

ResolvePseudoTypeExpr is ResolveTypeExpr for the type a function signature names. Signatures reference pseudo-types ("any", "record") and types no dialect bothers to list, so an unknown family is registered as an opaque type rather than rejected, and gets no operators of its own.

func (*Catalog) ResolveType

func (c *Catalog) ResolveType(tn *ast.TypeName) (int64, error)

ResolveType interns the type an AST node names, registering it when the dialect's seed did not: a schema is free to declare types of its own.

func (*Catalog) ResolveTypeExpr

func (c *Catalog) ResolveTypeExpr(t *TypeExpr) (int64, error)

ResolveTypeExpr interns the type an expression names and returns its row: the family for a bare name, the instance for a family applied to arguments, each argument type interned first. Names are canonicalized, so integer and int4 intern to one row. A family the dialect did not seed is one the schema declared, and is registered as a user type.

func (*Catalog) ResolveTypeName

func (c *Catalog) ResolveTypeName(name string) (int64, error)

ResolveTypeName is ResolveTypeExpr for a type spelled as a string.

func (*Catalog) SeededDialectOID

func (c *Catalog) SeededDialectOID() int64

SeededDialectOID returns the dialect this catalog was seeded with, which is what anything registered after seeding — an extension's types and functions — records as its dialect.

func (*Catalog) SetAttributeNotNull

func (c *Catalog) SetAttributeNotNull(classOID int64, name string, notNull bool) error

SetAttributeNotNull records whether a column accepts NULL.

func (*Catalog) SetAttributePrimaryKey

func (c *Catalog) SetAttributePrimaryKey(classOID int64, columns []string) error

func (*Catalog) SetAttributeType

func (c *Catalog) SetAttributeType(classOID int64, name string, typeOID int64, declType string) error

SetAttributeType changes a column's type.

func (*Catalog) SetAttributeUnique

func (c *Catalog) SetAttributeUnique(classOID int64, columns []string) error

func (*Catalog) SetConstType

func (c *Catalog) SetConstType(dialectOID int64, kind, typeName string) error

SetConstType records the type a literal of the given kind takes on in this dialect.

func (*Catalog) SetDialectFlag

func (c *Catalog) SetDialectFlag(dialectOID int64, key, value string) error

func (*Catalog) SetExtensionLoader

func (c *Catalog) SetExtensionLoader(fn func(name string) error)

SetExtensionLoader installs the function CREATE EXTENSION calls to apply an extension's seed. A dialect without extension data leaves it unset.

func (*Catalog) TableColumns

func (c *Catalog) TableColumns(table string) ([]ColumnInfo, error)

func (*Catalog) TablesInNamespace

func (c *Catalog) TablesInNamespace(namespaceOID int64) ([]ClassInfo, error)

func (*Catalog) TypeDeclared

func (c *Catalog) TypeDeclared(name string) bool

TypeDeclared reports whether a schema's CREATE TYPE would redeclare a type: one of that name in the namespace the name qualifies, or in the default namespaces for a bare name.

func (*Catalog) TypeExprOf

func (c *Catalog) TypeExprOf(oid int64) (*TypeExpr, error)

TypeExprOf is the expression a type row stands for, read back from its arguments: the family's name for a family, the family applied to its arguments for an instance. The result is the caller's to change.

func (*Catalog) TypeName

func (c *Catalog) TypeName(oid int64) (string, error)

TypeName returns the family name of a type row.

func (*Catalog) TypeOID

func (c *Catalog) TypeOID(name string) (int64, error)

TypeOID returns the family a name refers to: an alias spelling resolves to the type it names.

func (*Catalog) TypeOIDsInCategory

func (c *Catalog) TypeOIDsInCategory(category string) ([]int64, error)

TypeOIDsInCategory returns the type families the catalog's dialect has in the named category, in the order they were created.

func (*Catalog) UntypedTypeOID

func (c *Catalog) UntypedTypeOID() (int64, bool)

UntypedTypeOID returns the type an unconstrained placeholder takes, and whether the dialect gives it one at all.

type ClassColumn

type ClassColumn struct {
	AttOID  int64
	Name    string
	TypeOID int64
	// Type is the column's type as an expression, set for a column of a
	// derived relation whose type the catalog holds no row for, or holds
	// only the family of.
	Type    *TypeExpr
	NotNull bool
	Hidden  bool
}

type ClassInfo

type ClassInfo struct {
	OID  int64
	Name string
}

type CodegenColumn

type CodegenColumn struct {
	Name    string
	TypeOID int64
	NotNull bool
}

type Column

type Column struct {
	Name     string `json:"name"`
	DataType string `json:"data_type"`
	// Type is the column's type as an expression, carrying what DataType
	// and IsArray flatten away: arguments, nesting and inner nullability.
	Type               *TypeExpr     `json:"type,omitempty"`
	TypeOID            int64         `json:"type_oid,omitempty"`
	NotNull            bool          `json:"not_null"`
	IsArray            bool          `json:"is_array,omitempty"`
	SourceClassOID     int64         `json:"source_class_oid,omitempty"`
	SourceAttributeOID int64         `json:"source_attribute_oid,omitempty"`
	Source             *ColumnSource `json:"source,omitempty"`
	DeclType           string        `json:"decl_type,omitempty"`
	IsPrimaryKey       bool          `json:"is_primary_key,omitempty"`
	IsUnique           bool          `json:"is_unique,omitempty"`
	IsAutoIncrement    bool          `json:"is_auto_increment,omitempty"`
}

type ColumnInfo

type ColumnInfo struct {
	Name          string
	TypeName      string
	TypeOID       int64
	NotNull       bool
	DeclType      string
	AutoIncrement bool
	IsPrimaryKey  bool
	IsUnique      bool
	AttributeOID  int64
	ClassOID      int64
}

type ColumnSource

type ColumnSource struct {
	Schema     string `json:"schema,omitempty"`
	Table      string `json:"table,omitempty"`
	TableAlias string `json:"table_alias,omitempty"`
	Column     string `json:"column,omitempty"`
}

type Command

type Command string
const (
	CommandSelect Command = "SELECT"
	CommandInsert Command = "INSERT"
	CommandUpdate Command = "UPDATE"
	CommandDelete Command = "DELETE"
)

type NamespaceInfo

type NamespaceInfo struct {
	OID  int64
	Name string
}

type OperatorOverload

type OperatorOverload struct {
	OID           int64
	Name          string
	LeftTypeOID   int64
	RightTypeOID  int64
	ResultTypeOID int64
	ProcOID       int64
}

type OperatorSpec

type OperatorSpec struct {
	Name          string
	NamespaceOID  int64
	DialectOID    int64
	LeftTypeOID   int64
	RightTypeOID  int64
	ResultTypeOID int64
	ProcOID       int64
}

type Option

type Option func(*Catalog) error

func WithSeed

func WithSeed(fn func(*Catalog) error) Option

type Parameter

type Parameter struct {
	Number   int           `json:"number"`
	Name     string        `json:"name,omitempty"`
	DataType string        `json:"data_type,omitempty"`
	Type     *TypeExpr     `json:"type,omitempty"`
	TypeOID  int64         `json:"type_oid,omitempty"`
	NotNull  bool          `json:"not_null"`
	IsArray  bool          `json:"is_array,omitempty"`
	Source   *ColumnSource `json:"source,omitempty"`
}

type PrepareResult

type PrepareResult struct {
	Command    Command         `json:"command,omitempty"`
	Columns    []Column        `json:"columns"`
	Parameters []Parameter     `json:"parameters"`
	Stars      []StarExpansion `json:"stars,omitempty"`
}

type ProcArg

type ProcArg struct {
	Name       string
	TypeOID    int64
	Mode       string
	HasDefault bool
}

type ProcOverload

type ProcOverload struct {
	OID            int64
	Name           string
	Kind           string
	ReturnTypeOID  int64
	ReturnNullable bool
	NeverNull      bool
	ReturnTemplate string
	ArgTypes       []int64
}

type ProcSpec

type ProcSpec struct {
	Name           string
	NamespaceOID   int64
	DialectOID     int64
	Kind           string
	ReturnTypeOID  int64
	ReturnSet      bool
	ReturnNullable bool
	// NeverNull marks a function whose result is never NULL even when an
	// argument is, in a dialect that otherwise propagates nullability.
	NeverNull bool
	// ReturnTemplate is the result as an expression over the call's
	// arguments, when it depends on their values: Decimal(18, $2) for
	// toDecimal64(x, s).
	ReturnTemplate string
	Strict         bool
	VariadicKind   string
	Args           []ProcArg
}

type StarColumn

type StarColumn struct {
	// Relation is the name the column's relation goes by in the query, which
	// is its alias when it was given one.
	Relation string `json:"relation,omitempty"`
	Name     string `json:"name"`
	DataType string `json:"data_type,omitempty"`
}

StarColumn is a single column a star expanded to.

type StarExpansion

type StarExpansion struct {
	// Location is where the target the star belongs to starts, measured the
	// way the AST measures a node: from the beginning of the file the
	// statement was parsed from.
	Location int `json:"location"`

	// Fields is the reference as it was written, with the star as its last
	// element: ["*"] for a bare star and ["foo", "*"] for a qualified one.
	Fields []string `json:"fields"`

	// Alias is the output name the target was given, if any.
	Alias string `json:"alias,omitempty"`

	Columns []StarColumn `json:"columns"`
}

StarExpansion is what a star in a target list stands for. The analyzer resolves the reference against the query's scope and reports the columns it covers; rewriting the query text with them is the caller's to do, since only it knows how the engine quotes an identifier.

type TypeArg

type TypeArg struct {
	Label  string    `json:"label,omitempty"`
	Type   *TypeExpr `json:"type,omitempty"`
	Int    *int64    `json:"int,omitempty"`
	Bool   *bool     `json:"bool,omitempty"`
	String *string   `json:"string,omitempty"`
	Ident  *string   `json:"ident,omitempty"`
}

TypeArg is one argument of a TypeExpr: exactly one of Type, Int, Bool, String or Ident is set. Ident is a bare word that is not a type — the max of nvarchar(max), the function of SimpleAggregateFunction(sum, UInt64), the fields of interval day to second.

type TypeExpr

type TypeExpr struct {
	Name     string    `json:"name"`
	Nullable bool      `json:"nullable,omitempty"`
	Args     []TypeArg `json:"args,omitempty"`
}

TypeExpr is a type written as a call expression: a lowercased name applied to arguments that are other types, integers, booleans or strings, each with an optional label, and a nullable flag at whatever depth it applies. Nothing about a nested type is special-cased, so an array of nullable strings is array(string nullable), a map is map(string, uint32) and a named tuple is tuple(lat: float64, lon: float64). The catalog resolves the names; the expression only records what was declared or inferred.

func Array

func Array(element *TypeExpr) *TypeExpr

Array wraps element in one array dimension.

func ColumnTypeExpr

func ColumnTypeExpr(col *ast.ColumnDef) *TypeExpr

ColumnTypeExpr reads a column definition's type. Engines report an array column either on the type name or on the column itself.

func ParseTypeExpr

func ParseTypeExpr(s string) *TypeExpr

ParseTypeExpr reads a type spelled the way every dialect spells one, as a name optionally applied to a parenthesised, comma-separated argument list whose entries may be labelled (`lat Float64` in a tuple, `'a' = 1` in an enum). A Nullable(T) wrapper becomes T with Nullable set, and a trailing [] becomes an array of the element.

func TypeExprOfTypeName

func TypeExprOfTypeName(tn *ast.TypeName) *TypeExpr

TypeExprOfTypeName reads the type an AST node names into an expression. An engine that renders the whole type as a call expression — DuckDB's struct(a: integer, b: varchar) — hands it over in Canonical; one that folds it into the spelling the formatter prints back — ClickHouse's Array(Nullable(String)), SQLite's VARYING CHARACTER(10) — in Spelling. Otherwise the name comes from Name or the qualifying parts of Names, the type modifiers become integer or string arguments, and each array bound wraps the result in an array.

func (*TypeExpr) ArrayDims

func (t *TypeExpr) ArrayDims() int

ArrayDims counts the array dimensions wrapped around the expression's innermost type, and Innermost is that type: the integer of an array of arrays of integers.

func (*TypeExpr) Clone

func (t *TypeExpr) Clone() *TypeExpr

Clone copies the expression, arguments and all, so that a caller can set nullability on the copy without touching a cached one.

func (*TypeExpr) Element

func (t *TypeExpr) Element() *TypeExpr

Element is an array's element type, or nil for anything else.

func (*TypeExpr) HasNullable

func (t *TypeExpr) HasNullable() bool

HasNullable reports whether the expression marks nullability anywhere, which tells whether the spelling it came from said so itself.

func (*TypeExpr) Innermost

func (t *TypeExpr) Innermost() *TypeExpr

func (*TypeExpr) IsArray

func (t *TypeExpr) IsArray() bool

IsArray reports whether the expression is an array.

func (*TypeExpr) Key

func (t *TypeExpr) Key() string

Key is the expression's canonical spelling, which identifies its row in the catalog: the expression's own nullability is not part of it, since a row is never nullable, while the nullability of a nested type is.

func (*TypeExpr) String

func (t *TypeExpr) String() string

String renders the expression in its canonical text form, with a trailing "nullable" marking a nullable type.

func (*TypeExpr) WithNullable

func (t *TypeExpr) WithNullable(nullable bool) *TypeExpr

WithNullable returns a copy of the expression with its own nullability set as given; the nullability of a nested type is left alone.

type TypeInfo

type TypeInfo struct {
	OID          int64
	NamespaceOID int64
	Name         string
	Expr         string
	Category     string
	Typtype      string
	Preferred    bool
	FamilyOID    int64
	ElementOID   int64
	BaseOID      int64
	CanonicalOID int64
	NotNull      bool
}

TypeInfo is a type row as the catalog holds it.

func (TypeInfo) IsFamily

func (t TypeInfo) IsFamily() bool

IsFamily reports whether the row is a family rather than an instance.

type TypeLookup

type TypeLookup struct {
	// OID is the instance row when the catalog holds one, otherwise the
	// family row.
	OID int64
	// FamilyOID is the family, which is OID for a family or an instance the
	// catalog does not hold.
	FamilyOID int64
	// Expr is the expression canonicalized: the family and every argument
	// type spelled as the catalog spells them, whether or not the instance
	// is a row.
	Expr *TypeExpr
}

TypeLookup is what LookupTypeExpr found for an expression.

type TypeSpec

type TypeSpec struct {
	Name         string
	Expr         string
	Typtype      string
	Category     string
	Preferred    bool
	NamespaceOID int64
	DialectOID   int64
	FamilyOID    int64
	ElementOID   int64
	BaseOID      int64
	CanonicalOID int64
	NotNull      bool
}

TypeSpec describes a type row. Name is the family's name; Expr is the canonical spelling of the whole expression and defaults to the name, which is what a family's is.

Directories

Path Synopsis
Package seed builds a core catalog for a SQL dialect from a declarative description of its type system: the types it defines, the operators and casts between them, and the functions it ships with.
Package seed builds a core catalog for a SQL dialect from a declarative description of its type system: the types it defines, the operators and casts between them, and the functions it ships with.

Jump to

Keyboard shortcuts

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