+
    Ki   c                   s    ^ RI t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht / tRsRR ltR	 tR
 tR tR tR tRR ltR tR tR tR tR tR tR tR tR tR tR tR# )i    N)chain)settings)sql)logger)slugifyFc           	      sR    \         P                  ! \        P                  R WW#R7      # )gamesZsearchesfiltersZexcludesZsorts)r   Zfiltered_queryr   DB_PATHr   s   &&&&:/usr/lib/python3.14/site-packages/lutris/database/games.py	get_gamesr
      s%    'HPX     c                 sT   Rp. p. pV P                  4        EF  w  rEVP                  R4      vrFV'       Ed`   V^ ,          pVR8X  d2   VP                  RP                  V4      4       VP                  V4       VR8X  d+   TP                  RP                  YE'       d   RMR4      4       VR8X  d2   VP                  R	P                  V4      4       VP                  V4       VR
8X  d   \	        VR4      '       g   \        RV,          4      h\        V4      R8  d   \        R4      hV'       db   TP                  RP                  TRP                  R\        V4      ,          4      ;'       g    R4      4       \        \        W54      4      pEKz  EK}  EK  VP                  RP                  V4      4       VP                  V4       EK  	  RP                  V4      pV'       d   RP                  W34      pM. # \        P                  ! \        P                  V\        V4      4      # )a&  
Query games table based on conditions

Args:
    conditions (dict): named arguments with each field matches its desired value.
    Special values for field names can be used:
        <field>__lessthan will return rows where `field` is less than the value
        <field>__isnull will return rows where `field` is NULL if the value is True
        <field>__not will invert the condition using `!=` instead of `=`
        <field>__in will match rows for every value of `value`, which should be an iterable

Returns:
    list: Rows matching the query

zselect * from gamesZ__Zlessthanz{} < ?Zisnullz{} is {} nullZ Znotz{} != ?ZinZ__iter__z&Value should be an iterable (%s given)  z.SQLite limited to a maximum of 999 parameters.z
{} in ({})z, Z?z{} = ?z AND z WHERE )ZitemsZsplitZappendZformatZhasattr
ValueErrorlenZjoinlistr    r   Zdb_queryr   r   Ztuple)	Z
conditionsqueryZcondition_fieldsZcondition_valuesfieldvalueZextra_conditionsZextra_condition	conditions	   ,        r	   get_games_wherer      s     "E"((*#(;;t#4 .q1O*, ''(>? ''.(* ''(>(>uEbW\(]^%' ''	(8(8(?@ ''.$&uj11$%MPU%UVVu:#$%UVV$++L,?,?tyyQTWZ[`WaQaGbGhGhfh,ij'+E2B,J'K$  ' ##HOOE$:;##E*- +. -.I12 	<<((%7G1HIIr   c                 s   R p\        \        P                  ! \        \        P
                  ! \        V 4      V,          4      4       Uu. uF.  p\        \        V 4      W!,          W!,          V,            R7      NK0  	  up4      4      # u upi )r   )Zid__in)r   r    Zfrom_iterableZrangemathZceilr   r   )Zgame_idsZsizeZpage   &  r	   get_games_by_idsr   H   sw     D "$))CMD,@"ABBD  tH~dkDKRVDV'WXB	
 s   	4Bc                 sp    V R 8X  d   \        VRR7      # \        RVRV /R7      pV'       d
   V^ ,          # R# )lutrisslug)r   
service_idservicer   N)get_game_by_fieldr
   )r   ZappidZexisting_games   && r	   get_game_for_servicer   V   s=    ( f55eY'PQNa   r   c                 s    V R 8X  d(   \        R^/R7      pV Uu/ uF  q"R,          VbK  	  up# \        RV R^/R7      pV Uu/ uF  q"R,          VbK  	  up# u upi u upi )r   	installedr   r   r   r   )r
   )r   Zdb_gamesZgr   r	   "get_all_installed_game_for_servicer!   _   sm    (k1%56&./h&	1h//)Wk1!EFH(011lOQ11 0 2s   AAc                s   \         ;'       g    ^ p\        P                  ! 4       s V \        9  g   \         V,
          ^8  dm   V R8X  d9   \        RR/R7       Uu. uF  q"R,          NK  	  up\        V &   \        V ,          # \        RV RR/R7       Uu. uF  q"R,          NK  	  up\        V &   \        V ,          # u upi u upi )z4Return the list of all installed games for a servicer   r    Z1r   r   r   r   )_SERVICE_CACHE_ACCESSEDtime_SERVICE_CACHEr
   )r   Zprevious_cache_accessedgamer   r	   get_service_gamesr&   h   s     6::"iikn$(?BY(Y\](]h@IS^`cRd@e&f@eF||@e&fN7#
 '"" 09)WVacfAg/h'/ht\""/h'N7# '"" 'g's   B<Cc                s    VR9  d   \        RV,          4      h\        P                  ! \        P                  RW3R7      pV'       d
   V^ ,          # / # )z&Query a game based on a database fieldzCan't query by field '%s'r   r   )r   Zinstaller_slugid
