firestore

package
v7.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func In added in v7.9.0

func In[T any](field string, values []T) repository.Option

In generates a new option that allows selecting all the elements where the given field contains any of the given values.

Multiple In options can be passed to a single Repository operation. They are logically ANDed together.

Repository.Find(&list, In[string]("Name", []string{"Andrew", "John"]))

func MaxResults

func MaxResults(n int) repository.Option

MaxResults defines the maximum number of results for an operation that can return multiple results. Passing this Option to a Repository operation overwrites any previous MaxResults options passed.

func NewFirestoreRepository

func NewFirestoreRepository[T repository.Model](client *firestore.Client) repository.Repository

NewFirestoreRepository initializes a new Repository implementation for Firestore collections.

func NoOp added in v7.9.0

func NoOp() repository.Option

NoOp is an option that performs no action. It is defined so that options functions can validate inputs and choose to do nothing because of some internal logic.

func Offset

func Offset(offset int) repository.Option

Offset defines a number of results to skip before starting to capture values to return. This Option will be ignored if the MaxResults Option is not present. Passing this Option to a Repository operation overwrites any previous Offset options passed.

func OrderBy

func OrderBy(orders ...OrderByField) repository.Option

OrderBy sorts results based on fields. Use the Ascending and Descending functions to pass orders to this Option. In situations with multiple orders, they are applied in sequence. Multiple OrderBy options can be passed to a single Repository operation. They are appended to any previous orders.

func SetCurrentPage added in v7.9.0

func SetCurrentPage(p pagination.Pagination) ([]repository.Option, error)

SetCurrentPage generates a set of repository.Option to retrieve results for a specific page.

func StartAfter

func StartAfter(fieldValues ...any) repository.Option

StartAfter initializes a new option that specifies that results should start right after the document with the given field values.

StartAfter should be called with one field value for each OrderBy clause, in the order that they appear. For example, in

Repository.Find(&list, OrderBy(Descending("Value"), Ascending("Name")), StartAfter(2, "Test"))

list will begin at the first document where Value = <2> + 1.

Calling StartAfter overrides a previous call to StartAfter.

func StartAt added in v7.8.0

func StartAt(fieldValues ...any) repository.Option

StartAt initializes a new option that specifies that results should start at document with the given field values.

StartAt should be called with one field value for each OrderBy clause, in the order that they appear. For example, in

Repository.Find(&list, OrderBy(Descending("Value"), Ascending("Name")), StartAt(1, "Test"))

list will begin at the first document where Value = <1> + 1.

Calling StartAt overrides a previous call to StartAt.

func Where

func Where(field string, op string, value interface{}) repository.Option

Where filters results based on passed conditions. Multiple Where options can be passed to a single Repository operation. They are logically ANDed together. The op argument must be one of "==", "!=", "<", "<=", ">", ">=", "array-contains", "array-contains-any", "in" or "not-in".

Types

type Model

type Model struct {
	// CreatedAt contains the date and time at which this model has been persisted.
	CreatedAt time.Time `firestore:"created_at"`
	// UpdatedAt contains the last date and time when this model has been updated.
	UpdatedAt time.Time `firestore:"updated_at"`
}

Model implements the repository.Model interface for firestore. It provides a set of common generic fields and operations that partially implement the repository.Model interface. To use it, embed it in your application-specific repository.Model implementation.

func (Model) GetID

func (m Model) GetID() uint

GetID returns the unique identifier for this Model.

type Option

type Option func(q *firestore.Query)

Option is a Firestore-specific repository.Option implementation. It is used to configure Firestore repository operations.

func (Option) IsOption

func (o Option) IsOption()

type OrderByField

type OrderByField struct {
	Field     string
	Direction firestore.Direction
}

OrderByField contains order by information for a field

func Ascending

func Ascending(field string) OrderByField

Ascending sorts the passed field in ascending order.

func Descending

func Descending(field string) OrderByField

Descending sorts the passed field in descending order.

Jump to

Keyboard shortcuts

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