Skip to content

Commit

Permalink
Updated db.py to comply to sqlalchemy 1.4, switched table.count() wit…
Browse files Browse the repository at this point in the history
…h func.count()
  • Loading branch information
flochir authored and cydanil committed May 16, 2022
1 parent 966cc85 commit 0d23126
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/gourmand/backends/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import sqlalchemy.orm
from gi.repository import Gtk
from sqlalchemy import (Boolean, Column, Float, ForeignKey, Integer,
LargeBinary, Numeric, String, Table, Text, event, func)
LargeBinary, Numeric, String, Table, Text,
event, func, select)
from sqlalchemy.sql import and_, case, or_

import gourmand.__version__
Expand Down Expand Up @@ -741,9 +742,16 @@ def fetch_len (self, table, **criteria):
"""Return the number of rows in table that match criteria
"""
if criteria:
return table.count(*make_simple_select_arg(criteria,table)).execute().fetchone()[0]
else:
return table.count().execute().fetchone()[0]
return select(
[func.count(list(table.primary_key.columns)[0])])\
.where(*make_simple_select_arg(criteria,table))\
.execute()\
.fetchone()[0]

return select(
[func.count(list(table.primary_key.columns)[0])])\
.execute()\
.fetchone()[0]

def fetch_join (self, table1, table2, col1, col2,
column_names=None, sort_by=None, **criteria):
Expand Down

0 comments on commit 0d23126

Please sign in to comment.