@@ -177,12 +177,12 @@ def missing_outputs(self, query: Query, predict_id: str) -> t.List[str]:
177177 :param predict_id: The predict id.
178178 """
179179
180- @abstractmethod
181- def primary_id (self , query : Query ) -> str :
182- """Get the primary id of a query.
180+ def primary_id (self , table : str ) -> str :
181+ """Get the primary id of a table.
183182
184- :param query : The query to get the primary id of.
183+ :param table : The table to get the primary id of.
185184 """
185+ return self .db .metadata .get_primary_id (table )
186186
187187 @abstractmethod
188188 def select (self , query : Query ) -> t .List [t .Dict ]:
@@ -222,7 +222,7 @@ def get(self, query: Query, raw: bool = False):
222222 return None
223223
224224 def _wrap_results (self , query : Query , result , schema , raw : bool = False ):
225- pid = self .primary_id (query )
225+ pid = self .primary_id (query . table )
226226 for r in result :
227227 if pid in r :
228228 r [pid ] = str (r [pid ])
@@ -326,7 +326,7 @@ def pre_like(self, query: Query, **kwargs):
326326
327327 results = new .execute (** kwargs )
328328
329- pid = self .primary_id (query )
329+ pid = self .primary_id (query . table )
330330 for r in results :
331331 r ['score' ] = lookup [r [pid ]]
332332
@@ -356,7 +356,7 @@ def post_like(self, query: Query, **kwargs):
356356
357357 results = prepare_query .filter (t .primary_id .isin (ids )).execute (** kwargs )
358358
359- pid = self .primary_id (query )
359+ pid = self .primary_id (query . table )
360360
361361 for r in results :
362362 r ['score' ] = lookup [r [pid ]]
@@ -484,7 +484,7 @@ def delete(self, table, condition):
484484 r_table = self ._get_with_component_identifier ('Table' , table )
485485
486486 if not r_table ['is_component' ]:
487- pid = r_table [ ' primary_id' ]
487+ pid = self . primary_id ( table )
488488 if pid in condition :
489489 docs = self .get_many (table , condition [pid ])
490490 else :
@@ -571,7 +571,7 @@ def replace(self, table, condition, r):
571571 r_table = self ._get_with_component_identifier ('Table' , table )
572572
573573 if not r_table ['is_component' ]:
574- pid = r_table [ ' primary_id' ]
574+ pid = self . primary_id ( table )
575575 docs = self .get_many (table , condition [pid ])
576576 docs = self ._do_filter (docs , condition )
577577 for s in docs :
@@ -603,7 +603,7 @@ def update(self, table, condition, key, value):
603603 r_table = self ._get_with_component_identifier ('Table' , table )
604604
605605 if not r_table ['is_component' ]:
606- pid = r_table [ ' primary_id' ]
606+ pid = self . primary_id ( table )
607607 docs = self .get_many (table , condition [pid ])
608608 docs = self ._do_filter (docs , condition )
609609 for s in docs :
@@ -695,20 +695,6 @@ def _get_with_component_identifier_version(
695695 def __delitem__ (self , key : t .Tuple [str , str , str ]):
696696 pass
697697
698- def primary_id (self , query ):
699- """Get the primary id of a query.
700-
701- :param query: The query to get the primary id of.
702- """
703- r = max (
704- self .get_many ('Table' , query .table , '*' ),
705- key = lambda x : x ['version' ],
706- default = None ,
707- )
708- if r is None :
709- raise exceptions .NotFound ("Table" , query .table )
710- return r ['primary_id' ]
711-
712698 def insert (self , table , documents ):
713699 """Insert data into the database.
714700
@@ -717,7 +703,7 @@ def insert(self, table, documents):
717703 """
718704 ids = []
719705 try :
720- pid = self .primary_id (self . db [ table ] )
706+ pid = self .primary_id (table )
721707 except exceptions .NotFound :
722708 pid = None
723709
@@ -726,7 +712,7 @@ def insert(self, table, documents):
726712 self [table , r ['identifier' ], r ['uuid' ]] = r
727713 ids .append (r ['uuid' ])
728714 elif pid :
729- pid = self .primary_id (self . db [ table ] )
715+ pid = self .primary_id (table )
730716 for r in documents :
731717 if pid not in r :
732718 r [pid ] = self .random_id ()
@@ -790,7 +776,7 @@ def do_test(r):
790776 is_component = max (tables , key = lambda x : x ['version' ])['is_component' ]
791777
792778 if not is_component :
793- pid = self .primary_id (query )
779+ pid = self .primary_id (query . table )
794780 if pid in filter_kwargs :
795781 keys = self .keys (query .table , filter_kwargs [pid ]['value' ])
796782 del filter_kwargs [pid ]
0 commit comments