Call scalars() from session rather than row results
This commit is contained in:
parent
858c86d907
commit
37cdaf3e3f
@ -123,7 +123,7 @@ class NoteColours(Base):
|
|||||||
Return all records
|
Return all records
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return session.execute(select(cls)).scalars().all()
|
return session.scalars(select(cls)).all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_colour(session: scoped_session, text: str) -> Optional[str]:
|
def get_colour(session: scoped_session, text: str) -> Optional[str]:
|
||||||
@ -135,12 +135,11 @@ class NoteColours(Base):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
for rec in (
|
for rec in (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(NoteColours)
|
select(NoteColours)
|
||||||
.filter(NoteColours.enabled.is_(True))
|
.filter(NoteColours.enabled.is_(True))
|
||||||
.order_by(NoteColours.order)
|
.order_by(NoteColours.order)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
):
|
):
|
||||||
if rec.is_regex:
|
if rec.is_regex:
|
||||||
@ -204,12 +203,11 @@ class Playdates(Base):
|
|||||||
"""Return a list of Playdates objects since passed time"""
|
"""Return a list of Playdates objects since passed time"""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(Playdates)
|
select(Playdates)
|
||||||
.where(Playdates.lastplayed >= since)
|
.where(Playdates.lastplayed >= since)
|
||||||
.order_by(Playdates.lastplayed)
|
.order_by(Playdates.lastplayed)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -288,12 +286,11 @@ class Playlists(Base):
|
|||||||
"""Returns a list of all playlists ordered by last use"""
|
"""Returns a list of all playlists ordered by last use"""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
.filter(cls.is_template.is_(False))
|
.filter(cls.is_template.is_(False))
|
||||||
.order_by(cls.tab.desc(), cls.last_used.desc())
|
.order_by(cls.tab.desc(), cls.last_used.desc())
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -302,10 +299,9 @@ class Playlists(Base):
|
|||||||
"""Returns a list of all templates ordered by name"""
|
"""Returns a list of all templates ordered by name"""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls).filter(cls.is_template.is_(True)).order_by(cls.name)
|
select(cls).filter(cls.is_template.is_(True)).order_by(cls.name)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -314,7 +310,7 @@ class Playlists(Base):
|
|||||||
"""Returns a list of all closed playlists ordered by last use"""
|
"""Returns a list of all closed playlists ordered by last use"""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
.filter(
|
.filter(
|
||||||
cls.tab.is_(None),
|
cls.tab.is_(None),
|
||||||
@ -323,7 +319,6 @@ class Playlists(Base):
|
|||||||
)
|
)
|
||||||
.order_by(cls.last_used.desc())
|
.order_by(cls.last_used.desc())
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -334,8 +329,7 @@ class Playlists(Base):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
session.execute(select(cls).where(cls.tab.is_not(None)).order_by(cls.tab))
|
session.scalars(select(cls).where(cls.tab.is_not(None)).order_by(cls.tab))
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -440,10 +434,9 @@ class PlaylistRows(Base):
|
|||||||
"""Copy playlist entries"""
|
"""Copy playlist entries"""
|
||||||
|
|
||||||
src_rows = (
|
src_rows = (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(PlaylistRows).filter(PlaylistRows.playlist_id == src_id)
|
select(PlaylistRows).filter(PlaylistRows.playlist_id == src_id)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -520,12 +513,11 @@ class PlaylistRows(Base):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(PlaylistRows)
|
select(PlaylistRows)
|
||||||
.where(PlaylistRows.playlist_id == playlist_id)
|
.where(PlaylistRows.playlist_id == playlist_id)
|
||||||
.order_by(PlaylistRows.plr_rownum)
|
.order_by(PlaylistRows.plr_rownum)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -545,12 +537,11 @@ class PlaylistRows(Base):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
.where(cls.playlist_id == playlist_id, cls.id.in_(plr_ids))
|
.where(cls.playlist_id == playlist_id, cls.id.in_(plr_ids))
|
||||||
.order_by(cls.plr_rownum)
|
.order_by(cls.plr_rownum)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -591,12 +582,11 @@ class PlaylistRows(Base):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
.where(cls.playlist_id == playlist_id, cls.played.is_(True))
|
.where(cls.playlist_id == playlist_id, cls.played.is_(True))
|
||||||
.order_by(cls.plr_rownum)
|
.order_by(cls.plr_rownum)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -623,7 +613,7 @@ class PlaylistRows(Base):
|
|||||||
if to_row is not None:
|
if to_row is not None:
|
||||||
query = query.where(cls.plr_rownum <= to_row)
|
query = query.where(cls.plr_rownum <= to_row)
|
||||||
|
|
||||||
plrs = session.execute((query).order_by(cls.plr_rownum)).scalars().all()
|
plrs = session.scalars((query).order_by(cls.plr_rownum)).all()
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
|
|
||||||
@ -637,7 +627,7 @@ class PlaylistRows(Base):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
plrs = (
|
plrs = (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
.where(
|
.where(
|
||||||
cls.playlist_id == playlist_id,
|
cls.playlist_id == playlist_id,
|
||||||
@ -646,7 +636,6 @@ class PlaylistRows(Base):
|
|||||||
)
|
)
|
||||||
.order_by(cls.plr_rownum)
|
.order_by(cls.plr_rownum)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -702,7 +691,7 @@ class Settings(Base):
|
|||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
settings = session.execute(select(cls)).scalars().all()
|
settings = session.scalars(select(cls)).all()
|
||||||
for setting in settings:
|
for setting in settings:
|
||||||
result[setting.name] = setting
|
result[setting.name] = setting
|
||||||
|
|
||||||
@ -789,7 +778,7 @@ class Tracks(Base):
|
|||||||
def get_all(cls, session) -> List["Tracks"]:
|
def get_all(cls, session) -> List["Tracks"]:
|
||||||
"""Return a list of all tracks"""
|
"""Return a list of all tracks"""
|
||||||
|
|
||||||
return session.execute(select(cls)).scalars().unique().all()
|
return session.scalars(select(cls)).unique().all()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_path(cls, session: scoped_session, path: str) -> Optional["Tracks"]:
|
def get_by_path(cls, session: scoped_session, path: str) -> Optional["Tracks"]:
|
||||||
@ -817,13 +806,12 @@ class Tracks(Base):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
.options(joinedload(Tracks.playdates))
|
.options(joinedload(Tracks.playdates))
|
||||||
.where(cls.artist.ilike(f"%{text}%"))
|
.where(cls.artist.ilike(f"%{text}%"))
|
||||||
.order_by(cls.title)
|
.order_by(cls.title)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.unique()
|
.unique()
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
@ -838,13 +826,12 @@ class Tracks(Base):
|
|||||||
https://docs.sqlalchemy.org/en/20/orm/queryguide/relationships.html#joined-eager-loading
|
https://docs.sqlalchemy.org/en/20/orm/queryguide/relationships.html#joined-eager-loading
|
||||||
"""
|
"""
|
||||||
return (
|
return (
|
||||||
session.execute(
|
session.scalars(
|
||||||
select(cls)
|
select(cls)
|
||||||
.options(joinedload(Tracks.playdates))
|
.options(joinedload(Tracks.playdates))
|
||||||
.where(cls.title.like(f"{text}%"))
|
.where(cls.title.like(f"{text}%"))
|
||||||
.order_by(cls.title)
|
.order_by(cls.title)
|
||||||
)
|
)
|
||||||
.scalars()
|
|
||||||
.unique()
|
.unique()
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user