pgsql

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 13 Imported by: 1

README

BloodHound PgSQL Model

This package contains a syntax model for the PostgreSQL SQL dialect. It also contains a translation implementation to take openCpyher input and output valid PostgreSQL SQL. This model is not intended to be a complete implementation of all available SQL dialect features but rather the subset of the dialect required to perform openCypher to pgsql translation.

Expected PostgreSQL SQL dialect version: 16.X

Formatting

The format package contains the string rendering logic for the PgSQL syntax model.

Translation

The translate package contains the openCypher translation implementation.

Visualization

The visualization package contains a PUML digraph formatter for the PgSQL syntax model.

Test Cases

The test package contains the test cases used to validate translation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAvailableArrayDataType = errors.New("data type has no direct array representation")
)

Functions

func As

func As[T any](node SyntaxNode) (T, error)

As is a helper function that takes a SyntaxNode and attempts to cast it to the type represented by T. If the node passed is equal to nil then the empty value of T is returned. If the typed node does not convert to the type represented by T then an error is returned.

func AsOptionalIdentifier

func AsOptionalIdentifier(identifier Identifier) models.Optional[Identifier]

func IDSliceToInt8Array

func IDSliceToInt8Array(value []graph.ID) (pgtype.Int8Array, error)

func Int32SliceToInt4Array

func Int32SliceToInt4Array(value []int32) (pgtype.Int4Array, error)

func IsAggregateFunction

func IsAggregateFunction(function Identifier) bool

func IsReservedIdentifier

func IsReservedIdentifier(identifier Identifier) bool

func JSONBToProperties

func JSONBToProperties(jsonb pgtype.JSONB) (*graph.Properties, error)

func MapStringAnyToJSONB

func MapStringAnyToJSONB(values map[string]any) (pgtype.JSONB, error)

func MatcherAsJSONB

func MatcherAsJSONB(fieldName string, value any) (pgtype.JSONB, error)

func MustMatcherAsJSONB

func MustMatcherAsJSONB(fieldName string, value any) pgtype.JSONB

func NegotiateValue

func NegotiateValue(value any) (any, error)

func OperatorIsBoolean

func OperatorIsBoolean(operator Expression) bool

func OperatorIsComparator

func OperatorIsComparator(operator Expression) bool

func OperatorIsIn

func OperatorIsIn(operator Expression, matchers ...Expression) bool

func OperatorIsPropertyLookup

func OperatorIsPropertyLookup(operator Expression) bool

func PropertiesToJSONB

func PropertiesToJSONB(properties *graph.Properties) (pgtype.JSONB, error)

func StringSliceToTextArray

func StringSliceToTextArray(values []string) (pgtype.TextArray, error)

func ValueToJSONB

func ValueToJSONB(value any) (pgtype.JSONB, error)

Types

type AliasedExpression

type AliasedExpression struct {
	Expression Expression
	Alias      models.Optional[Identifier]
}

func (AliasedExpression) AsExpression

func (s AliasedExpression) AsExpression() Expression

func (AliasedExpression) AsSelectItem

func (s AliasedExpression) AsSelectItem() SelectItem

func (AliasedExpression) NodeType

func (s AliasedExpression) NodeType() string

type AllExpression

type AllExpression struct {
	Expression
}

func NewAllExpression

func NewAllExpression(inner Expression) AllExpression

type AnyExpression

type AnyExpression struct {
	Expression
	CastType DataType
}

func NewAnyExpression

func NewAnyExpression(inner Expression, castType DataType) *AnyExpression

func NewAnyExpressionHinted

func NewAnyExpressionHinted(inner TypeHinted) *AnyExpression

func (AnyExpression) AsExpression

func (s AnyExpression) AsExpression() Expression

func (AnyExpression) NodeType

func (s AnyExpression) NodeType() string

func (AnyExpression) TypeHint

func (s AnyExpression) TypeHint() DataType

type ArrayExpression

type ArrayExpression struct {
	Expression Expression
}

func (ArrayExpression) AsExpression

func (s ArrayExpression) AsExpression() Expression

func (ArrayExpression) NodeType

func (s ArrayExpression) NodeType() string

type ArrayIndex

type ArrayIndex struct {
	Expression Expression
	Indexes    []Expression
}

func (ArrayIndex) AsExpression

func (s ArrayIndex) AsExpression() Expression

func (ArrayIndex) NodeType

func (s ArrayIndex) NodeType() string

type ArrayLiteral

type ArrayLiteral struct {
	Values   []Expression
	CastType DataType
}

func NewArrayLiteral

func NewArrayLiteral[T any](values []T, castType DataType) (ArrayLiteral, error)

func (ArrayLiteral) AsExpression

func (s ArrayLiteral) AsExpression() Expression

func (ArrayLiteral) AsSelectItem

func (s ArrayLiteral) AsSelectItem() SelectItem

func (ArrayLiteral) NodeType

func (s ArrayLiteral) NodeType() string

func (ArrayLiteral) TypeHint

func (s ArrayLiteral) TypeHint() DataType

type Assignment

type Assignment interface {
	SyntaxNode
	AsAssignment() Assignment
}

Assignment is an expression that can be used as an assignment.

type Between

type Between struct {
	Expression Expression
	Low        Expression
	High       Expression
	Negated    bool
}

Between represents a comparison expression between a low expression and high expression. <expr> [not] between <low> and <high>

type BinaryExpression

type BinaryExpression struct {
	Operator Operator
	LOperand Expression
	ROperand Expression
}

<expr> > <expr> table.column > 12345

func NewBinaryExpression

func NewBinaryExpression(left Expression, operator Operator, right Expression) *BinaryExpression

func NewJSONTextFieldLookup

func NewJSONTextFieldLookup(reference CompoundIdentifier, field Identifier) *BinaryExpression

func NewPropertyLookup

func NewPropertyLookup(identifier CompoundIdentifier, reference Literal) *BinaryExpression

func (BinaryExpression) AsAssignment

func (s BinaryExpression) AsAssignment() Assignment

func (BinaryExpression) AsExpression

func (s BinaryExpression) AsExpression() Expression

func (BinaryExpression) AsSelectItem

func (s BinaryExpression) AsSelectItem() SelectItem

func (BinaryExpression) NodeType

func (s BinaryExpression) NodeType() string

type Case

type Case struct {
	Operand    Expression
	Conditions []Expression
	Then       []Expression
	Else       Expression
}

Case represents a pattern matching syntax node:

CASE

WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result

END;

type CommonTableExpression

type CommonTableExpression struct {
	Alias        TableAlias
	Materialized *Materialized
	Query        Query
}

CommonTableExpression is a named component of a `WITH` query and provides a way to write auxiliary statements for use in a larger query

func (CommonTableExpression) NodeType

func (s CommonTableExpression) NodeType() string

type CompositeValue

type CompositeValue struct {
	Values   []Expression
	DataType DataType
}

func (CompositeValue) AsExpression

func (s CompositeValue) AsExpression() Expression

func (CompositeValue) AsSelectItem

func (s CompositeValue) AsSelectItem() SelectItem

func (CompositeValue) NodeType

func (s CompositeValue) NodeType() string

type CompoundIdentifier

type CompoundIdentifier []Identifier

func AsCompoundIdentifier

func AsCompoundIdentifier[T string | Identifier](parts ...T) CompoundIdentifier

func (CompoundIdentifier) AsExpression

func (s CompoundIdentifier) AsExpression() Expression

func (CompoundIdentifier) AsSelectItem

func (s CompoundIdentifier) AsSelectItem() SelectItem

func (CompoundIdentifier) Copy

func (CompoundIdentifier) Field

func (s CompoundIdentifier) Field() Identifier

func (CompoundIdentifier) HasField

func (s CompoundIdentifier) HasField() bool

func (CompoundIdentifier) IsBlank

func (s CompoundIdentifier) IsBlank() bool

func (CompoundIdentifier) NodeType

func (s CompoundIdentifier) NodeType() string

func (CompoundIdentifier) Root

func (s CompoundIdentifier) Root() Identifier

func (CompoundIdentifier) String

func (s CompoundIdentifier) String() string

func (CompoundIdentifier) Strings

func (s CompoundIdentifier) Strings() []string

type ConflictAction

type ConflictAction interface {
	Expression
	AsConflictAction() ConflictAction
}

ConflictAction is an expression that is evaluated as part of an OnConflict expression.

type ConflictTarget

type ConflictTarget struct {
	Columns    []Expression
	Constraint CompoundIdentifier
}

func (ConflictTarget) AsExpression

func (s ConflictTarget) AsExpression() Expression

func (ConflictTarget) NodeType

func (s ConflictTarget) NodeType() string

type DataType

type DataType string
const (
	// UnsetDataType represents a DataType that has not been visited by any logic. It is the default, zero-value for
	// the DataType type.
	UnsetDataType DataType = ""

	// UnknownDataType represents a DataType that has been visited by type inference logic but remains unknowable.
	UnknownDataType DataType = "unknown"

	Null          DataType = "null"
	Any           DataType = "any"
	NodeComposite DataType = "nodecomposite"
	EdgeComposite DataType = "edgecomposite"
	PathComposite DataType = "pathcomposite"
	Int           DataType = "int"
	Int2          DataType = "int2"
	Int4          DataType = "int4"
	Int8          DataType = "int8"
	Float4        DataType = "float4"
	Float8        DataType = "float8"
	Boolean       DataType = "bool"
	Text          DataType = "text"
	JSONB         DataType = "jsonb"
	Numeric       DataType = "numeric"

	AnyArray           DataType = "anyarray"
	NodeCompositeArray DataType = "nodecomposite[]"
	EdgeCompositeArray DataType = "edgecomposite[]"
	IntArray           DataType = "int[]"
	Int2Array          DataType = "int2[]"
	Int4Array          DataType = "int4[]"
	Int8Array          DataType = "int8[]"
	Float4Array        DataType = "float4[]"
	Float8Array        DataType = "float8[]"
	TextArray          DataType = "text[]"
	JSONBArray         DataType = "jsonb[]"
	NumericArray       DataType = "numeric[]"

	Date                     DataType = "date"
	TimeWithTimeZone         DataType = "time with time zone"
	TimeWithoutTimeZone      DataType = "time without time zone"
	Interval                 DataType = "interval"
	TimestampWithTimeZone    DataType = "timestamp with time zone"
	TimestampWithoutTimeZone DataType = "timestamp without time zone"

	Scope                 DataType = "scope"
	ParameterIdentifier   DataType = "parameter_identifier"
	ExpansionPattern      DataType = "expansion_pattern"
	ExpansionPath         DataType = "expansion_path"
	ExpansionRootNode     DataType = "expansion_root_node"
	ExpansionEdge         DataType = "expansion_edge"
	ExpansionTerminalNode DataType = "expansion_terminal_node"
)

func ValueToDataType

func ValueToDataType(value any) (DataType, error)

func (DataType) ArrayBaseType

func (s DataType) ArrayBaseType() DataType

func (DataType) CoerceToSupertype

func (s DataType) CoerceToSupertype(other DataType) (DataType, bool)

CoerceToSupertype attempts to take the super of the type s and the type other

func (DataType) IsArrayType

func (s DataType) IsArrayType() bool

func (DataType) IsComparable

func (s DataType) IsComparable(other DataType, operator Operator) bool

func (DataType) IsKnown

func (s DataType) IsKnown() bool

func (DataType) MatchesOneOf

func (s DataType) MatchesOneOf(others ...DataType) bool

func (DataType) NodeType

func (s DataType) NodeType() string

func (DataType) OperatorResultType

func (s DataType) OperatorResultType(other DataType, operator Operator) (DataType, bool)

func (DataType) String

func (s DataType) String() string

func (DataType) ToArrayType

func (s DataType) ToArrayType() (DataType, error)

type Delete

type Delete struct {
	From      []TableReference
	Using     []FromClause
	Where     Expression
	Returning []SelectItem
}

Delete is a SQL statement that is evaluated to remove data from a target table.

func (Delete) AsExpression

func (s Delete) AsExpression() Expression

func (Delete) AsSetExpression

func (s Delete) AsSetExpression() SetExpression

func (Delete) AsStatement

func (s Delete) AsStatement() Statement

func (Delete) NodeType

func (s Delete) NodeType() string

type DoNothing

type DoNothing struct{}

type DoUpdate

type DoUpdate struct {
	Assignments []Assignment
	Where       Expression
}

func (DoUpdate) AsConflictAction

func (s DoUpdate) AsConflictAction() ConflictAction

func (DoUpdate) AsExpression

func (s DoUpdate) AsExpression() Expression

func (DoUpdate) NodeType

func (s DoUpdate) NodeType() string

type ExistsExpression

type ExistsExpression struct {
	Subquery Subquery
	Negated  bool
}

ExistsExpression is an expression that is wrapped by an exists unary expression that can be optionally negated.

[not] exists(<query>)

func (ExistsExpression) AsExpression

func (s ExistsExpression) AsExpression() Expression

func (ExistsExpression) AsSelectItem

func (s ExistsExpression) AsSelectItem() SelectItem

func (ExistsExpression) NodeType

func (s ExistsExpression) NodeType() string

type Expression

type Expression interface {
	SyntaxNode
	AsExpression() Expression
}

Expression one or more syntax nodes that evaluate to a value.

func OptionalAnd

func OptionalAnd(leftOperand Expression, rightOperand Expression) Expression

func OptionalBinaryExpressionJoin

func OptionalBinaryExpressionJoin(optional Expression, operator Operator, conjoined Expression) Expression

type FormattingLiteral

type FormattingLiteral string

FormattingLiteral is a syntax node that is used as a transparent formatting syntax node. The formatter will take the string value and emit it as-is.

func (FormattingLiteral) AsExpression

func (s FormattingLiteral) AsExpression() Expression

func (FormattingLiteral) NodeType

func (s FormattingLiteral) NodeType() string

func (FormattingLiteral) String

func (s FormattingLiteral) String() string

type FromClause

type FromClause struct {
	Source Expression
	Joins  []Join
}

func (FromClause) NodeType

func (s FromClause) NodeType() string

type FunctionCall

type FunctionCall struct {
	Bare       bool
	Distinct   bool
	Function   Identifier
	Parameters []Expression
	Over       *Window
	CastType   DataType
}

func (FunctionCall) AsAssignment

func (s FunctionCall) AsAssignment() Assignment

func (FunctionCall) AsExpression

func (s FunctionCall) AsExpression() Expression

func (FunctionCall) AsSelectItem

func (s FunctionCall) AsSelectItem() SelectItem

func (FunctionCall) NodeType

func (s FunctionCall) NodeType() string

func (FunctionCall) TypeHint

func (s FunctionCall) TypeHint() DataType

type Future

type Future[U any] struct {
	SyntaxNode SyntaxNode
	Data       U
	DataType   DataType
}

func NewFuture

func NewFuture[U any](data U, dataType DataType) *Future[U]

func (Future[U]) AsExpression

func (s Future[U]) AsExpression() Expression

func (Future[U]) NodeType

func (s Future[U]) NodeType() string

func (Future[U]) Satisfied

func (s Future[U]) Satisfied() bool

func (Future[U]) TypeHint

func (s Future[U]) TypeHint() DataType

func (Future[U]) Unwrap

func (s Future[U]) Unwrap() SyntaxNode

type Identifier

type Identifier string
const (
	FunctionUnidirectionalASPHarness Identifier = "unidirectional_asp_harness"
	FunctionUnidirectionalSPHarness  Identifier = "unidirectional_sp_harness"
	FunctionBidirectionalASPHarness  Identifier = "bidirectional_asp_harness"
	FunctionIntArrayUnique           Identifier = "uniq"
	FunctionIntArraySort             Identifier = "sort"
	FunctionJSONBToTextArray         Identifier = "jsonb_to_text_array"
	FunctionJSONBArrayElementsText   Identifier = "jsonb_array_elements_text"
	FunctionJSONBBuildObject         Identifier = "jsonb_build_object"
	FunctionJSONBArrayLength         Identifier = "jsonb_array_length"
	FunctionArrayLength              Identifier = "array_length"
	FunctionArrayAggregate           Identifier = "array_agg"
	FunctionArrayRemove              Identifier = "array_remove"
	FunctionMin                      Identifier = "min"
	FunctionMax                      Identifier = "max"
	FunctionSum                      Identifier = "sum"
	FunctionAvg                      Identifier = "avg"
	FunctionLocalTimestamp           Identifier = "localtimestamp"
	FunctionLocalTime                Identifier = "localtime"
	FunctionCurrentTime              Identifier = "current_time"
	FunctionCurrentDate              Identifier = "current_date"
	FunctionNow                      Identifier = "now"
	FunctionToLower                  Identifier = "lower"
	FunctionToUpper                  Identifier = "upper"
	FunctionCoalesce                 Identifier = "coalesce"
	FunctionUnnest                   Identifier = "unnest"
	FunctionJSONBSet                 Identifier = "jsonb_set"
	FunctionCount                    Identifier = "count"
	FunctionStringToArray            Identifier = "string_to_array"
	FunctionEdgesToPath              Identifier = "edges_to_path"
	FunctionNodesToPath              Identifier = "nodes_to_path"
	FunctionExtract                  Identifier = "extract"
)
const (
	WildcardIdentifier Identifier = "*"
	EpochIdentifier    Identifier = "epoch"
)
const (
	StringLiteralNull       = "null"
	StringLiteralEmptyArray = "[]"

	TableNode Identifier = "node"
	TableEdge Identifier = "edge"

	ColumnID         Identifier = "id"
	ColumnPath       Identifier = "path"
	ColumnProperties Identifier = "properties"
	ColumnKindIDs    Identifier = "kind_ids"
	ColumnKindID     Identifier = "kind_id"
	ColumnGraphID    Identifier = "graph_id"
	ColumnStartID    Identifier = "start_id"
	ColumnEndID      Identifier = "end_id"
)

func AsIdentifiers

func AsIdentifiers(strs ...string) []Identifier

func (Identifier) AsCompoundIdentifier

func (s Identifier) AsCompoundIdentifier() CompoundIdentifier

func (Identifier) AsExpression

func (s Identifier) AsExpression() Expression

func (Identifier) AsSelectItem

func (s Identifier) AsSelectItem() SelectItem

func (Identifier) Matches

func (s Identifier) Matches(others ...Identifier) bool

func (Identifier) NodeType

func (s Identifier) NodeType() string

func (Identifier) String

func (s Identifier) String() string

type IdentifierSet

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

IdentifierSet represents a set of identifiers backed by a map[Identifier]struct{} instance.

func AllocateIdentifierSet

func AllocateIdentifierSet(length int) *IdentifierSet

func AsIdentifierSet

func AsIdentifierSet(identifiers ...Identifier) *IdentifierSet

func NewIdentifierSet

func NewIdentifierSet() *IdentifierSet

func (*IdentifierSet) Add

func (s *IdentifierSet) Add(identifiers ...Identifier) *IdentifierSet

func (*IdentifierSet) CheckedAdd

func (s *IdentifierSet) CheckedAdd(identifier Identifier) bool

func (*IdentifierSet) Clear

