tekartik / sembast.dart

Simple io database
BSD 2-Clause "Simplified" License
780 stars 64 forks source link

Ambiguity around null record value #380

Closed duard-sf closed 3 months ago

duard-sf commented 3 months ago

The README reports that a record may have null as its value. However, SembastRecordRefExtension._checkValueArgument throws ArgumentError.notNull if the value is null. Additionally, the CHANGELOG reports that null is no longer supported for record values since version 3.0.0+6.

Ideally, I would like to have seen support for nullable record values remain. There are similarities between Sembast and Firestore, and Firestore does support null values.

Alternatively, the README should be updated to remove null as a supported value. I would also really appreciate some recommendations on how to handle nullable values in Sembast added to README.

alextekartik commented 3 months ago

null is not supported (only for the root value, a map or a list can contain null) sorry I will check the documentation. Firestore (AFAIK) does not support null neither for its root value (it can only be an empty map).

Alternatively, the README should be updated to remove null as a supported value

As I said you can have {'test': null} or [1, null, 'test]. But indeed a record data itself cannot be null like almost any database so I'm not sure what recommendation I could make.

duard-sf commented 3 months ago

Yes, you're right. Firestore documents cannot be null themselves, but their fields can.

My confusion arose from this part of the README:

image

Which is unclear about what is actually allowed to be null. In my case, I interpreted this as a record's value can be null, so this is valid: await store.record(123).put(db, null).

Since this is working as designed, I guess this issue can be closed. Thanks for the quick help!

alextekartik commented 3 months ago

I have added some clarification (that will be available the next time the package is updated): https://github.com/tekartik/sembast.dart/commit/f0ea94a57ce35d9aa37f95f284a9d8a8a69c424c