surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
272 stars 45 forks source link

Bug: Unable to set NULL values #210

Closed dodanex closed 2 months ago

dodanex commented 5 months ago

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 fieldphone, with recordarticles: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

dodanex@gmail.com

Is there an existing issue for this?

Code of Conduct

ntorrey commented 4 months ago

@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.

AlbertMarashi commented 3 months ago

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>>
AlbertMarashi commented 3 months ago

Doing none instead of null seems to work, but anyone else think that's weird?..

UPDATE page:4krty932fk9atidjy4mr SET parent = none
armandoradan commented 3 months ago

@AlbertMarashi You shuold probably use <sometype|null> instead of option in table schema.

AlbertMarashi commented 3 months ago

@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

dodanex commented 3 months ago

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.

kearfy commented 2 months ago

This should be resolved by #227