goFirebase

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 5 Imported by: 0

README

Firebase Go CRUD Documentation

The firebase-go-crud.go file provides an interface for interacting with Firebase Firestore to perform CRUD (Create, Read, Update, Delete) operations on documents.

Structure

The file defines a FirebaseClient structure that encapsulates a Firebase client and an execution context. This structure provides methods to interact with Firestore.

Methods

NewFirebaseClient

Creates a new Firebase client.


func NewFirebaseClient(ctx context.Context, projectID string, secretsJSON []byte) (*FirebaseClient, error)
  • ctx: The execution context.
  • projectID: The Firebase project ID.
  • secretsJSON: The JSON credentials.
GetDocument

Retrieves a document from a specified collection.

func (f *FirebaseClient) GetDocument(collection string, document string) (map[string]interface{}, error)
  • collection: The name of the collection.
  • document: The ID of the document to retrieve.

DeleteDocument

Deletes a document from a specified collection.

func (f *FirebaseClient) DeleteDocument(collection string, document string) error
collection: The name of the collection.
  • document: The ID of the document to delete.

UpsertDocument

Inserts or updates a document in a specified collection with the provided data.

func (f *FirebaseClient) UpsertDocument(collection string, document string, data map[string]interface{}) error
  • collection: The name of the collection.
  • document: The ID of the document to insert or update.
  • data: The data to insert or update in the document.

Dependencies

This file depends on the following libraries:

  • cloud.google.com/go/firestore
  • firebase.google.com/go
  • google.golang.org/api/option

Ensure you have these dependencies in your go.mod file to use the Firebase client.

For more details on the methods and their usage, refer to the source code in firebase-go-crud.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FirebaseClient

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

FirebaseClient is a wrapper around the firebase.App client.

func NewFirebaseClient

func NewFirebaseClient(ctx context.Context, projectID string, secretsJSON []byte) (*FirebaseClient, error)

NewFirebaseClient creates a new Firebase client with the provided project ID and secrets JSON. It initializes the Firebase app using the given context, project ID, and secrets JSON. Returns a pointer to the created FirebaseClient and any error encountered during initialization.

func (*FirebaseClient) DeleteDocument

func (f *FirebaseClient) DeleteDocument(collection string, document string) error

DeleteDocument deletes a document from the specified collection in Firestore. It takes the collection name and document ID as parameters. Returns an error if there was a problem deleting the document.

func (*FirebaseClient) GetDocument

func (f *FirebaseClient) GetDocument(collection string, document string) (map[string]interface{}, error)

GetDocument retrieves a document from a specified collection in Firestore. It takes the collection name and document ID as parameters and returns the document data as a map[string]interface{} and an error, if any.

func (*FirebaseClient) UpsertDocument

func (f *FirebaseClient) UpsertDocument(collection string, document string, data map[string]interface{}) error

UpsertDocument inserts or updates a document in the specified collection with the provided data. If the document already exists, it will be updated with the new data. If it doesn't exist, a new document will be created. The function returns an error if there was a problem with the Firestore operation.

Jump to

Keyboard shortcuts

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