firestorebind

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package firestorebind parses and prints typed Firestore Datastore access-pattern sources.

The grammar is the .tb.dynamo one with the parts Datastore does not have removed and the parts it does have added. It declares no kind: a kind belongs to the type, not to the deployment, so the result type already says it. That is the one structural difference from the DynamoDB grammar, and it is why the two stay separate packages rather than one with a mode flag.

Index

Constants

View Source
const DefaultTemplatePattern = "*.tb.firestore"

DefaultTemplatePattern is the base-name glob for query declarations, beside the HTML, SQL and DynamoDB template patterns.

Variables

This section is empty.

Functions

func Format

func Format(filename string, source []byte, options syntax.PrintOptions) ([]byte, error)

Format lays out one .tb.firestore source. A source that does not parse is reported rather than guessed at, so the caller can leave the file untouched.

Types

type Bound

type Bound struct {
	// Literal is the constant form; Param names a parameter instead. Exactly one
	// is set when Present is true.
	Literal int
	Param   string
	Present bool
	Line    int
}

Bound is a limit or an offset, which is either a literal or a parameter.

type Condition

type Condition struct {
	Predicate *Predicate
	Junction  Junction
	Operands  []Condition
	Line      int
}

Condition is one node of a where clause: either a comparison or a junction of other conditions.

A where clause is a tree rather than a list because Datastore composes with both AND and OR. It was AND-only when this grammar was written, and the parser said so while rejecting or; the driver gained OR in tinygodriver v1.1.6 after this side asked whether the claim still held.

Exactly one of Predicate and Operands is set. A leaf carries the comparison; a junction carries its operands and the word that joins them.

func (Condition) Flatten

func (c Condition) Flatten() ([]Predicate, bool)

Flatten returns the leaves of an all-and tree, and reports whether the tree is one. The emitter uses it to keep the common declaration generating the same per-predicate Filter calls it always has.

func (Condition) HasOr

func (c Condition) HasOr() bool

HasOr reports whether any junction below this one is an or, which is what decides whether generated code needs the condition tree at all.

func (Condition) IsLeaf

func (c Condition) IsLeaf() bool

IsLeaf reports whether the condition is a single comparison.

func (Condition) Walk

func (c Condition) Walk(visit func(*Predicate) error) error

Walk calls visit on every leaf, in the order the source wrote them, which is the order a generated function binds its parameters in.

type Direction

type Direction string

Direction is a sort direction.

const (
	Ascending  Direction = "asc"
	Descending Direction = "desc"
)

type IndexProperty

type IndexProperty struct {
	Name      string
	Direction Direction
}

IndexProperty is one property of a declared composite index.

type Junction

type Junction string

Junction is how a Condition joins its operands.

const (
	// JunctionAnd requires every operand.
	JunctionAnd Junction = "and"
	// JunctionOr requires at least one.
	JunctionOr Junction = "or"
)

type Op

type Op string

Op is a property filter comparison.

const (
	OpEqual          Op = "=="
	OpNotEqual       Op = "!="
	OpLess           Op = "<"
	OpLessOrEqual    Op = "<="
	OpGreater        Op = ">"
	OpGreaterOrEqual Op = ">="
	OpIn             Op = "in"
	OpNotIn          Op = "not in"
)

func (Op) Multi

func (o Op) Multi() bool

Multi reports whether the operator takes a slice of candidates rather than one value.

type Order

type Order struct {
	Property  string
	Direction Direction
	Line      int
}

Order is one sort key of an order clause.

type Predicate

type Predicate struct {
	Property string
	Op       Op
	Param    string
	Line     int
}

Predicate is one comparison in a where clause.

type Projection

type Projection struct {
	Name string
	Line int
}

Projection is one property a select clause returns.

type QueryDecl

type QueryDecl struct {
	Name       string
	Exported   bool
	Params     []QueryParam
	Shape      ResultShape
	EntityType string
	// Where is the filter tree, or nil when the declaration has no where clause.
	Where *Condition
	// Ancestor names the parameter holding the ancestor key, when the
	// declaration has an ancestor clause.
	Ancestor     string
	AncestorLine int
	Order        []Order
	Limit        Bound
	Offset       Bound
	// Select is the projection: the properties the query returns instead of
	// whole entities. The result type is unchanged; what is not projected
	// arrives as the zero value.
	Select     []Projection
	SelectLine int
	// Distinct collapses results sharing the named properties.
	Distinct     []Projection
	DistinctLine int
	// Start and End name the parameters holding the cursors this query resumes
	// from and stops at.
	Start     string
	StartLine int
	End       string
	EndLine   int
	// Index is the composite index this access pattern needs, when the author
	// declared one. Nothing derives it: the rule for when one is required is
	// subtle, and a derivation that is quietly wrong names an index that does
	// not fix the query.
	Index     []IndexProperty
	IndexLine int
	// HasIndex separates a declared empty index from no index clause.
	HasIndex   bool
	SourcePath string
	Line       int
}

QueryDecl is one declared access pattern.

It names no kind. The result type names the bound Go type, and that type's generated Kind method is the kind, so a declaration cannot disagree with the codec about what it is querying.

func ParseQueries

func ParseQueries(path string, source []byte) ([]QueryDecl, error)

ParseQueries reads every declaration in one .tb.firestore source.

type QueryParam

type QueryParam struct {
	Name string
	// Type is the Go type as the declaration spells it, checked later against
	// the property's own Go type.
	Type string
	Line int
}

QueryParam is one declared parameter of a query function.

type ResultShape

type ResultShape string

ResultShape is what a declaration asks the generated function to return. It selects the request shape rather than a row count: a query always returns many, and the choice is whether the caller sees the batch boundaries.

const (
	// Batch issues one request and returns a page.
	Batch ResultShape = "batch"
	// Many iterates every batch.
	Many ResultShape = "many"
	// Count runs an aggregation query and decodes no entity.
	Count ResultShape = "count"
	// Keys runs a keys-only query, which is the cheap way to test existence in
	// bulk.
	Keys ResultShape = "keys"
)

Jump to

Keyboard shortcuts

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