surrealdb/surrealdb.js

Bug: problems in v1.0.0-beta.5 with select, delete and update functions when providing ID and inconsistency when returning JSON results from select and create functions.

dodanex opened this issue · 2 comments

Describe the bug

  1. The select function is not working when adding an ID, for example: db.select('table:id') will not return the correct result, but an empty array. Same happens for the update() and delete() functions.

  2. The JSON result from the select() or create() function is not consistent with what the database shows in the Surrealist or when directly calling the database via CURL http://localhost:8000/sql and selecting.

Here you have a screenshot with the Surrealist result and the Network request from Browser Developer Tools made in an Nuxt app:
Screenshot 2024-04-27 034003

In the old version v0.11.1 those methods worked fine!

Steps to reproduce

Connect to the database using surrealdb.js v1.0.0-beta.5 and try to get a result by id using db.select('table:id') and you will get an empty array. Also test for db.delete('table:id') and db.select('table:id', object)

Then do the same request using v0.11.1 and you will get the correct result.

Expected behaviour

  1. The functions should work as expected when passing an ID.
  2. The JSON result should be consistent with the database, don't put the id inside an object,

SurrealDB version

1.4.2

SurrealDB.js version

1.0.0-beta.5

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

Hey @dodanex! I haven't had the time just yet to update the docs unfortunately, but the way Record IDs and some other native types are represented is changing in surrealdb.js v1.0.0. Due to the newly introduced CBOR protocol, we now have an understanding of values native to SurrealQL, but not JSON, like Record IDs.

This means that you would now use the new RecordId class to select, create or alter specific records, like so:

await db.select(new RecordId("table", "id"));

As some people mentioned they had some usecases where they need to be able to work with string representations of Record IDs, I did the work in #256 to make this possible again, like

const res = await db.select(new StringRecordId("table:id"));
res.id.toString();

Lastly, selecting, creating or altering a specific Record ID instead of a table in general will now return just the object representing that record, instead of an array of objects.

This will be pushed in the next beta, I hope this helps!

Thank you for your detailed answer!