Skip to content

Commit

Permalink
Adds naïve get_all implementation for GenericDAO
Browse files Browse the repository at this point in the history
  • Loading branch information
duck-nukem committed Nov 4, 2021
1 parent 426ab49 commit 232c69e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions providers/databases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def get_one(self, **kwargs):

return result

def get_all(self, page_size: int = 10, page_number: int = 1):
with connect() as db:
query = select(self.db_model_class) \
.limit(page_size) \
.offset(page_number * page_size)
results = db.execute(query).fetchall()

return [r._data[0] for r in results]

def update(self, primary_key: int, values: Dict):
with connect() as db:
statement = update(self.db_model_class) \
Expand Down
5 changes: 4 additions & 1 deletion providers/repositories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Dict
from typing import Dict, List

from providers.databases import GenericDAO

Expand All @@ -16,6 +16,9 @@ def create(self, domain_entity):
def get(self, primary_key: int):
return self.from_db(self.dao.get_one(id=primary_key))

def list(self) -> List:
return [self.from_db(entity) for entity in self.dao.get_all()]

def update(self, domain_entity, updated_data: Dict):
self.dao.update(domain_entity.id, updated_data)

Expand Down

0 comments on commit 232c69e

Please sign in to comment.