firebase / firebase/firebase-admin-go

FR: ServerTimestamp constant for firebase.database

Open
#376 0 comments 2 reactions 0 assignees View on GitHub
api: database help wanted type: feature request
Dominant language
Go
Stars
1.3k
Forks
274
Avg merge
10h 39m
Merged PRs (30d)
2

Description

### Describe your environment

* Operating System version: all
* Firebase SDK version: v3.13.0
* Firebase Product: database

### Describe the problem

The serverside timestamp value is a unique field in Firebase databases, as it's uploaded with the json `{ ".sv" : "timestamp" }` and then converted to a timestamp on the serverside.

The javascript realtime database sdk has a constant called [firebase.database.ServerValue.TIMESTAMP](https://firebase.google.com/docs/reference/js/firebase.database.ServerValue#timestamp) for this.

The golang Firestore sdk has a constant for the ServerTimestamp value : . https://godoc.org/cloud.google.com/go/firestore#pkg-constants.

And allows setting it in a struct as :

```golang
type TimeObject struct {
TS time.Time `firestore:"ts, serverTimestamp"`
}
```

This seems to be missing in the `database` SDK. I guess the `serverTimestamp` value is a sugar on top, but it would be nice to have the constant available in the database package as well.

#### Relevant Code:

```golang
type TimeObject struct {
TS time.Time `json:"ts"`
}

data := TimeObject{
TS: firebase.db.ServerTimestamp
}

_, err := firebase.db.NewRef("someref").Push(context.Background(), data)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.