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

Getting Parsing Error When Use Fetch with map[string]interface #40

Closed
ElecTwix opened this issue Mar 4, 2023 · 10 comments · Fixed by #115
Closed

Getting Parsing Error When Use Fetch with map[string]interface #40

ElecTwix opened this issue Mar 4, 2023 · 10 comments · Fixed by #115
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ElecTwix
Copy link
Contributor

ElecTwix commented Mar 4, 2023

Hi Everyone,

I was selecting the record and fetching it is the field record link with the fetch keyword
but when I try to use it with the parameter it gives
There was a problem with the database: Parse error when parsing 'fetch $fetchstr'
this error I checkout the source code this line JSON Marshaling giving the error.
Also, I tried with not safe method string merge ( fmt.sprintf ) and added my string at the end it worked that way.

Am I doing something wrong?
if that's the case please let me know.

The Code I'm trying to fetch

res, err := db.Globaldb.Query("select * from $table fetch $fetchstr;", map[string]interface{}{
	"table":  ID,
	"fetchstr": fetchstr,
})

UPDATE:

for clear out

The problem I was facing was:

After the FETCH statement, arguments are no longer parsed.

Example:

select * from $table FETCH $fetchstr;
$table will parse but $fetchstr will not parse

@phughk phughk added good first issue Good for newcomers help wanted Extra attention is needed labels Jul 21, 2023
@phughk
Copy link
Contributor

phughk commented Jul 21, 2023

Thanks! We will add a test for this.

@sbshah97
Copy link
Contributor

sbshah97 commented Sep 15, 2023

Can I take this up as discussed in Discord? Here's how I am looking to do this.

Step 1: Write a test in db_test.go for fetch to ensure fetch works properly.
Step 2: Replicate this particular error in the test case to see if it's currently working
Step 3: Based on Step 2, decide if we need a fix or this is already done and push the test case for fetch as it is.

@phughk
Copy link
Contributor

phughk commented Sep 18, 2023

Yes please @sbshah97 ! That is exactly what is needed

@sbshah97
Copy link
Contributor

Hi had some work, picking this back up

@ElecTwix
Copy link
Contributor Author

Sorry for delay here to way to reproduce

func (s *SurrealDBTestSuite) TestFetch() {
	userSlice := []testUser{
		{Username: "arthur", Personal: PersonalInfo{Name: "arthur", Surname: "morgan"}, Password: "deer", Friends: []string{"users:john"}},
	}

	for _, v := range userSlice {
		data, err := s.db.Create(v.ID, v)
		s.NoError(err)
		s.NotNil(data)
	}

	for _, v := range userSlice {
		res, err := s.db.Query("select * from $table fetch $fetchstr;", map[string]interface{}{
			"record":   v.ID,
			"fetchstr": "friends.*",
		})
		// it will throw err
		fmt.Println(res, err)
		s.NoError(err)
		s.NotNil(res)
	}
}

ElecTwix@6af3184#diff-842765a20a0a937a8eb5267b53fb11b7493cc6c2a6a8871e1da2b684702c5bc9R502

db_test.go:503: 
Error Trace:	/home/electwix/dev/go/surrealdb.go/db_test.go:503
Error:      	Received unexpected error:
sending request failed for method 'query': There was a problem with the database: Parse error: Failed to parse query at line 1 column 28 expected a idiom
1 | select * from $table fetch $fetchstr;
Test:       	TestSurrealDBSuite/gorilla/TestFetch

to reproduce

just clone the repo and run go test -v

@sbshah97
Copy link
Contributor

What is v.ID over here?

@ElecTwix
Copy link
Contributor Author

ElecTwix commented Nov 26, 2023

What is v.ID over here?

came from testUser's ID on db_test.go

Update: It was my bad updated commit with ElecTwix@fde06eb

@sbshah97
Copy link
Contributor

From the looks of it issue here seems to be not being able to parse the fetch string. Just want to confirm if we are seeing this in other drivers or not ?

cc: @timpratim @phughk ?

If not probably will dive again in on this but from what I could see adding fmt statements till the end of the call stack, the query is being sent as correctly as possible.

@ElecTwix
Copy link
Contributor Author

After reproducing the issue with SurrealQL,
I created an issue on the SurrealDB repo: surrealdb/surrealdb#3028

@phughk
Copy link
Contributor

phughk commented Nov 27, 2023

Thanks @ElecTwix and @sbshah97 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants