Skip to content
Snippets Groups Projects
Commit a1ddfd31 authored by Heijden,T.A.J. van der (Thijs)'s avatar Heijden,T.A.J. van der (Thijs)
Browse files

Merge branch 'refactor-sprint-7' into 'main'

Refactor sprint 7

See merge request datastrophe/query-conversion!1
parents 06ff65cd 0a33817a
No related branches found
No related tags found
No related merge requests found
......@@ -15,29 +15,29 @@ ConvertQuery converts an IncomingQueryJSON object into AQL
func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, error) {
// Check to make sure all indexes exist
// How many entities are there
numEntities := len(JSONQuery.Entities) - 1
// How many relations there are
numRelations := len(JSONQuery.Relations) - 1
// The largest possible id for an entity
largestEntityID := len(JSONQuery.Entities) - 1
// The largest possible id for a relation
largestRelationID := len(JSONQuery.Relations) - 1
// Make sure no entity should be returned that is outside the range of that list
for _, e := range JSONQuery.Return.Entities {
// If this entity references an entity that is outside the range
if e > numEntities || e < 0 {
if e > largestEntityID || e < 0 {
return nil, errors.New("non-existing entity referenced in return")
}
}
// Make sure that no relation mentions a non-existing entity
for _, r := range JSONQuery.Relations {
if r.EntityFrom > numEntities || r.EntityTo > numEntities {
if r.EntityFrom > largestEntityID || r.EntityTo > largestEntityID {
return nil, errors.New("non-exisiting entity referenced in relation")
}
}
// Make sure no non-existing relation is tried to be returned
for _, r := range JSONQuery.Return.Relations {
if r > numRelations || r < 0 {
if r > largestRelationID || r < 0 {
return nil, errors.New("non-existing relation referenced in return")
}
}
......@@ -253,7 +253,7 @@ func createRelationLetWithFromEntity(relation *entity.QueryRelationStruct, name
// Add a WITH statement if the collection of entityTo is not yet included
if (*entities)[(*relation).EntityFrom].Type != (*entities)[(*relation).EntityTo].Type {
header = fmt.Sprintf("WITH %v\n %v", (*entities)[(*relation).EntityTo].Type, header)
header = fmt.Sprintf("%v\n\tWITH %v", header, (*entities)[(*relation).EntityTo].Type)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment