Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Specify that Value() return a map on the lists #87

Closed
erwanlbp opened this issue Aug 25, 2017 · 2 comments
Closed

Specify that Value() return a map on the lists #87

erwanlbp opened this issue Aug 25, 2017 · 2 comments

Comments

@erwanlbp
Copy link

In the README, please say that Firebase.Value() returns a map[string]interface{} when it is used to query lists, I spent quite some time figuring that (Newbie speaking)

@zabawaba99
Copy link
Owner

I don't mind adding a snippet in the README to describe this behavior. It's a Firebase specific thing though.

For example,

package main

import (
	"log"

	"github.com/zabawaba99/firego"
)

func main() {
	fb := firego.New("https://my-app.firebaseio.com/issue62", nil)
	// auth configuration left out intentionally

	testData := map[string]string{
		"1": "tkn1",
		"2": "tkn1",
		"3": "tkn2",
		"4": "tkn3",
		"5": "tkn4",
		"6": "tkn5",
	}

	if err := fb.Set(testData); err != nil {
		panic(err)
	}

	var v interface{}
	if err := fb.Value(&v); err != nil {
		log.Fatalf("cannot get value %s", err)
	}

	log.Printf("Before deletion %#v\n", v)

	fb.Child("2").Remove()
	fb.Child("3").Remove()
	fb.Child("5").Remove()

	if err := fb.Value(&v); err != nil {
		log.Fatalf("cannot get value %s", err)
	}

	log.Printf("After deletion %#v\n", v)
}

Prints out

$ go run issue62.go
2017/08/26 17:03:00 Before deletion []interface {}{interface {}(nil), "tkn1", "tkn1", "tkn2", "tkn3", "tkn4", "tkn5"}
2017/08/26 17:03:00 After deletion map[string]interface {}{"6":"tkn5", "1":"tkn1", "4":"tkn3"}

IIRC, if you end up deleting for than X amount of values inside the array, then it's returned as a map

@zabawaba99
Copy link
Owner

Closing issue as repository is being archived.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants