surrealdb / surrealdb.go

SurrealDB SDK for Golang
https://surrealdb.com
Apache License 2.0
232 stars 60 forks source link

feat(marshal): smartUnmarshalRaw1 to handle raw query single return result including THROW statement errors #120

Open agufagit opened 8 months ago

agufagit commented 8 months ago

current SmartUnmarshal only handles array return results, doesn't handle other return types such as create only user which returns an object.

the new SmartUnmarshalRaw1 only handles raw query, and only handles single return result: [map[result:true status:OK time:4.219606ms]]

This is required because of custom functions DEFINE FUNCTION fn::xxx and BEGIN;...COMMIT; block doesn't return arrays, and only returns single result.

it also handles THROW statement errors BEGIN; THROW 'blocked'; COMMIT; : [map[result:An error occurred: blocked status:ERR time:4.219606ms]]

this function should cover 99% of people's needs

tested against surrealdb v1.0.0

ElecTwix commented 8 months ago

Thanks for the PR @agufagit, I was working on my project and I faced similar problems with current driver. It can be good to add something like this as a helper function.

@phughk , @timpratim what do you think?