Description
What feature would you like to see?
When interacting with Firestore via POJOs, there are a couple of annotations available for server-derived values (@DocumentId
and @ServerTimestamp
). These correspond with the sentinel values you can use when storing data as Maps<>
-- .add()
and FieldValue.serverTimestamp()
.
There does not seem to be an annotation equivalent of FieldValue.increment()
.
How would you use it?
This feature would be used in the same ways as FieldValue.increment()
but will work for developers that choose to use POJOs instead of Maps for storing data. Developers could of course do this manually, but there are potentially several places where they'd have to remember to increment the field.
The default would increment the field by 1 every time the POJO is persisted.
@Increment
public Long version() {
return this.version;
}
To have parity with the FieldValue API, you could specify how much to increment:
@Increment(2)
public Long version() {
return this.version;
}
It will also need to work with double
fields.
If the POJO field is null
, increment the database's version by the specified amount. The only question becomes what to do with values that are set
- Store the value as-is without incrementing (similar to
@ServerTimestamp
) - Increment the value by the specified amount (would make sense for read/write cycles)
This ambiguity is also present with @ServerTimestamp
so this isn't really a new problem -- is it a "created on" timestamp or an "updated on" timestamp; it's hard to tell.