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

date columns should be provided as DateTime instead of String. #845

Open
mateusfccp opened this issue Feb 25, 2024 · 5 comments
Open

date columns should be provided as DateTime instead of String. #845

mateusfccp opened this issue Feb 25, 2024 · 5 comments
Labels
blocked This issue is blocked by another issue enhancement New feature or request postgrest This issue or pull request is related to postgrest

Comments

@mateusfccp
Copy link

mateusfccp commented Feb 25, 2024

Is your feature request related to a problem? Please describe.
Currently, if I have a table with a column of type date, when I query for the data, the runtime type of the data is String.

For instance, for a date value of 2024-02-25, I receive the string "2024-25-02".

Describe the solution you'd like
Instead, we should receive DateTime.

For instance, for a date value of 2024-02-25, I should receive the object DateTime(2024, 02, 25).

Describe alternatives you've considered
The alternative is to do nothing and let the consumer parse the date. This is how we have to do currently.

void main() async {
	final data = await supabase.from('members').select('birthday');
	for (final datum in data) {
		final birthday = DateTime.parse(datum['birthday']); // Manually parsing the received string
		// Do something with `birthday`...
	}
}
@mateusfccp mateusfccp added the enhancement New feature or request label Feb 25, 2024
@dshukertjr dshukertjr added the postgrest This issue or pull request is related to postgrest label Feb 26, 2024
@Vinzent03
Copy link
Collaborator

I think postgrest-js just returns them as string as well. We would have to do the same as you and manually try to parse every column. This may cause issues with columns that are not intended to be DateTime objects. It's better if the api is clean and everything is string/int/bool, because the data is coming in as JSON.

@dshukertjr
Copy link
Member

We would need the type generation to happen for this. It would be awesome if we could support it though!

@mateusfccp
Copy link
Author

mateusfccp commented Mar 1, 2024

This may cause issues with columns that are not intended to be DateTime objects.

Do you think it's common to define a column as date and don't want it to be a DateTime? If I want some data to be a string, wouldn't I rather use varchar or text as the column type?

It's better if the api is clean and everything is string/int/bool, because the data is coming in as JSON.

Is it a requirement that Data comes as JSON in Dart? I don't see any advantage in doing so...

@Vinzent03
Copy link
Collaborator

The postgrest endpoint only returns a json for our query, we don't have any information about the type of the columns. Therefore, we cannot do any converting.

@mateusfccp
Copy link
Author

The postgrest endpoint only returns a json for our query, we don't have any information about the type of the columns. Therefore, we cannot do any converting.

Didn't know about this detail.

Maybe we should have this information, as it's really important.

@Vinzent03 Vinzent03 added the blocked This issue is blocked by another issue label Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This issue is blocked by another issue enhancement New feature or request postgrest This issue or pull request is related to postgrest
Projects
None yet
Development

No branches or pull requests

3 participants