Skip to content

Commit

Permalink
fix query result type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
TanmoySG committed May 14, 2024
1 parent 2ad9a8f commit acf98fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/TanmoySG/wunderDB/pkg/schema"
"github.com/TanmoySG/wunderDB/pkg/utils/maps"
er "github.com/TanmoySG/wunderDB/pkg/wdb/errors"
wdbErrors "github.com/TanmoySG/wunderDB/pkg/wdb/errors"
"github.com/spyzhov/ajson"
)

Expand Down Expand Up @@ -171,9 +172,16 @@ func (d Data) Query(query string, mode QueryType) (interface{}, *er.WdbError) {
for _, node := range queryResultNodes {
marshaledNode, err := ajson.Marshal(node)
if err != nil {
return nil, nil
return nil, &wdbErrors.QueryResultProcessingError
}
queryResults = append(queryResults, string(marshaledNode))

var result interface{}
err = json.Unmarshal(marshaledNode, &result)
if err != nil {
return nil, &wdbErrors.QueryResultProcessingError
}

queryResults = append(queryResults, result)
}

return queryResults, nil
Expand Down
6 changes: 6 additions & 0 deletions pkg/wdb/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ var (
HttpStatusCode: 400,
}

QueryResultProcessingError = WdbError{
ErrCode: "queryResultProcessingError",
ErrMessage: "json path result processing failed",
HttpStatusCode: 400,
}

// Safe Name Error
CollectionNameFormatError = WdbError{
ErrCode: "entityNameFormatError",
Expand Down

0 comments on commit acf98fe

Please sign in to comment.