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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

agufagit
Copy link

@agufagit agufagit commented Jan 1, 2024

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
Copy link
Contributor

ElecTwix commented Jan 4, 2024

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?

Copy link
Contributor

@ElecTwix ElecTwix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall,
did some nitpicks.

db_test.go Show resolved Hide resolved
db_test.go Show resolved Hide resolved
db_test.go Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
pkg/marshal/marshal.go Outdated Show resolved Hide resolved
…esult including THROW statement errors.

test: fix typo user to users
Copy link
Contributor

@phughk phughk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are very likely to change direction with the API. Until then, approving this, but please consider that it might not live long as available functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants