Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #330 from multinet-app/fix_count_query
Browse files Browse the repository at this point in the history
Update length query and remove duplicate code
  • Loading branch information
jjnesbitt committed Mar 2, 2020
2 parents 54dda8d + f09c880 commit 6d7071b
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions multinet/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,8 @@ def workspace_table(workspace: str, table: str, offset: int, limit: int) -> dict
"""Return a specific table named `name` in workspace `workspace`."""
get_table_collection(workspace, table)

query = f"""
FOR d in {table}
LIMIT {offset}, {limit}
RETURN d
"""

count = workspace_table_row_count(workspace, table)
rows = aql_query(workspace, query)
rows = workspace_table_rows(workspace, table, offset, limit)

return {"count": count, "rows": list(rows)}

Expand All @@ -185,9 +179,7 @@ def workspace_table_rows(
def workspace_table_row_count(workspace: str, table: str) -> int:
"""Return the number of rows in a table."""
count_query = f"""
FOR d in {table}
COLLECT WITH COUNT INTO count
return count
RETURN LENGTH({table})
"""
return next(aql_query(workspace, count_query))

Expand Down

0 comments on commit 6d7071b

Please sign in to comment.