surrealdb / surrealdb.js

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

Bug: db.update() throws error if not all fields of records are specified #211

Closed OTheNonE closed 5 months ago

OTheNonE commented 5 months ago

Describe the bug

When trying to update a user by the .update() function, you have to specify all fields of the record in order to update the record, otherwise the function throws an error.

Steps to reproduce

I want to update the role of the following user:

{
    id: "user:7k0keh247arqv02pjfdw"
    username: "guest"
    password: "someVerySecurePassword"
    role: "guest"
}

I do this by using .update() as stated in the Docs:

let id = "user:7k0keh247arqv02pjfdw"
let user = { role: "admin" }
await db.update(id, user);

When doing this, i recieve the following error:

Error: There was a problem with the database: Found NONE for field `username`, with record `user:7k0keh247arqv02pjfdw`, but expected a string

Expected behaviour

I expect the function not to throw, but rather update only the fields specified in the user object.

SurrealDB version

surreal 1.1.1 for Windows

SurrealDB.js version

0.11.0

Contact Details

olavnon@gmail.com

Is there an existing issue for this?

Code of Conduct

Micnubinub commented 5 months ago

db.update expects all the fields to be available and overwrites the whole record. What you are looking for is db.merge

OTheNonE commented 5 months ago

Oh my, how did miss this? Yes, i am looking for db.merge, thank you.