func (s *IdentifierSet) Clear()

func (*IdentifierSet) CombinedKey

func (s *IdentifierSet) CombinedKey() Identifier

func (*IdentifierSet) Contains

func (s *IdentifierSet) Contains(other Identifier) bool

func (*IdentifierSet) Copy

func (s *IdentifierSet) Copy() *IdentifierSet

func (*IdentifierSet) IsEmpty

func (s *IdentifierSet) IsEmpty() bool

func (*IdentifierSet) Len

func (s *IdentifierSet) Len() int

func (*IdentifierSet) Matches

func (s *IdentifierSet) Matches(other *IdentifierSet) bool

func (*IdentifierSet) MergeSet

func (s *IdentifierSet) MergeSet(other *IdentifierSet) *IdentifierSet

func (*IdentifierSet) Remove

func (s *IdentifierSet) Remove(others ...Identifier) *IdentifierSet

func (*IdentifierSet) RemoveSet

func (s *IdentifierSet) RemoveSet(other *IdentifierSet) *IdentifierSet

func (*IdentifierSet) Satisfies

func (s *IdentifierSet) Satisfies(other *IdentifierSet) bool

Satisfies returns true if the `other`is a subset of `s`

func (*IdentifierSet) Slice

func (s *IdentifierSet) Slice() []Identifier

func (*IdentifierSet) Strings

func (s *IdentifierSet) Strings() []string

type InExpression

type InExpression struct {
	Expression Expression
	List       []Expression
	Negated    bool
}

InExpression represents a contains operation against a list of evaluated expressions: m.identifier in (val1, val2, ...)

type InSubquery

type InSubquery struct {
	Expression Expression
	Query      Query
	Negated    bool
}

InSubquery represents a contains expression against a suq-query. [not] in (<Select> ...)

type Insert

type Insert struct {
	Table      TableReference
	Shape      *RecordShape
	OnConflict *OnConflict
	Source     *Query
	Returning  []SelectItem
}

Insert is a SQL statement that is evaluated to insert data into a target table.

func (Insert) AsStatement

func (s Insert) AsStatement() Statement

func (Insert) NodeType

func (s Insert) NodeType() string

type Join

type Join struct {
	Table        TableReference
	JoinOperator JoinOperator
}

func (Join) NodeType

func (s Join) NodeType() string

type JoinOperator

type JoinOperator struct {
	JoinType   JoinType
	Constraint Expression
}

func (JoinOperator) NodeType

func (s JoinOperator) NodeType() string

type JoinType

type JoinType int
const (
	JoinTypeInner JoinType = iota
	JoinTypeLeftOuter
	JoinTypeRightOuter
	JoinTypeFullOuter
)

type KindListLiteral

type KindListLiteral struct {
	Values graph.Kinds
}

func (KindListLiteral) AsExpression

func (s KindListLiteral) AsExpression() Expression

func (KindListLiteral) NodeType

func (s KindListLiteral) NodeType() string

type KindMapper

type KindMapper interface {
	MapKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)
	AssertKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)
}

KindMapper is an interface that represents a service that can map a given slice of graph.Kind to a slice of int16 numeric identifiers.

type Literal

type Literal struct {
	Value    any
	Null     bool
	CastType DataType
}

Literal is a type-hinted literal SQL value.

func AsLiteral

func AsLiteral(value any) (Literal, error)

func NewLiteral

func NewLiteral(value any, dataType DataType) Literal

func NullLiteral

func NullLiteral() Literal

func (Literal) AsExpression

func (s Literal) AsExpression() Expression

func (Literal) AsSelectItem

func (s Literal) AsSelectItem() SelectItem

func (Literal) NodeType

func (s Literal) NodeType() string

func (Literal) TypeHint

func (s Literal) TypeHint() DataType

type LiteralNodeValue

type LiteralNodeValue struct {
	Value    any
	Null     bool
	CastType DataType
}

type MatchedDelete

type MatchedDelete struct {
	Predicate Expression
}

func (MatchedDelete) AsExpression

func (s MatchedDelete) AsExpression() Expression

func (MatchedDelete) AsMergeAction

func (s MatchedDelete) AsMergeAction() MergeAction

func (MatchedDelete) NodeType

func (s MatchedDelete) NodeType() string

type MatchedUpdate

type MatchedUpdate struct {
	Predicate   Expression
	Assignments []Assignment
}

func (MatchedUpdate) AsExpression

func (s MatchedUpdate) AsExpression() Expression

func (MatchedUpdate) AsMergeAction

func (s MatchedUpdate) AsMergeAction() MergeAction

func (MatchedUpdate) NodeType

func (s MatchedUpdate) NodeType() string

type Materialized

type Materialized struct {
	Materialized bool
}

Materialized is an expression that represents a query hint for common table expressions that informs the query planner if it should prefer to materialize the given CTE.

func (Materialized) AsExpression

func (s Materialized) AsExpression() Expression

