Skip to content

Commit

Permalink
Serialisation was not working for queries which embedded dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinMendelGleason committed Nov 9, 2023
1 parent 0251f80 commit 089fb9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion terminusdb_client/woqlquery/woql_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# helper functions for WOQLCore
import re


def _split_at(op, tokens):
results = []
stack = []
Expand Down Expand Up @@ -156,6 +155,8 @@ def _copy_dict(orig, rollup=None):
query = _copy_dict(part, rollup)
if query:
nuj[key] = query
elif hasattr(part, 'to_dict'):
nuj[key] = part.to_dict()
else:
nuj[key] = part
return nuj
7 changes: 7 additions & 0 deletions terminusdb_client/woqlquery/woql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def __init__(self, name):
def __str__(self):
return self.name

def to_dict(self):
return {"@type": "Value",
"variable": self.name}

class Doc:
def __init__(self, dictionary):
Expand All @@ -58,6 +61,9 @@ def __init__(self, dictionary):
def __str__(self):
return str(self.dictionary)

def to_dict(self):
return self.encoded

def _convert(self, obj):
if type(obj) is str:
return {"@type": "Value", "data": {"@type": "xsd:string", "@value": obj}}
Expand Down Expand Up @@ -584,6 +590,7 @@ def _json(self, input_json=None):
self.from_dict(json.loads(input_json))
return self
else:
print(self.to_dict())
return json.dumps(self.to_dict(), sort_keys=True)

def to_dict(self):
Expand Down

0 comments on commit 089fb9e

Please sign in to comment.