configpathname)r   r   	db_selectr   r   )r   r   Zgame_resultr   r	   r   r   w   sH    JJ4u<==-- 0 0'e^TK1~Ir   c                T    \         P                  ! \        P                  RRV 3R7      # )z(Return all games using a specific runnerr   runnerr'   r   r+   r   r   )r-      &r	   get_games_by_runnerr0      s     ==))7x>PQQr   c                r,   )z&Return all games using a specific slugr   r   r'   r.   r   r/   r	   get_games_by_slugr2      s    ==))7vtnMMr   c                 s    \        \        P                  ! 4       4      V R&   RV 9  d   \        V R,          4      V R&   \        P                  ! \
        P                  RV 4      # )zAdd a game to the database.Zinstalled_atr   r*   r   )Zintr#   r   r   	db_insertr   r   )Z	game_datas   ,r	   add_gamer4      sL     #DIIK 0InY#If$56	&==))7I>>r   c                sx    V  Uu. uF)  p\         P                  ! \        P                  RV4      NK+  	  up# u upi )z
Add a list of games to the database.
The dicts must have an identical set of keys.

Args:
    games (list): list of games in dict format
Returns:
    list: List of inserted game ids
r   )r   r3   r   r   )r   r%   s   & r	   add_games_bulkr5      s1     HMMutCMM(**GT:uMMMs   /7c                 sB    \        R/ V B pV'       d   V# \        R/ V B # )zAdd a game to the database or update an existing one

If an 'id' is provided in the parameters then it
will try to match it, otherwise it will try matching
by slug, creating one when possible.
 )update_existingr4   paramsgame_id   , r	   add_or_updater<      s'     ''Gfr   c                 s    \        V 4      pV'       d0   WR&   \        P                  ! \        P                  RV RV/4       V# R# )zyUpdates a game, but do not add one. If the game exists, this returns its ID;
if not it returns None and makes no changes.r(   r   N)get_matching_gamer   Z	db_updater   r   r8   r;   r	   r7   r7      s<      'Gth&&$Ir   c                s|   V P                  R4      '       dC   \        V R,          R4      pV'       d
   VR,          # \        P                  ! RV R,          4       V P                  R4      ;'       g    \	        V P                  R4      4      pV'       g   \        R4      h\        V4       F  pVR,          '       d+   VR,          V P                  R4      8X  d   VR,          u # K<  VR,          V P                  R4      8X  g,   \        V P                  R4      VR,          .4      '       d   K  VR,          u # 	  R	# )
z5Tries to match given parameters with an existing gamer(   z+Game ID %s provided but couldn't be matchedr   r*   z)Can't add or update without an identifierr    r)   r-   N)Zgetr   r   Zwarningr   r   r2   Zall)r9   r%   r   r   r	   r=   r=      s     zz$ t4:DfTlS::f<<F);!<DDEE!$'L!VZZ%==Dz! > H~H!55S&**XBVX\]eXfAg=h=hDz! ( r   c                sT    \         P                  ! \        P                  RRV 4       R# )zDelete a game from the PGA.r   r(   N)r   Z	db_deleter   r   )r:   r/   r	   delete_gamer>      s    MM(""GT7;r   c                 4   \         P                  ! \        P                  4      ;_uu_ 4       p RpV P	                  V4      pVP                  4       pRRR4       X Uu. uF  qD^ ,          '       g   K  V^ ,          NK  	  up#   + '       g   i     L9; iu upi )z7Return a list of the runners in use by installed games.zJselect distinct runner from games where runner is not null order by runnerNr   Z	db_cursorr   r   ZexecuteZfetchallZcursorr   ZrowsZresultsZresult        r	   get_used_runnersrC      sn    	x''	(	(F\~~e$--/ 
) %,9G&ayyIF1IIG99	 
)	( :   $BB2BB	c                 r?   )z+Return a list of platforms currently in usezgselect distinct platform from games where platform is not null and platform is not '' order by platformNr@   rA   rB   r	   get_used_platformsrE      ss    	x''	(	(Fu 	 ~~e$--/ 
) %,9G&ayyIF1IIG99 
)	( :rD   c                 s    \         P                  ! \        P                  R RW3R7      pV'       d   V^ ,          R,          # R# )r   	COUNT(id))Zfieldsr   N)rF   r.   )Zparamr   Zresr   r	   get_game_countrG      s7    
--(('.UZTb
cC
1vk"" r   )NNNNr1   ) r   r#   Z	itertoolsr    r   r   Zlutris.databaser   Zlutris.util.logr   Zlutris.util.stringsr   r$   r"   r
   r   r   r   r!   r&   r   r0   r2   r4   r5   r<   r7   r=   r>   rC   rE   rG   r6   r   r	   <module>rH      s         " ' 1Jh!2#R
N
?
N*<
::#r   