calcifer

package module
v0.0.0-...-a1c0fb3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

Calcifer

Go Reference Test Status

Calcifer is Radiopaper's ODM (Object-Document Mapping) library, written in Go, targeting Google Cloud Firestore.

Planned features include:

  • Foreign-key relations with (optionally) cascading reads, writes, deletes.
  • Transactional and asynchronous denormalization based on declarative struct tags.
  • Computed document properties.
  • Model history bookkeeping and visualization.
  • Smart retries for reads when Firestore is unavailable.
  • Smart retries for writes when an idempotency key is provided.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRegisterModel

func MustRegisterModel(m ReadableModel)

func RegisterModel

func RegisterModel(m ReadableModel) error

Types

type Client

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

A Client provides access to Firestore via the Calcifer ODM.

func NewClient

func NewClient(fs *firestore.Client) *Client

NewClient creates a new Calcifier client that uses the given Firestore client.

func (*Client) Collection

func (c *Client) Collection(path string) *CollectionRef

func (*Client) RunTransaction

func (c *Client) RunTransaction(ctx context.Context, f func(context.Context, *Transaction) error, opts ...TransactionOption) (err error)

type CollectionRef

type CollectionRef struct {

	// Use the methods of Query on a CollectionRef to create and run queries.
	Query
	// contains filtered or unexported fields
}

func (*CollectionRef) Doc

func (c *CollectionRef) Doc(id string) *DocumentRef

func (*CollectionRef) NewDoc

func (c *CollectionRef) NewDoc() *DocumentRef

NewDoc returns a DocumentRef with a uniquely generated ID.

type DocumentIterator

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

func (*DocumentIterator) GetAll

func (it *DocumentIterator) GetAll(ctx context.Context, p any) error

func (*DocumentIterator) Next

Next fetches the next result from Firestore, and unmarshals it into p. If error is iterator.Done, no result is unmarshalled. Once Next returns Done, all subsequent calls will return Done.

type DocumentRef

type DocumentRef struct {
	*firestore.DocumentRef
	// contains filtered or unexported fields
}

func (*DocumentRef) Collection

func (d *DocumentRef) Collection(id string) *CollectionRef

func (*DocumentRef) Delete

func (d *DocumentRef) Delete(ctx context.Context) error

Delete removes from Firestore the document at the path referred to by d if it exists.

func (*DocumentRef) Get

func (d *DocumentRef) Get(ctx context.Context, p MutableModel) error

Get fetches the document referred to by d from Firestore, and unmarshals it into p.

func (*DocumentRef) Set

Set writes a Model to Firestore at the path referred to by d.

type Model

type Model struct {
	ID         string    `calcifer:"id" json:"id"`
	CreateTime time.Time `calcifer:"create_time" json:"create_time"`
	UpdateTime time.Time `calcifer:"update_time" json:"update_time"`
}

A Model is a Go-native representation of a document that can be stored in Firestore. Embeded `Model` into your own struct to define other types of models.

type MutableModel

type MutableModel interface {
	// contains filtered or unexported methods
}

The MutableModel interface is satisfied only by pointers to calcifer.Model and structs that embed it.

type Query

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

Query represents a Firestore query.

Query values are immutable. Each Query method creates a new Query; it does not modify the old.

func (Query) Documents

func (q Query) Documents(ctx context.Context) *DocumentIterator

Documents returns an iterator over the query's resulting documents.

func (Query) Limit

func (q Query) Limit(n int) Query

Limit returns a new Query that specifies the maximum number of first results to return. It must not be negative.

func (Query) LimitToLast

func (q Query) LimitToLast(n int) Query

LimitToLast returns a new Query that specifies the maximum number of last results to return. It must not be negative.

func (Query) OrderBy

func (q Query) OrderBy(path string, dir firestore.Direction) Query

OrderBy returns a new Query that specifies the order in which results are returned. A Query can have multiple OrderBy/OrderByPath specifications. OrderBy appends the specification to the list of existing ones.

The path argument can be a single field or a dot-separated sequence of fields, and must not contain any of the runes "˜*/[]".

To order by document name, use the special field path DocumentID.

func (Query) Where

func (q Query) Where(path, op string, value interface{}) Query

Where returns a new Query that filters the set of results. A Query can have multiple filters. The path argument can be a single field or a dot-separated sequence of fields, and must not contain any of the runes "˜*/[]". The op argument must be one of "==", "!=", "<", "<=", ">", ">=", "array-contains", "array-contains-any", "in" or "not-in".

type Queryer

type Queryer interface {
	// contains filtered or unexported methods
}

A Queryer is a Query or a CollectionRef. CollectionRefs act as queries whose results are all the documents in the collection.

type ReadableModel

type ReadableModel interface {
	// contains filtered or unexported methods
}

The ReadbleModel interface is satisfied only by calcifer.Model and structs that embed it.

type Transaction

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

func (*Transaction) Delete

func (tx *Transaction) Delete(dr *DocumentRef) error

func (*Transaction) Documents

func (tx *Transaction) Documents(q Queryer) *DocumentIterator

func (*Transaction) Get

func (tx *Transaction) Get(dr *DocumentRef, m MutableModel) error

func (*Transaction) Set

func (tx *Transaction) Set(dr *DocumentRef, m ReadableModel) error

type TransactionOption

type TransactionOption any

Jump to

Keyboard shortcuts

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