-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global converters for different types #1408
Comments
Hey there, Sorry for responding so late. We definitely understand the pain you have, and want to address this. However, we currently don't have a good idea of how to implement this gracefully. We will keep this issue open while we search for solutions. In the meantime, if you have some concrete ideas, please share. |
Like @TomasWeg said, also in my projects I only use converters to convert Timestamp into Date. I believe this is the most common use case for this kind of problem. From the top of my head here are two options: admin.firestore().settings({
convertTimestampToDate: true;
}) 2. Converter for Firebase types: Setting global converters for firebase types like Timestamp, GeoPoint etc. admin.firestore().settings({
converters: [{
type: 'Timestamp',
to: (timestamp: Timestamp) => timestamp.toDate(),
from: (date: Date) => Timestamp.fromDate(date)
}]
}) Incompatibility of Firebase Types: |
Push |
Strongly agree with @cedricdg . I'm about to write converters just about anywhere in my database abstraction for firebase: having this out of the box would have saved me a lot of time, and frankly I don't understand how this issue had so little traffic. Feels like just about every dev using firestore would stumble upon this at some point? |
Hi all, This is something we would like to do if we have capacity. The team is short handed at the moment, and unfortunately we do not know when we can work on this. OTOH, PRs are always welcome if anyone feeling like helping other users :-) |
The idea is to set global converters, maybe using
That can be reused along with all the requests and for individual types, for example, for
Timestamp
:I have many models where I use the Javascript Date object which gets converted to a
Timestamp
object, and when I get from the database, I cannot usesnapshot.data() as MyModel
, because ifMyModel
contains a Date property, it will be undefined since Timestamp cannot be converted directly to Date. This can be solved using a converter andwithConverter
, but it makes sense to have many converters only for a Date property? Why we can make it global usingFirestoreDataConverter<Date>
?The text was updated successfully, but these errors were encountered: