firestorefixture

package
v0.3.6 Latest Latest
Warning

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

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

Documentation

Overview

Package firestorefixture exercises the generated Firestore entity codec against the firestorebind runtime and the driver's wire protocol.

The calls below are what generation is directed by: each one names the type it binds, and the generator emits exactly the methods those calls need.

Index

Constants

This section is empty.

Variables

View Source
var HotOrNamedIndex = datastore.Index{
	Kind: hotOrNamedKind,
	Properties: []datastore.IndexProperty{
		{Name: "sensor", Direction: datastore.Ascending},
		{Name: "at", Direction: datastore.Ascending},
	},
}

HotOrNamedIndex is the composite index HotOrNamed declares it needs.

It is a description, not a request: applying an index is an admin-API operation. Feed it to datastore.MarshalIndexYAML and to whatever owns index.yaml in this project.

View Source
var ReadingTimesIndex = datastore.Index{
	Kind: readingTimesKind,
	Properties: []datastore.IndexProperty{
		{Name: "sensor", Direction: datastore.Ascending},
		{Name: "at", Direction: datastore.Ascending},
	},
}

ReadingTimesIndex is the composite index ReadingTimes declares it needs.

It is a description, not a request: applying an index is an admin-API operation. Feed it to datastore.MarshalIndexYAML and to whatever owns index.yaml in this project.

View Source
var WarmReadingsBySensorIndex = datastore.Index{
	Kind: warmReadingsBySensorKind,
	Properties: []datastore.IndexProperty{
		{Name: "sensor", Direction: datastore.Ascending},
		{Name: "at", Direction: datastore.Descending},
	},
}

WarmReadingsBySensorIndex is the composite index WarmReadingsBySensor declares it needs.

It is a description, not a request: applying an index is an admin-API operation. Feed it to datastore.MarshalIndexYAML and to whatever owns index.yaml in this project.

Functions

func ActiveReadingCount

func ActiveReadingCount(ctx context.Context, active bool, opts ...datastore.ReadOption) (int64, error)

ActiveReadingCount queries Reading.

func ActiveReadingCountTx

func ActiveReadingCountTx(ctx context.Context, tx *firestorebind.Tx, active bool) (int64, error)

ActiveReadingCountTx is ActiveReadingCount inside a transaction, so its read joins the snapshot the transaction is built on rather than seeing what has been committed since.

func AnySensorOrNote

func AnySensorOrNote(ctx context.Context, sensors []SensorID, note string, opts ...datastore.ReadOption) iter.Seq2[Reading, error]

AnySensorOrNote queries Reading.

One range can issue many requests; nothing here reports the boundary.

The filter is disjunctive. Datastore puts the whole filter in disjunctive normal form and caps the result at datastore.MaxDisjunctions, so an or nested inside an and multiplies rather than adds. Nothing counts that here: the expansion rule is the service's, and a count that disagreed would refuse a query that works.

This query combines filters and ordering in a shape that may require a composite index. Nothing in the toolchain verifies that one exists, so a missing index surfaces as FAILED_PRECONDITION on the first run.

func HotOrNamed

func HotOrNamed(ctx context.Context, sensor SensorID, note string, from time.Time, opts ...datastore.ReadOption) (firestorebind.Page[Reading], error)

HotOrNamed queries Reading.

The filter is disjunctive. Datastore puts the whole filter in disjunctive normal form and caps the result at datastore.MaxDisjunctions, so an or nested inside an and multiplies rather than adds. Nothing counts that here: the expansion rule is the service's, and a count that disagreed would refuse a query that works.

func HotOrNamedTx

func HotOrNamedTx(ctx context.Context, tx *firestorebind.Tx, sensor SensorID, note string, from time.Time) (firestorebind.Page[Reading], error)

HotOrNamedTx is HotOrNamed inside a transaction, so its read joins the snapshot the transaction is built on rather than seeing what has been committed since.

func InsertTask

func InsertTask(ctx context.Context, t Task) (datastore.Key, error)

InsertTask exercises the put-if-absent verb over the id-keyed type.

func QueryReadings

func QueryReadings(ctx context.Context, q *datastore.Query) iter.Seq2[Reading, error]

QueryReadings iterates a kind, which is what Scan would have been.

func ReadingTimes

func ReadingTimes(ctx context.Context, sensor SensorID, opts ...datastore.ReadOption) (firestorebind.Page[Reading], error)

ReadingTimes queries Reading.

This is a projection: only the selected properties are read, and every other field of the returned value is its zero value. Do not write one back with Store or Update, which replace the whole entity and would therefore erase everything this query did not ask for.

A projection reads from an index, so every selected property must be indexed, and the service rejects projecting a property an equality filter already fixes.

func ReadingTimesTx

func ReadingTimesTx(ctx context.Context, tx *firestorebind.Tx, sensor SensorID) (firestorebind.Page[Reading], error)

ReadingTimesTx is ReadingTimes inside a transaction, so its read joins the snapshot the transaction is built on rather than seeing what has been committed since.

func ReadingsBySensor

func ReadingsBySensor(ctx context.Context, sensor SensorID, opts ...datastore.ReadOption) iter.Seq2[Reading, error]

ReadingsBySensor queries Reading.

One range can issue many requests; nothing here reports the boundary.

func ReadingsForAnySensor

func ReadingsForAnySensor(ctx context.Context, sensors []SensorID, opts ...datastore.ReadOption) (firestorebind.Page[Reading], error)

ReadingsForAnySensor queries Reading.

func ReadingsForAnySensorTx

func ReadingsForAnySensorTx(ctx context.Context, tx *firestorebind.Tx, sensors []SensorID) (firestorebind.Page[Reading], error)

ReadingsForAnySensorTx is ReadingsForAnySensor inside a transaction, so its read joins the snapshot the transaction is built on rather than seeing what has been committed since.

func ReadingsFrom

func ReadingsFrom(ctx context.Context, cursor datastore.Cursor, size int, opts ...datastore.ReadOption) (firestorebind.Page[Reading], error)

ReadingsFrom queries Reading.

func ReadingsFromTx

func ReadingsFromTx(ctx context.Context, tx *firestorebind.Tx, cursor datastore.Cursor, size int) (firestorebind.Page[Reading], error)

ReadingsFromTx is ReadingsFrom inside a transaction, so its read joins the snapshot the transaction is built on rather than seeing what has been committed since.

func ReadingsSince

func ReadingsSince(ctx context.Context, from time.Time, size int, opts ...datastore.ReadOption) (firestorebind.Page[Reading], error)

ReadingsSince queries Reading.

func ReadingsSinceTx

func ReadingsSinceTx(ctx context.Context, tx *firestorebind.Tx, from time.Time, size int) (firestorebind.Page[Reading], error)

ReadingsSinceTx is ReadingsSince inside a transaction, so its read joins the snapshot the transaction is built on rather than seeing what has been committed since.

func ReadingsUnder

func ReadingsUnder(ctx context.Context, parent datastore.Key, opts ...datastore.ReadOption) iter.Seq2[Reading, error]

ReadingsUnder queries Reading.

One range can issue many requests; nothing here reports the boundary.

This query combines filters and ordering in a shape that may require a composite index. Nothing in the toolchain verifies that one exists, so a missing index surfaces as FAILED_PRECONDITION on the first run.

func RemoveReading

func RemoveReading(ctx context.Context, r Reading) error

RemoveReading is a key-only use.

func RenameInTransaction

func RenameInTransaction(ctx context.Context, key datastore.Key, title string) error

RenameInTransaction is a read-modify-write, which is the only thing a transaction is for here: nothing on this wire evaluates a predicate.

func StoreReading

func StoreReading(ctx context.Context, r Reading) (datastore.Key, error)

StoreReading is an encode-side use, whose type comes from the value argument.

func StoreReadings

func StoreReadings(ctx context.Context, rs []Reading) ([]datastore.Key, error)

StoreReadings exercises the size-chunked batch write.

func StoreSession

func StoreSession(ctx context.Context, s Session) (datastore.Key, error)

StoreSession is the encode-side use that directs the Session codec, and the only reason the ttl declaration reaches generated code.

func SweepKeys

func SweepKeys(ctx context.Context, keys []datastore.Key) error

SweepKeys deletes by key rather than by value, which is the shape a keys-only query hands back and the shape a namespace teardown needs.

func TaskKeys

func TaskKeys(ctx context.Context, title string, opts ...datastore.ReadOption) (firestorebind.KeyPage, error)

TaskKeys queries Task.

func TaskKeysTx

func TaskKeysTx(ctx context.Context, tx *firestorebind.Tx, title string) (firestorebind.KeyPage, error)

TaskKeysTx is TaskKeys inside a transaction, so its read joins the snapshot the transaction is built on rather than seeing what has been committed since.

func WarmReadingsBySensor

func WarmReadingsBySensor(ctx context.Context, sensor SensorID, from time.Time, opts ...datastore.ReadOption) iter.Seq2[Reading, error]

WarmReadingsBySensor queries Reading.

One range can issue many requests; nothing here reports the boundary.

Types

type Reading

type Reading struct {
	ID     SensorID         `firestore:"-,name"`
	Parent datastore.Key    `firestore:"-,parent"`
	Ver    int64            `firestore:"-,version"`
	Sensor SensorID         `firestore:"sensor"`
	Note   string           `firestore:"note"`
	At     time.Time        `firestore:"at"`
	Scale  float64          `firestore:"scale"`
	Small  float32          `firestore:"small"`
	Count  int64            `firestore:"count"`
	Tiny   uint16           `firestore:"tiny"`
	Active bool             `firestore:"active"`
	Blob   []byte           `firestore:"blob"`
	Ref    datastore.Key    `firestore:"ref"`
	Where  datastore.LatLng `firestore:"where"`

	Tags   []string        `firestore:"tags,omitempty"`
	Nested Site            `firestore:"site"`
	Extra  *string         `firestore:"extra"`
	Body   string          `firestore:"body,noindex"`
	Raw    datastore.Value `firestore:"raw"`
}

