You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I admit a very niche usecase, but i still think a potentially useful one.
I've got a Sveltekit app and i am sending db data from the server to the client. Sveltekit is able to to send POJOs to the client, and is even auto parsing Date instances accordingly, so the user does not need to add special handling to stringify and parse said Date.
What it (logically) is not able to handle stuff like RecordId, which can be nicely handled with jsonify though.
The thing if jsonify parses datetimes into strings, reintroducing the need to add some special handling on the client side to parse the datetime strings back into Date instances.
Describe the solution
It would be nice to have some sort of reviver function on jsonify. Similar to the reviver of JSON.parse(). Enabling users to add custom handling to specific fields if needed. This would enable me to easily ignore Date during conversion.
Maybe something like this:
returnjsonify(entries,(key,value,resolve)=>{// If value is instance of Date, do nothimg if(valueinstanceofDate){returnvalue;}// on every other case call the default value resolve functionreturnresolve(value);});
Alternative methods
Implementing some custom handling like this:
consttest=JSON.parse(JSON.stringify(users),(key,value)=>{// one needs to know the keys to be able to do thisif(key==='datetime_field'){returnnewDate(value);}returnvalue;});
This seems very resource intensive and requires prior knowledge of the data structure.
SurrealDB version
surreal 2.1.2 for linux on x86_64
JavaScript SDK version
1.1.0
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
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem?
I admit a very niche usecase, but i still think a potentially useful one.
I've got a Sveltekit app and i am sending db data from the server to the client. Sveltekit is able to to send POJOs to the client, and is even auto parsing
Date
instances accordingly, so the user does not need to add special handling to stringify and parse saidDate
.What it (logically) is not able to handle stuff like
RecordId
, which can be nicely handled withjsonify
though.The thing if
jsonify
parses datetimes into strings, reintroducing the need to add some special handling on the client side to parse the datetime strings back intoDate
instances.Describe the solution
It would be nice to have some sort of reviver function on
jsonify
. Similar to thereviver
ofJSON.parse()
. Enabling users to add custom handling to specific fields if needed. This would enable me to easily ignoreDate
during conversion.Maybe something like this:
Alternative methods
Implementing some custom handling like this:
This seems very resource intensive and requires prior knowledge of the data structure.
SurrealDB version
surreal 2.1.2 for linux on x86_64
JavaScript SDK version
1.1.0
Contact Details
No response
Is there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: