Skip to content

Commit

Permalink
feat: implements RawlBase.count()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz committed Sep 27, 2023
1 parent 3ce74fa commit 6f8e131
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rawl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ def all(self) -> List[RawlResult]:

return self.select("SELECT {0} FROM " + self.table + ";", self.columns)

def count(self) -> int:
"""
Get a count of all records in the table.
:returns: List of results
"""

return self.query("SELECT COUNT(*) FROM " + self.table + ";")[0][0]

def start_transaction(self) -> Connection[Any]:
"""
Initiate a connection to use as a transaction
Expand Down
8 changes: 8 additions & 0 deletions tests/test_rawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def delete_rawl_without_commit(self, rawl_id: int) -> List[RawlResult]:


class TestRawl(object):
@pytest.mark.dependency()
def test_count(self, pgdb: Connection[Any]) -> None:
"""Test out count() statement"""

mod = TheModel(RAWL_DSN)

assert mod.count() == 4

@pytest.mark.dependency()
def test_all(self, pgdb: Connection[Any]) -> None:
"""Test out a basic SELECT statement"""
Expand Down

0 comments on commit 6f8e131

Please sign in to comment.