Reading covers every property form the generator supports.

ID carries the key's name and is absent from the properties: Datastore stores a key beside them, so writing it as a property too would store identity twice.

func LoadReading

func LoadReading(ctx context.Context, key datastore.Key) (Reading, error)

LoadReading is a decode-side use: T appears only in the result, so the AST carries it even before any codec exists.

func LoadReadings

func LoadReadings(ctx context.Context, keys []datastore.Key) ([]Reading, []datastore.Key, []datastore.Key, error)

LoadReadings exercises the key-chunked batch read and its three results.

func (*Reading) DecodeEntity

func (v *Reading) DecodeEntity(e datastore.Entity) error

DecodeEntity fills Reading from a Datastore entity. A property the entity does not carry leaves its field untouched, since Datastore is schemaless and an older writer is normal rather than exceptional.

func (Reading) EncodeEntity

func (v Reading) EncodeEntity() datastore.Entity

EncodeEntity converts Reading into a Datastore entity.

The key travels beside the properties rather than among them, so the identity fields are absent from the property map and cannot drift from it.

func (Reading) EntityKey

func (v Reading) EntityKey() datastore.Key

EntityKey returns the key of Reading, including its ancestor path.

func (Reading) EntityVersion

func (v Reading) EntityVersion() int64

EntityVersion is the version Reading was read at. A non-zero version makes a later Store or Update conditional on the stored entity still being at it.

func (Reading) Kind

func (v Reading) Kind() string

Kind is the Datastore kind Reading is stored under. A kind belongs to the type rather than to the deployment, so nothing configures it.

type SensorID

type SensorID string

SensorID is a named string, so the codec has to convert rather than assign.

type Session

type Session struct {
	Token     string    `firestore:"-,name"`
	Subject   string    `firestore:"subject"`
	ExpiresAt time.Time `firestore:"expires_at,ttl"`
}

Session carries an expiry property. The ttl option changes nothing about how ExpiresAt is written — it is an ordinary timestamp property — and produces one generated fact: this kind's TTL policy targets "expires_at". Applying that policy stays a deployment step, since Datastore mode has no expiry on the wire.

func (Session) EncodeEntity

func (v Session) EncodeEntity() datastore.Entity

EncodeEntity converts Session into a Datastore entity.

The key travels beside the properties rather than among them, so the identity fields are absent from the property map and cannot drift from it.

func (Session) EntityKey

func (v Session) EntityKey() datastore.Key

EntityKey returns the key of Session, including its ancestor path.

func (Session) ExpiryProperty

func (v Session) ExpiryProperty() (string, bool)

ExpiryProperty is the property a TTL policy for kind Session should expire entities by. Nothing here applies one: Datastore mode has no expiry on the wire, so a policy is applied out of band with gcloud over this property.

func (Session) Kind

func (v Session) Kind() string

Kind is the Datastore kind Session is stored under. A kind belongs to the type rather than to the deployment, so nothing configures it.

type Site

type Site struct {
	City string `firestore:"city"`
	Zip  string `firestore:"zip,omitempty"`
}

Site is a nested entity, stored as an entityValue. It declares no identity, because an entityValue carries no key.

func (*Site) DecodeEntity

func (v *Site) DecodeEntity(e datastore.Entity) error

DecodeEntity fills Site from a Datastore entity. A property the entity does not carry leaves its field untouched, since Datastore is schemaless and an older writer is normal rather than exceptional.

func (Site) EncodeEntity

func (v Site) EncodeEntity() datastore.Entity

EncodeEntity converts Site into a Datastore entity.

The key travels beside the properties rather than among them, so the identity fields are absent from the property map and cannot drift from it.

func (Site) Kind

func (v Site) Kind() string

Kind is the Datastore kind Site is stored under. A kind belongs to the type rather than to the deployment, so nothing configures it.

type Task

type Task struct {
	Number int64  `firestore:"-,id"`
	Title  string `firestore:"title"`
}

Task uses an integer id rather than a name, and stores nothing but its own identity plus one property.

func (*Task) DecodeEntity

func (v *Task) DecodeEntity(e datastore.Entity) error

DecodeEntity fills Task from a Datastore entity. A property the entity does not carry leaves its field untouched, since Datastore is schemaless and an older writer is normal rather than exceptional.

func (Task) EncodeEntity

func (v Task) EncodeEntity() datastore.Entity

EncodeEntity converts Task into a Datastore entity.

The key travels beside the properties rather than among them, so the identity fields are absent from the property map and cannot drift from it.

func (Task) EntityKey

func (v Task) EntityKey() datastore.Key

EntityKey returns the key of Task, including its ancestor path.

func (Task) Kind

func (v Task) Kind() string

Kind is the Datastore kind Task is stored under. A kind belongs to the type rather than to the deployment, so nothing configures it.

Jump to

Keyboard shortcuts

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