surrealdb / surrealdb.js

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

Feature: Implement toString and fromString for RecordId class #241

Closed vitorTheDev closed 2 months ago

vitorTheDev commented 3 months ago

Is your feature request related to a problem?

RecordId usage is pretty common in surrealdb, and casting from/to a string right now is not easy because toString gives [object Object], and to cast it from a string you need to split(':') table and id parts.

Describe the solution

It would be good if we could just do id.toString() because it's the default for JS and will be called automatically when you pass it as a string. In case of fromString, it would be good if we had a class method for casting a string with both parts as a record id e.g.

RecordId.fromString('table:id')
// or
new RecordId('table:id')

Alternative methods

NONE

SurrealDB version

1.4.2 for windows 11 x64

SurrealDB.js version

1.0.0-beta.4

Contact Details

netd777@gmail.com

Is there an existing issue for this?

Code of Conduct

vitorTheDev commented 2 months ago

Instead of this solution I went for another route: changing the entire app to use only the .id part of RecordId. It has solved my problems, but I still think .toString() should be more readable so we could console.log it.