Skip to content

Commit 0b2017f

Browse files
committed
sql orm
Signed-off-by: Saurabh Misra <[email protected]>
1 parent 730689b commit 0b2017f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

codeflash/after_db.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def get_authors(session):
2+
query = session.query(Author).join(Book).distinct(Author.id).order_by(Author.id)
3+
return query.all()

codeflash/before_db.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def get_authors(session):
2+
books = session.query(Book).all()
3+
_authors = []
4+
for book in books:
5+
_authors.append(book.author)
6+
return sorted(list(set(_authors)), key=lambda x: x.id)

0 commit comments

Comments
 (0)