Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Unclear behavior for db.insert #368

Open
2 tasks done
knackstedt opened this issue Nov 11, 2024 · 1 comment
Open
2 tasks done

Bug: Unclear behavior for db.insert #368

knackstedt opened this issue Nov 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@knackstedt
Copy link
Contributor

Describe the bug

This may be an artifact of the (as I percieve it) ambiguous table name setup in the JS SDK of SurrealDB.
The documentation suggests using a colon followed by mathematical angle brackets to create a new object in a table with the contents of the mathematical brackets as the id.
However, all it does is declare a table and NOT insert a new record into said table.

If the functionality is meant to create a table with whatever the string contents are, that's fine but it needs to be documented in the JS SDK. It would also need to actually insert the object I pass in the same way as when I call the method with a simple ascii string that doesn't have any unusual characters.

image
image

Steps to reproduce

    await db.insert("foobar:123", { thing: true });
    await db.insert("foobar:guid()", { thing: true });
    await db.insert("foobar:⟨456⟩", { thing: true });
    
    
    await db.create(new RecordId('foobar', '789'), { thing: true });
    

    await db.insert("foobar", { id: "exact_id", thing: true });

Expected behaviour

Either behave the same way as the older versions where tables and string IDs can be parsed apart, or insert the record that is provided. If there's a third scenario where the SDK intends for developers to be able to create tables by theirselves and not insert a record, then throw an error when a developer provides the arguments in an inconsistent manner.

SurrealDB version

2.0.4 linux

JavaScript SDK version

1.0.6

Contact Details

[email protected]

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
@knackstedt knackstedt added the bug Something isn't working label Nov 11, 2024
@kearfy
Copy link
Member

kearfy commented Nov 20, 2024

Hey @knackstedt, these are all actually valid table names, as table names when escaped with backticks or mathematical brackets can contain any complex character.

In hindsight, we should have stopped accepting strings for these methods, and only accept instances of Table, RecordId, RecordIdString and RecordIdRange to make this change more transparent, but since we already stabilised 1.0.0 this change can no longer be made. The only alternative I think would be to do another major release, but I'm not sure if that's the best solution 😅

I'll have some more discussions about this internally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants