Documentation ¶
Overview ¶
Package db contains functions for accessing the Firebase Realtime Database.
Index ¶
- func RedirectIntegrated()
- type Client
- type Event
- type EventType
- type Query
- func (q *Query) EndAt(v interface{}) *Query
- func (q *Query) EqualTo(v interface{}) *Query
- func (q *Query) Get(ctx context.Context, v interface{}) error
- func (q *Query) GetOrdered(ctx context.Context) ([]QueryNode, error)
- func (q *Query) LimitToFirst(n int) *Query
- func (q *Query) LimitToLast(n int) *Query
- func (q *Query) StartAt(v interface{}) *Query
- type QueryNode
- type Ref
- func (r *Ref) Child(path string) *Ref
- func (r *Ref) Delete(ctx context.Context) error
- func (r *Ref) Get(ctx context.Context, v interface{}) error
- func (r *Ref) GetIfChanged(ctx context.Context, etag string, v interface{}) (bool, string, error)
- func (r *Ref) GetShallow(ctx context.Context, v interface{}) error
- func (r *Ref) GetWithETag(ctx context.Context, v interface{}) (string, error)
- func (r *Ref) Listen(ctx context.Context) (*SnapshotIterator, error)
- func (r *Ref) OrderByChild(child string) *Query
- func (r *Ref) OrderByKey() *Query
- func (r *Ref) OrderByValue() *Query
- func (r *Ref) Parent() *Ref
- func (r *Ref) Push(ctx context.Context, v interface{}) (*Ref, error)
- func (r *Ref) Set(ctx context.Context, v interface{}) error
- func (r *Ref) SetIfUnchanged(ctx context.Context, etag string, v interface{}) (bool, error)
- func (r *Ref) Transaction(ctx context.Context, fn UpdateFn) error
- func (r *Ref) Update(ctx context.Context, v map[string]interface{}) error
- type SnapshotIterator
- type TransactionNode
- type UpdateFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RedirectIntegrated ¶
func RedirectIntegrated()
If you can call this function, the redirect was implemented correctly.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the interface for the Firebase Realtime Database service.
type Event ¶
type Event struct { EventType EventType // ChildChanged, ValueChanged, ChildAdded, ChildRemoved Data string // JSON-encoded snapshot Path string // snapshot path }
Event Sever-Sent Event object
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query represents a complex query that can be executed on a Ref.
Complex queries can consist of up to 2 components: a required ordering constraint, and an optional filtering constraint. At the server, data is first sorted according to the given ordering constraint (e.g. order by child). Then the filtering constraint (e.g. limit, range) is applied on the sorted data to produce the final result. Despite the ordering constraint, the final result is returned by the server as an unordered collection. Therefore the values read from a Query instance are not ordered.
func (*Query) EndAt ¶
EndAt returns a shallow copy of the Query with v set as a upper bound of a range query.
The resulting Query will only return child nodes with a value less than or equal to v.
func (*Query) EqualTo ¶
EqualTo returns a shallow copy of the Query with v set as an equals constraint.
The resulting Query will only return child nodes whose values equal to v.
func (*Query) Get ¶
Get executes the Query and populates v with the results.
Data deserialization is performed using https://golang.org/pkg/encoding/json/#Unmarshal, and therefore v has the same requirements as the json package. Specifically, it must be a pointer, and must not be nil.
Despite the ordering constraint of the Query, results are not stored in any particular order in v. Use GetOrdered() to obtain ordered results.
func (*Query) GetOrdered ¶
GetOrdered executes the Query and returns the results as an ordered slice.
func (*Query) LimitToFirst ¶
LimitToFirst returns a shallow copy of the Query, which is anchored to the first n elements of the window.
func (*Query) LimitToLast ¶
LimitToLast returns a shallow copy of the Query, which is anchored to the last n elements of the window.
type Ref ¶
Ref represents a node in the Firebase Realtime Database.
func (*Ref) Get ¶
Get retrieves the value at the current database location, and stores it in the value pointed to by v.
Data deserialization is performed using https://golang.org/pkg/encoding/json/#Unmarshal, and therefore v has the same requirements as the json package. Specifically, it must be a pointer, and must not be nil.
func (*Ref) GetIfChanged ¶
GetIfChanged retrieves the value and ETag of the current database location only if the specified ETag does not match.
If the specified ETag does not match, returns true along with the latest ETag of the database location. The value of the database location will be stored in v just like a regular Get() call. If the etag matches, returns false along with the same ETag passed into the function. No data will be stored in v in this case.
func (*Ref) GetShallow ¶
GetShallow performs a shallow read on the current database location.
Shallow reads do not retrieve the child nodes of the current reference.
func (*Ref) GetWithETag ¶
GetWithETag retrieves the value at the current database location, along with its ETag.
func (*Ref) Listen ¶
func (r *Ref) Listen(ctx context.Context) (*SnapshotIterator, error)
Listen returns an iterator that listens to realtime events
func (*Ref) OrderByChild ¶
OrderByChild returns a Query that orders data by child values before applying filters.
Returned Query can be used to set additional parameters, and execute complex database queries (e.g. limit queries, range queries). If r has a context associated with it, the resulting Query will inherit it.
func (*Ref) OrderByKey ¶
OrderByKey returns a Query that orders data by key before applying filters.
Returned Query can be used to set additional parameters, and execute complex database queries (e.g. limit queries, range queries). If r has a context associated with it, the resulting Query will inherit it.
func (*Ref) OrderByValue ¶
OrderByValue returns a Query that orders data by value before applying filters.
Returned Query can be used to set additional parameters, and execute complex database queries (e.g. limit queries, range queries). If r has a context associated with it, the resulting Query will inherit it.
func (*Ref) Parent ¶
Parent returns a reference to the parent of the current node.
If the current reference points to the root of the database, Parent returns nil.
func (*Ref) Push ¶
Push creates a new child node at the current location, and returns a reference to it.
If v is not nil, it will be set as the initial value of the new child node. If v is nil, the new child node will be created with empty string as the value.
func (*Ref) Set ¶
Set stores the value v in the current database node.
Set uses https://golang.org/pkg/encoding/json/#Marshal to serialize values into JSON. Therefore v has the same requirements as the json package. Values like functions and channels cannot be saved into Realtime Database.
func (*Ref) SetIfUnchanged ¶
SetIfUnchanged conditionally sets the data at this location to the given value.
Sets the data at this location to v only if the specified ETag matches. Returns true if the value is written. Returns false if no changes are made to the database.
func (*Ref) Transaction ¶
Transaction atomically modifies the data at this location.
Unlike a normal Set(), which just overwrites the data regardless of its previous state, Transaction() is used to modify the existing value to a new value, ensuring there are no conflicts with other clients simultaneously writing to the same location.
This is accomplished by passing an update function which is used to transform the current value of this reference into a new value. If another client writes to this location before the new value is successfully saved, the update function is called again with the new current value, and the write will be retried. In case of repeated failures, this method will retry the transaction up to 25 times before giving up and returning an error.
The update function may also force an early abort by returning an error instead of returning a value.
type SnapshotIterator ¶
type SnapshotIterator struct { Snapshot string // initial snapshot, JSON-encoded, returned from http Respoonse, server sent event, data part SSEDataChan <-chan string // continuous event snapshot, channel receive only, directional channel // contains filtered or unexported fields }
SnapshotIterator iterator for continuous events
func (*SnapshotIterator) Done ¶
func (it *SnapshotIterator) Done() bool
Done can be used to check if Stop() have been called
func (*SnapshotIterator) Next ¶
func (it *SnapshotIterator) Next() (*Event, error)
Next realtime event
func (*SnapshotIterator) Stop ¶
func (it *SnapshotIterator) Stop()
Stop listening for realtime events close http connection
type TransactionNode ¶
type TransactionNode interface {
Unmarshal(v interface{}) error
}
TransactionNode represents the value of a node within the scope of a transaction.
type UpdateFn ¶
type UpdateFn func(TransactionNode) (interface{}, error)
UpdateFn represents a function type that can be passed into Transaction().