def count_equal(cls, transaction: Optional[ spanner_transaction.Transaction] = None, **constraints: Any) -> int: """Returns the number of objects in Spanner that match the given conditions. Convenience method that generates equality conditions based on the keyword arguments. Args: transaction: The existing transaction to use, or None to start a new transaction **constraints: Each key/value pair is turned into an equality condition: the key is used as the column in the condition and the value is used as the value to compare the column against in the query. Returns: The integer result of the COUNT query """ conditions = [] for column, value in constraints.items(): if isinstance(value, list): conditions.append(condition.in_list(column, value)) else: conditions.append(condition.equal_to(column, value)) return cls.count(transaction, *conditions)
def where_equal( cls, transaction: Optional[spanner_transaction.Transaction] = None, **constraints: Any ) -> List["ModelObject"]: """Retrieves objects from Spanner based on the provided constraints. Args: transaction: The existing transaction to use, or None to start a new transaction **constraints: Each key/value pair is turned into an equality condition: the key is used as the column in the condition and the value is used as the value to compare the column against in the query. Returns: A list containing all requested objects that exist in the table (can be an empty list) """ conditions = [] for column, value in constraints.items(): if isinstance(value, list): conditions.append(condition.in_list(column, value)) else: conditions.append(condition.equal_to(column, value)) return cls.where(transaction, *conditions)