func (Materialized) AsSetExpression

func (s Materialized) AsSetExpression() SetExpression

func (Materialized) NodeType

func (s Materialized) NodeType() string

type Merge

type Merge struct {
	Into       bool
	Table      TableReference
	Source     TableReference
	JoinTarget Expression
	Actions    []MergeAction
}

func (Merge) AsStatement

func (s Merge) AsStatement() Statement

func (Merge) NodeType

func (s Merge) NodeType() string

type MergeAction

type MergeAction interface {
	Expression
	AsMergeAction() MergeAction
}

MergeAction is an expression that can be used as the action of a merge statement.

type OnConflict

type OnConflict struct {
	Target *ConflictTarget
	Action ConflictAction
}

OnConflict is an expression that outlines the target columns of a conflict and the action to be taken when a conflict is encountered.

func (OnConflict) AsExpression

func (s OnConflict) AsExpression() Expression

func (OnConflict) NodeType

func (s OnConflict) NodeType() string

type Operator

type Operator string
const (
	UnsetOperator                Operator = ""
	OperatorUnion                Operator = "union"
	OperatorConcatenate          Operator = "||"
	OperatorArrayOverlap         Operator = "&&"
	OperatorEquals               Operator = "="
	OperatorNotEquals            Operator = "!="
	OperatorGreaterThan          Operator = ">"
	OperatorGreaterThanOrEqualTo Operator = ">="
	OperatorLessThan             Operator = "<"
	OperatorLessThanOrEqualTo    Operator = "<="
	OperatorLike                 Operator = "like"
	OperatorILike                Operator = "ilike"
	OperatorPGArrayOverlap       Operator = "operator (pg_catalog.&&)"
	OperatorAnd                  Operator = "and"
	OperatorOr                   Operator = "or"
	OperatorNot                  Operator = "not"
	OperatorJSONBFieldExists     Operator = "?"
	OperatorJSONField            Operator = "->"
	OperatorJSONTextField        Operator = "->>"
	OperatorAdd                  Operator = "+"
	OperatorSubtract             Operator = "-"
	OperatorMultiply             Operator = "*"
	OperatorDivide               Operator = "/"
	OperatorIn                   Operator = "in"
	OperatorIs                   Operator = "is"
	OperatorIsNot                Operator = "is not"
	OperatorSimilarTo            Operator = "similar to"
	OperatorRegexMatch           Operator = "~"
	OperatorAssignment           Operator = "="
	OperatorAdditionAssignment   Operator = "+="

	OperatorCypherRegexMatch Operator = "=~"
	OperatorCypherStartsWith Operator = "starts with"
	OperatorCypherContains   Operator = "contains"
	OperatorCypherEndsWith   Operator = "ends with"
	OperatorCypherNotEquals  Operator = "<>"

	OperatorPropertyLookup Operator = "property_lookup"
	OperatorKindAssignment Operator = "kind_assignment"
)

func (Operator) AsExpression

func (s Operator) AsExpression() Expression

func (Operator) IsIn

func (s Operator) IsIn(others ...Operator) bool

func (Operator) NodeType

func (s Operator) NodeType() string

func (Operator) String

func (s Operator) String() string

type OrderBy

type OrderBy struct {
	Expression Expression
	Ascending  bool
}

func NewOrderBy

func NewOrderBy(ascending bool) *OrderBy

func (OrderBy) AsExpression

func (s OrderBy) AsExpression() Expression

func (OrderBy) NodeType

func (s OrderBy) NodeType() string

type Parameter

type Parameter struct {
	Identifier Identifier
	CastType   DataType
}

func AsParameter

func AsParameter(identifier Identifier, value any) (*Parameter, error)

func (Parameter) AsExpression

func (s Parameter) AsExpression() Expression

func (Parameter) AsSelectItem

func (s Parameter) AsSelectItem() SelectItem

func (Parameter) NodeType

func (s Parameter) NodeType() string

func (Parameter) TypeHint

func (s Parameter) TypeHint() DataType

type Parenthetical

type Parenthetical struct {
	Expression Expression
}

(<expr>)

func NewParenthetical

func NewParenthetical(expr Expression) *Parenthetical

func (*Parenthetical) AsExpression

func (s *Parenthetical) AsExpression() Expression

func (*Parenthetical) AsSelectItem

func (s *Parenthetical) AsSelectItem() SelectItem

func (*Parenthetical) NodeType

func (s *Parenthetical) NodeType() string

type Projection

type Projection []SelectItem

Projection is an alias for a slice of SelectItem instances.

func (Projection) AsExpression

func (s Projection) AsExpression() Expression

func (Projection) AsSyntaxNodes

func (s Projection) AsSyntaxNodes() []SyntaxNode

func (Projection) NodeType

func (s Projection) NodeType() string

type ProjectionFrom

type ProjectionFrom struct {
	Projection Projection
	From       []FromClause
}

func (ProjectionFrom) AsExpression

func (s ProjectionFrom) AsExpression() Expression

func (ProjectionFrom) NodeType

func (s ProjectionFrom) NodeType() string

type Query

type Query struct {
	CommonTableExpressions *With
	Body                   SetExpression
	OrderBy                []*OrderBy
	Offset                 Expression
	Limit                  Expression
}

[with <CTE>] select * from table;

func (Query) AddCTE

func (s Query) AddCTE(cte CommonTableExpression)

func (Query) AsExpression

func (s Query) AsExpression() Expression

func (Query) AsSetExpression

func (s Query) AsSetExpression() SetExpression

func (Query) AsStatement

func (s Query) AsStatement() Statement

func (Query) NodeType

func (s Query) NodeType() string

type RecordShape

type RecordShape struct {
	Columns []Identifier
}

RecordShape defines a list of column identifiers that name a record's fields: (id, enrolled)

func NewRecordShape added in v0.2.1

func NewRecordShape(columns []Identifier) *RecordShape

func (RecordShape) NodeType

func (s RecordShape) NodeType() string

type RowColumnReference

type RowColumnReference struct {
	Identifier Expression
	Column     Identifier
}

func (RowColumnReference) AsExpression

func (s RowColumnReference) AsExpression() Expression

func (RowColumnReference) AsSelectItem

func (s RowColumnReference) AsSelectItem() SelectItem

func (RowColumnReference) NodeType

func (s RowColumnReference) NodeType() string

type Select

type Select struct {
	Distinct   bool
	Projection Projection
	From       []FromClause
	Where      Expression
	GroupBy    []Expression
	Having     Expression
}

Select is a SQL expression that is evaluated to fetch data.

func (Select) AsExpression

func (s Select) AsExpression() Expression

func (Select) AsSetExpression

func (s Select) AsSetExpression() SetExpression

func (Select) NodeType

func (s Select) NodeType() string

type SelectItem

type SelectItem interface {
	Expression
	AsSelectItem() SelectItem
}

SelectItem is an expression that can be used as a projection.

type SetExpression

type SetExpression interface {
	Expression
	AsSetExpression() SetExpression
}

SetExpression is an expression that represents a query body expression.

type SetOperation

type SetOperation struct {
	Operator Operator
	LOperand SetExpression
	ROperand SetExpression
	All      bool
	Distinct bool
}

SetOperation is a binary expression that represents an operation to be applied to two set expressions:

select 1 union select 2;

func (SetOperation) AsExpression

func (s SetOperation) AsExpression() Expression

func (SetOperation) AsSetExpression

func (s SetOperation) AsSetExpression() SetExpression

func (SetOperation) NodeType

func (s SetOperation) NodeType() string

type Statement

type Statement interface {
	SyntaxNode
	AsStatement() Statement
}

Statement is a syntax node that does not evaluate to a value.

type Subquery

type Subquery struct {
	Query Query
}

func (Subquery) AsExpression

func (s Subquery) AsExpression() Expression

func (Subquery) NodeType

func (s Subquery) NodeType() string

type SymbolTable

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

SymbolTable is a symbol table that has some generic functions for negotiating unique symbols from identifiers, compound identifiers, and other PgSQL AST elements.

func NewSymbolTable

func NewSymbolTable() *SymbolTable

func (*SymbolTable) Add

func (s *SymbolTable) Add(symbol any)

func (*SymbolTable) AddCompoundIdentifier

func (s *SymbolTable) AddCompoundIdentifier(identifier CompoundIdentifier)

func (*SymbolTable) AddIdentifier

func (s *SymbolTable) AddIdentifier(identifier Identifier)

func (*SymbolTable) AddTable

func (s *SymbolTable) AddTable(symbols *SymbolTable)

func (*SymbolTable) Contains

func (s *SymbolTable) Contains(symbol any) bool

func (*SymbolTable) EachCompoundIdentifier

func (s *SymbolTable) EachCompoundIdentifier(each func(next CompoundIdentifier) bool)

func (*SymbolTable) EachIdentifier

func (s *SymbolTable) EachIdentifier(each func(next Identifier) bool)

func (*SymbolTable) IsEmpty

func (s *SymbolTable) IsEmpty() bool

func (*SymbolTable) NotIn

func (s *SymbolTable) NotIn(exclusions *SymbolTable) *SymbolTable

func (*SymbolTable) RootIdentifiers

func (s *SymbolTable) RootIdentifiers() *IdentifierSet

type SyntaxNode

type SyntaxNode interface {
	NodeType() string
}

SyntaxNode is the top-level interface for any of the modeled PgSQL AST syntax elements.

type SyntaxNodeFuture

type SyntaxNodeFuture interface {
	SyntaxNode
	Unwrap() SyntaxNode
	Satisfied() bool
}

SyntaxNodeFuture is a SyntaxNode that can be satisfied out-of-tree and communicate if it has been satisfied to upstream consumers. This is useful when a SyntaxNode is required to be embedded in a built syntax tree but can not be formally built itself due to ordering or missing dependency information (in the case of an existential subquery).

type TableAlias

type TableAlias struct {
	Name  Identifier
	Shape *RecordShape
}

TableAlias is an alias for a table with an optional record shape.

func (TableAlias) NodeType

func (s TableAlias) NodeType() string

type TableReference

type TableReference struct {
	Name    CompoundIdentifier
	Binding models.Optional[Identifier]
}

func (TableReference) AsExpression

func (s TableReference) AsExpression() Expression

func (TableReference) NodeType

func (s TableReference) NodeType() string

type TypeCast

type TypeCast struct {
	Expression Expression
	CastType   DataType
}

TypeCast wraps a given expression in a type cast that matches the given DataType.

func (TypeCast) AsExpression

func (s TypeCast) AsExpression() Expression

func (TypeCast) NodeType

func (s TypeCast) NodeType() string

func (TypeCast) TypeHint

func (s TypeCast) TypeHint() DataType

type TypeHinted

type TypeHinted interface {
	Expression
	TypeHint() DataType
}

TypeHinted is an expression that contains a DataType hint that can be accessed by handlers.

func NewTypeCast

func NewTypeCast(expression Expression, dataType DataType) TypeHinted

type UnaryExpression

type UnaryExpression struct {
	Operator Expression
	Operand  Expression
}

not <expr>

func NewUnaryExpression

func NewUnaryExpression(operator Operator, operand Expression) *UnaryExpression

func (UnaryExpression) AsExpression

func (s UnaryExpression) AsExpression() Expression

func (UnaryExpression) NodeType

func (s UnaryExpression) NodeType() string

type UnmatchedAction

type UnmatchedAction struct {
	Predicate Expression
	Columns   []Identifier
	Values    Values
}

func (UnmatchedAction) AsExpression

func (s UnmatchedAction) AsExpression() Expression

func (UnmatchedAction) AsMergeAction

func (s UnmatchedAction) AsMergeAction() MergeAction

func (UnmatchedAction) NodeType

func (s UnmatchedAction) NodeType() string

type Update

type Update struct {
	Table       TableReference
	Assignments []Assignment
	From        []FromClause
	Where       Expression
	Returning   []SelectItem
}

Update is a SQL statement that is evaluated to update data in a target table.

func (Update) AsExpression

func (s Update) AsExpression() Expression

func (Update) AsSetExpression

func (s Update) AsSetExpression() SetExpression

func (Update) AsStatement

func (s Update) AsStatement() Statement

func (Update) NodeType

func (s Update) NodeType() string

type Values

type Values struct {
	Values []Expression
}

Values represents a list of expressions to be taken as a value array: insert into table (id, enrolled) values (1, true);

func (Values) AsExpression

func (s Values) AsExpression() Expression

func (Values) AsSetExpression

func (s Values) AsSetExpression() SetExpression

func (Values) NodeType

func (s Values) NodeType() string

type Variadic

type Variadic struct {
	Expression Expression
}

Variadic isrepresents a variadic expansion of the given expression.

func (Variadic) AsExpression

func (s Variadic) AsExpression() Expression

func (Variadic) NodeType

func (s Variadic) NodeType() string

type Wildcard

type Wildcard struct{}

func (Wildcard) AsExpression

func (s Wildcard) AsExpression() Expression

func (Wildcard) AsSelectItem

func (s Wildcard) AsSelectItem() SelectItem

func (Wildcard) NodeType

func (s Wildcard) NodeType() string

type Window

type Window struct {
	PartitionBy []Expression
	OrderBy     []OrderBy
	WindowFrame *WindowFrame
}

type WindowFrame

type WindowFrame struct {
	Unit          WindowFrameUnit
	StartBoundary WindowFrameBoundary
	EndBoundary   *WindowFrameBoundary
}

type WindowFrameBoundary

type WindowFrameBoundary struct {
	BoundaryType    WindowFrameBoundaryType
	BoundaryLiteral *Literal
}

type WindowFrameBoundaryType

type WindowFrameBoundaryType int
const (
	WindowFrameBoundaryTypeCurrentRow WindowFrameBoundaryType = iota
	WindowFrameBoundaryTypePreceding
	WindowFrameBoundaryTypeFollowing
)

type WindowFrameUnit

type WindowFrameUnit int
const (
	WindowFrameUnitRows WindowFrameUnit = iota
	WindowFrameUnitRange
	WindowFrameUnitGroups
)

type With

type With struct {
	Recursive   bool
	Expressions []CommonTableExpression
}

With is a statement that provides a way to write auxiliary statements for use in a larger query.

func (With) NodeType

func (s With) NodeType() string

type WrappedNode

type WrappedNode interface {
	SyntaxNode
}

WrappedNode is an interface that allows for an expression to be wrapped to allow for side effects like futures.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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