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

Feature: Don't auto-convert dates to ISO 8601 #1328

Closed
2 tasks done
ntorrey opened this issue Oct 6, 2022 · 7 comments
Closed
2 tasks done

Feature: Don't auto-convert dates to ISO 8601 #1328

ntorrey opened this issue Oct 6, 2022 · 7 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@ntorrey
Copy link

ntorrey commented Oct 6, 2022

Is your feature request related to a problem?

Maybe this is related to #1301.

TL;DR
It seems to me that it would be better for the developer to determine the way his data is stored and not have SurrealDB decide that for him/her.

I need to store an array of dates and wish there were a simple way to keep them in the string format I assign them. For example, taking advantage of the CONTENT statement is really convenient for me since I can update data directly from a javascript (stringified) object:

UPDATE thing:id123 CONTENT { 
  dateArray: [
    '2022-10-06', 
    '2022-10-07', 
    '2022-10-08'
  ] 
}

To avoid surrealDB's conversion, I would need to run my object through a string conversion function (or make a more complex query statement) before sending the UPDATE/CONTENT statement, and this would be complicated with nested dates. It would end up looking something like this:

UPDATE thing:id123 CONTENT { 
  dateArray: [
    time::format('2022-10-06', '%Y-%m-%d'), 
    time::format('2022-10-07', '%Y-%m-%d'), 
    time::format('2022-10-08', '%Y-%m-%d')
  ]
}

I guess I'm just trying to figure out a way to reduce complexity, and I'd have to do this a little differently in each case depending on the structure of the data.
In addition, auto-formatting to UTC time complicates things for me because I want the date to be the same regardless of the time zone I'm in. Think of a calendar feature for a school (which is basically what I'm building): If I'm viewing the calendar from a different time zone all of the dates would be shifted unless I process the dates after receiving them which can get a little annoying.

All of this would be much simpler if SurrealDB didn't auto-convert my dates.
If a developer needs the date in UTC 8601 format, it is probably the case that they're already working with those formats in whatever codebase they're using.

Describe the solution

Don't auto-convert the dates! It seems to me that it would be better for the developer to determine the way their data is stored. For example, leave it up to them to cast a string to a datetime if they so desire:

UPDATE test:123 SET date = <datetime> '2022-10-05'

// output
result: [
  id: 'test:123',
  date: '2022-10-05T00:00:00Z'
] 

...and this is a feature that's already built into SurrealDB! (https://surrealdb.com/docs/surrealql/datamodel/casting)

Alternative methods

Doing lots of somersaults in my code 😄 !

SurrealDB version

Nightly release 13 (Oct 4, 2022)

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ntorrey ntorrey added feature New feature or request triage This issue is new labels Oct 6, 2022
@Shimori77
Copy link

Shimori77 commented Oct 6, 2022

I would like to have this feature too, it's bothersome to have to deal with your data format changing.

It is nice that the way it is now can normalize data across the schema though! So can we have both and can switch which one we prefer?

Or even better, let the developer create a custom converter for the format we desire?

@AntoniosBarotsis
Copy link

Perhaps a nice solution would be to have the ability to specify a date format string somewhere which could default to ISO 8601 if left empty.

@ntorrey
Copy link
Author

ntorrey commented Oct 6, 2022

@AntoniosBarotsis Hmm, like in an individual query or as a global setting for the entire database? As a query could be interesting, something like:

UPDATE thing:id123 CONTENT { 
  dateArray: [
    '2022-10-06', 
    '2022-10-07', 
    '2022-10-08'
  ] 
}
DATEFORMAT None 

...although it still seems to me that auto-conversion of dates should be something more like an 'opt-in' feature.

@AntoniosBarotsis
Copy link

I feel like per query would be an unnecessary slow down, was think something more like a column specific setting

@ntorrey
Copy link
Author

ntorrey commented Oct 6, 2022

Ah, right. Yes, I suppose in schemafull tables that might even already be possible (I haven't tried it). But that wouldn't work for schemaless tables which is what I'm using.

@tobiemh tobiemh removed the triage This issue is new label Oct 9, 2022
@tobiemh tobiemh added this to the v1.0.0-beta.9 milestone Oct 9, 2022
@oricc
Copy link
Contributor

oricc commented Oct 12, 2022

I believe the best way is to have schemaless tables have no casting whatsoever, while schemafull will cast the columns using it's field definition, this seems to me the most natural way, as it allows for consistency in either table type

@tobiemh tobiemh self-assigned this Oct 17, 2022
@ntorrey
Copy link
Author

ntorrey commented Oct 17, 2022

Woohoo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants