Skip to content
Snippets Groups Projects
Commit 88d014fb authored by thijsheijden's avatar thijsheijden
Browse files

Moved query structs into entity layer

parent 8fc180ff
No related branches found
No related tags found
No related merge requests found
package entity
// QueryParsedJSON is used for JSON conversion of the incoming byte array
type QueryParsedJSON struct {
Return QueryReturnStruct
Entities []QueryEntityStruct
Relations []QueryRelationStruct
// Limit is for limiting the amount of paths AQL will return in a relation let statement
Limit int
}
// QueryReturnStruct holds the indices of the entities and relations that need to be returned
type QueryReturnStruct struct {
Entities []int
Relations []int
}
// QueryEntityStruct encapsulates a single entity with its corresponding constraints
type QueryEntityStruct struct {
Type string
Constraints []QueryConstraintStruct
}
// QueryRelationStruct encapsulates a single relation with its corresponding constraints
type QueryRelationStruct struct {
Type string
EntityFrom int
EntityTo int
Depth QuerySearchDepthStruct
Constraints []QueryConstraintStruct
}
// QuerySearchDepthStruct holds the range of traversals for the relation
type QuerySearchDepthStruct struct {
Min int
Max int
}
/*
QueryConstraintStruct holds the information of the constraint
Constraint datatypes
text MatchTypes: exact/contains/startswith/endswith
number MatchTypes: GT/LT/EQ
bool MatchTypes: EQ/NEQ
*/
type QueryConstraintStruct struct {
Attribute string
Value string
DataType string
MatchType string
}
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"query-service/internal/entity"
)
/*
......@@ -57,8 +58,8 @@ Parameters: jsonMsg is the JSON file directly outputted by the drag and drop que
Return: parsedJSON is a struct with the same structure and holding the same data as jsonMsg
*/
func convertJSONToStruct(jsonMsg *[]byte) (*parsedJSON, error) {
jsonStruct := parsedJSON{}
func convertJSONToStruct(jsonMsg *[]byte) (*entity.QueryParsedJSON, error) {
jsonStruct := entity.QueryParsedJSON{}
err := json.Unmarshal(*jsonMsg, &jsonStruct)
if err != nil {
......@@ -73,7 +74,7 @@ Parameters: jsonQuery is a parsedJSON struct holding all the data needed to form
Return: a string containing the corresponding AQL query and an error
*/
func createQuery(jsonQuery *parsedJSON) *string {
func createQuery(jsonQuery *entity.QueryParsedJSON) *string {
// GROTE SIDENOTE:
// Vrij zeker dat een query waar alléén edges worden opgevraagd (#4)
// niet wordt gesupport door zowel de result parser als de frontend receiver
......@@ -172,7 +173,7 @@ name is the autogenerated name of the node consisting of "n" + the index of the
Return: a string containing a single LET-statement in AQL
*/
func createNodeLet(node *entityStruct, name *string) *string {
func createNodeLet(node *entity.QueryEntityStruct, name *string) *string {
header := fmt.Sprintf("LET %v = (\n\tFOR x IN %v \n", *name, node.Type)
footer := "\tRETURN x\n)\n"
constraints := *createConstraintStatements(&node.Constraints, "x", false)
......@@ -188,7 +189,7 @@ entities is a list of entityStructs that are needed to form the relation LET-sta
Return: a string containing a single LET-statement in AQL
*/
func createRelationLetWithFromEntity(relation *relationStruct, name string, entities *[]entityStruct, limit int) *string {
func createRelationLetWithFromEntity(relation *entity.QueryRelationStruct, name string, entities *[]entity.QueryEntityStruct, limit int) *string {
header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityFrom)
forStatement := fmt.Sprintf("\tFOR v, e, p IN %v..%v OUTBOUND x %s \n", relation.Depth.Min, relation.Depth.Max, relation.Type)
......@@ -222,7 +223,7 @@ entities is a list of entityStructs that are needed to form the relation LET-sta
Return: a string containing a single LET-statement in AQL
*/
func createRelationLetWithOnlyToEntity(relation *relationStruct, name string, entities *[]entityStruct, limit int) *string {
func createRelationLetWithOnlyToEntity(relation *entity.QueryRelationStruct, name string, entities *[]entity.QueryEntityStruct, limit int) *string {
header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityTo)
forStatement := fmt.Sprintf("\tFOR v, e, p IN %v..%v INBOUND x %s \n", relation.Depth.Min, relation.Depth.Max, relation.Type)
......
......@@ -8,55 +8,3 @@ type Service struct {
func NewService() *Service {
return &Service{}
}
// Struct used for JSON conversion of the incoming byte array
type parsedJSON struct {
Return returnStruct
Entities []entityStruct
Relations []relationStruct
// Limit is for limiting the amount of paths AQL will return in a relation let statement
Limit int
}
// returnStruct holds the indices of the entities and relations that need to be returned
type returnStruct struct {
Entities []int
Relations []int
}
// entityStruct encapsulates a single entity with its corresponding constraints
type entityStruct struct {
Type string
Constraints []constraintStruct
}
// relationStruct encapsulates a single relation with its corresponding constraints
type relationStruct struct {
Type string
EntityFrom int
EntityTo int
Depth searchDepthStruct
Constraints []constraintStruct
}
// searchDepthStruct holds the range of traversals for the relation
type searchDepthStruct struct {
Min int
Max int
}
/*
constraintStruct holds the information of the constraint
Constraint datatypes
text MatchTypes: exact/contains/startswith/endswith
number MatchTypes: GT/LT/EQ
bool MatchTypes: EQ/NEQ
*/
type constraintStruct struct {
Attribute string
Value string
DataType string
MatchType string
}
package convertquery
import "fmt"
import (
"fmt"
"query-service/internal/entity"
)
/* createConstraintStatements generates the appropriate amount of constraint lines calling createConstraingBoolExpression
Parameters: constraints is a list of constraintStructs that specify the constraints of a node or relation,
......@@ -9,7 +12,7 @@ isRelation is a boolean specifying if this constraint comes from a node or relat
Return: a string containing a FILTER-statement with all the constraints
*/
func createConstraintStatements(constraints *[]constraintStruct, name string, isRelation bool) *string {
func createConstraintStatements(constraints *[]entity.QueryConstraintStruct, name string, isRelation bool) *string {
s := ""
if len(*constraints) == 0 {
return &s
......@@ -34,7 +37,7 @@ isRelation is a boolean specifying if this constraint comes from a node or relat
Return: a string containing an boolean expression of a single constraint
*/
func createConstraintBoolExpression(constraint *constraintStruct, name string, isRelation bool) *string {
func createConstraintBoolExpression(constraint *entity.QueryConstraintStruct, name string, isRelation bool) *string {
var (
match string
value string
......
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