Skip to content

A thin wrapper around Google's Firestore client library for Go.

Notifications You must be signed in to change notification settings

billykirk01/go-firestore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

✨ go-firestore

A thin wrapper around the Google's Firestore client library for Go.

📦 Installing

go get github.com/billykirk01/go-firestore

📖 Example Usage

package main

import (
   "fmt"
   log "github.com/sirupsen/logrus"
   firestore "github.com/billykirk01/go-firestore"
)

type person struct {
   First string
   Last  string
}

func main() {
   client, err := firestore.NewClient("~/path/to/firebase/credentials.json")
   if err != nil {
      log.Fatalf("Could not initialize Cloud Firestore: %v", err)
   }
   defer client.Close()

   p1 := person{
      First: "Billy",
      Last:  "Kirk",
   }

   docID, err := client.CreateDocument(client.Db.Collection("users"), p1)
   if err != nil {
      log.Fatalf("Failed adding document: %v", err)
   }

   fmt.Println("Saved document with ID:", docID)

   documents, err := client.GetDocuments(client.Db.Collection("users"))
   if err != nil {
      log.Fatalf("Failed adding document: %v", err)
   }

   fmt.Printf("Documents in users collection: %v\n", documents)

   queryResults, err := client.Query(client.Db.Collection("users").Where("First", "==", "foo"))
   if err != nil {
      log.Fatalf("Failed adding document: %v", err)
   }

   fmt.Printf("Documents in users collection with foo for first name: %v\n", queryResults)

   err = client.DeleteDocument(client.Db.Collection("users"), docID)
   if err != nil {
      log.Fatalf("Failed deleting document: %v", err)
   }

   fmt.Printf("Deleted document with ID: %s\n", docID)
}

About

A thin wrapper around Google's Firestore client library for Go.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages