surrealdb / surrealdb.js

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

Bug: merge doesn't work (Just not documented) #292

Closed irishburlybear closed 1 week ago

irishburlybear commented 1 week ago

Describe the bug

beta.9 tried to update with merge. Nothing happens. I can see it in the debugger log, but no actual change happens.

Steps to reproduce

just simply update a record (svelte) locals.db.merge(id, data) nothing happens. No error either.

Expected behaviour

Updates the record.

SurrealDB version

1.5.3

SurrealDB.js version

beta.9

Contact Details

irishburlybear@gmail.com

Is there an existing issue for this?

Code of Conduct

kearfy commented 1 week ago

Hey @irishburlybear, I'm pretty sure that this is not an issue in the SDK but potentially rather with the data that you send over, or with schema/permissions configuration on your SurrealDB instance. Would you be able to share a bit more as to what you are trying to do, perhaps a reproducable example? Thanks!

irishburlybear commented 1 week ago

Ok, I figured it out after reading some hints here and there... Apparently, I have to import RecordId to make a thing:: so the new beta can update the record.

So it's a lack of documentation that caused my dementia meltdown. It's very off putting and confusing to do a merge(new RecordId('table', 'id'), data) It feels like I'm actually creating a new record ID, but I'm really not. I'm creating an instance of a record id to be sent as a thing::

irishburlybear commented 1 week ago

To update a record in beta9, (example coming from svelte):

import {RecordId} from 'surrealdb.js'

const employee = await locals.db.merge(new RecordId('employees', params.id), data);

//RecordId helps to construct a surrealdb record instead of doing string concat magic...
//This is actually easier to use, now because when I create an ACTUAL new record I can use ulid()

return employee
kearfy commented 1 week ago

That's correct! We have a Pull Request open in our documentation repository which we will be merging soon, and which will clarify this change: https://github.com/surrealdb/docs.surrealdb.com/pull/627