Bug: Unable to set NULL values
dodanex opened this issue · 7 comments
Describe the bug
If you try to save NULL values, the database will return an error:
Error: There was a problem with the database: Found NULL for field
phone, with record
articles:43qqmitt0iqd7vmfvmsa, but expected a string
Steps to reproduce
Try to save into the database a value with null
:
{
"name": "test",
"email": "", <----- this is working
"phone": null, <----- this is not working
}
Expected behaviour
According to this documentation the database accepts null values.
NULL is a special value in JavaScript and we should be able to save it without problems.
SurrealDB version
1.1.1
SurrealDB.js version
0.11.0
Contact Details
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
@micha
Sorry for the ping, but related to this, when I try to run the merge
command - from the js library - with a null
or undefined
field value, it erases the entire record - everything except the id! It would be better if an error were thrown in my opinion.
Also getting a similar issue
UPDATE page:4krty932fk9atidjy4mr SET parent = null
Found NULL for field `parent`, with record `page:4krty932fk9atidjy4mr`, but expected a option<record<page>>
Doing none
instead of null
seems to work, but anyone else think that's weird?..
UPDATE page:4krty932fk9atidjy4mr SET parent = none
@AlbertMarashi You shuold probably use <sometype|null> instead of option in table schema.
@AlbertMarashi You shuold probably use <sometype|null> instead of option in table schema.
Hmm, I dunno I think in my case it makes sense to use option<object>
- I don't really need to know whether something is null
but set in my case. Using none
is okay
The point is that surrealdb.js
is a JavaScript library, and JavaScript uses the null
as a special value. For example you may have an array or object that has null
values inside it and you want to save this to the database and the library must handle this.