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

Commit

Permalink
Merge b27f877 into 480e9ac
Browse files Browse the repository at this point in the history
  • Loading branch information
theprojectabot committed Jun 24, 2016
2 parents 480e9ac + b27f877 commit d65e2ea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
formatParam = "format"
shallowParam = "shallow"
orderByParam = "orderBy"
equalToParam = "equalTo"
startAtParam = "startAt"
endAtParam = "endAt"
formatVal = "export"
Expand Down
13 changes: 13 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ func (fb *Firebase) OrderBy(value string) *Firebase {
return c
}

// EqualTo sends the query string equalTo so that one can find a single value
//
// Reference https://www.firebase.com/docs/rest/guide/retrieving-data.html#section-rest-filtering
func (fb *Firebase) EqualTo(value string) *Firebase {
c := fb.copy()
if value != "" {
c.params.Set(equalToParam, escapeString(value))
} else {
c.params.Del(equalToParam)
}
return c
}

func escapeString(s string) string {
_, err := strconv.ParseInt(s, 10, 64)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ func TestOrderBy(t *testing.T) {
assert.Equal(t, orderByParam+"=%22user_id%22", req.URL.Query().Encode())
}

func TestEqualTo(t *testing.T) {
t.Parallel()
var (
server = newTestServer("")
fb = New(server.URL, nil)
)
defer server.Close()

fb.EqualTo("user_id").Value("")
require.Len(t, server.receivedReqs, 1)

req := server.receivedReqs[0]
assert.Equal(t, equalToParam+"=%22user_id%22", req.URL.Query().Encode())
}

func TestLimitToFirst(t *testing.T) {
t.Parallel()
var (
Expand Down

0 comments on commit d65e2ea

Please sign in to comment.