Skip to content

Commit 3e7c202

Browse files
committed
Merge branch 'add-query'
* add-query: Fix distinct query paths in values
2 parents 463987c + 14c6dbf commit 3e7c202

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pathtraits/access.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ def get_paths_values(db, query_str):
9191
:param query_str: Description
9292
"""
9393
query_str = f"SELECT * FROM data where {query_str};"
94-
res = db.execute(query_str, ignore_error=False).fetchall()
94+
response = db.execute(query_str, ignore_error=False).fetchall()
95+
res = {}
96+
for r in response:
97+
path = r["path"]
98+
# ensure distinct paths
99+
if path not in res.keys():
100+
r = nest_dict(r)
101+
r.pop("path")
102+
res[path] = r
95103
return res
96104

97105

test/test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ def test_data_query(self):
8080
target = 1
8181
self.assertEqual(source, target)
8282

83-
source = len(pathtraits.access.get_paths(self.db, "TRUE"))
84-
target = 3
85-
self.assertEqual(source, target)
83+
traits = pathtraits.access.get_paths_values(self.db, "TRUE")
84+
self.assertEqual(len(traits), 3)
85+
for v in traits.values():
86+
self.assertTrue("path" not in v.keys())
8687

8788

8889
if __name__ == "__main__":

0 commit comments

Comments
 (0)