jointree

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package jointree supports the query buildNodeTree process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	QueryNode       query.Node
	Parent          *Element
	References      []*Element              // TableNodeI objects
	Columns         []*Element              // All columns that will be used to build the query, including those in Where, OrderBy and other clauses
	SelectedColumns maps.SliceSet[*Element] // Pointers to elements in Columns that will be returned in the query. Using a SliceSet to iterate in the order given.
	Alias           string                  // computed or assigned alias
	Calculations    map[string]query.Node   // calculations attached to this node by alias
	IsPK            bool
}

Element is used to build the join tree. The join tree creates a hierarchy of joined nodes that let us generate aliases, serialize the query, and afterward, unpack the results.

func (*Element) CalculationsIter

func (j *Element) CalculationsIter() iter.Seq2[string, query.Node]

CalculationsIter iterates on all the calculations in this element and its sub elements.

func (*Element) ColumnIter

func (j *Element) ColumnIter() iter.Seq[*Element]

ColumnIter iterates on all the columns in this element and its sub elements.

func (*Element) FindCalculation

func (j *Element) FindCalculation(alias string) query.Node

func (*Element) IsArray

func (j *Element) IsArray() bool

IsArray returns true if the enclosed query node is an array type node.

func (*Element) PrimaryKey

func (j *Element) PrimaryKey() *Element

PrimaryKey will return the primary key join tree item attached to this item, or nil if none exists. If the element is not the kind of element that can have a primary key, it will panic.

func (*Element) SelectedReferences

func (j *Element) SelectedReferences() (refs []*Element)

SelectedReferences returns just the references that have selected columns. This helps filter out references that are just used for where clauses and the like.

func (*Element) SelectsIter

func (j *Element) SelectsIter() iter.Seq[*Element]

SelectsIter iterates on all the selects in this element and its sub elements.

func (*Element) String

func (j *Element) String() string

String shows information about the node for debugging.

type JoinTree

type JoinTree struct {
	Root      *Element
	SubPrefix string

	IsDistinct bool

	Command   query.BuilderCommand
	Limits    query.LimitParams
	Condition query.Node
	GroupBys  []query.Node
	OrderBys  []query.Sorter
	Having    query.Node
	// contains filtered or unexported fields
}

JoinTree is used by various goradd-orm database drivers to convert a query.Builder object into a query understandable by the database. Developers do not normally need to call code here unless they are making a custom database driver.

It analyzes a query.QueryBuilder object, combines all the nodes into a single tree structure, adds extra nodes implied by the query, and assigns aliases to the columns that will be selected.

func NewJoinTree

func NewJoinTree(b query.BuilderI) *JoinTree

NewJoinTree analyzes b and turns it into a JoinTree.

func (*JoinTree) CalculationsIter

func (t *JoinTree) CalculationsIter() iter.Seq2[string, query.Node]

func (*JoinTree) FindAlias

func (t *JoinTree) FindAlias(alias string) query.Node

FindAlias searches the join tree for the given manually assigned alias and returns the node corresponding to the alias.

func (*JoinTree) FindElement

func (t *JoinTree) FindElement(node query.Node) *Element

FindElement will return the element matching node, or nil if not found.

func (*JoinTree) HasAggregates

func (t *JoinTree) HasAggregates() bool

func (*JoinTree) HasCalcs

func (t *JoinTree) HasCalcs() bool

func (*JoinTree) HasSelects

func (t *JoinTree) HasSelects() bool

func (*JoinTree) SelectsIter

func (t *JoinTree) SelectsIter() iter.Seq[*Element]

Jump to

Keyboard shortcuts

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