[go: nahoru, domu]

Skip to content
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

Open
tomasweigenast opened this issue Feb 3, 2021 · 5 comments
Open

Global converters for different types #1408

tomasweigenast opened this issue Feb 3, 2021 · 5 comments
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@tomasweigenast
Copy link

The idea is to set global converters, maybe using

admin.firestore().settings({
    converters: []
})

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 use snapshot.data() as MyModel, because if MyModel contains a Date property, it will be undefined since Timestamp cannot be converted directly to Date. This can be solved using a converter and withConverter, but it makes sense to have many converters only for a Date property? Why we can make it global using FirestoreDataConverter<Date> ?

@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Feb 3, 2021
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Feb 4, 2021
@var-const var-const self-assigned this Feb 5, 2021
@var-const var-const added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Feb 5, 2021
@wu-hui wu-hui assigned wu-hui and unassigned var-const Feb 12, 2021
@wu-hui
Copy link
Contributor
wu-hui commented Mar 9, 2021

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.

@cedricdg
Copy link
cedricdg commented Apr 19, 2021

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:
1. Timestamp - Date Conversion: Why can't we simply add a setting like convertTimestampToDate to enable the conversion of Timestamp to Date? From a technical perspective I understand the advantages of using Timestamp, but firebase is so awesome because of its developer friendliness and usability. Therefore I'd love to see an easy way to work with Dates.

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:
When we try to share backend and frontend types it's a big hassle right now when using firebase specific types. This is because of the incompatibility between nodejs and js-client library types.

@inf0rmatix-old
Copy link

Push

@Brucbbro
Copy link

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?
What would be the recommended approach to dealing with the native type differences?

@wu-hui
Copy link
Contributor
wu-hui commented Jan 17, 2022

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

7 participants