from typing import Iterable def sql_and(terms: Iterable[str], *, default: str = "TRUE") -> str: """Join a list of SQL statements together in an AND clause. Args: terms: a list of SQL strings to be combined default: SQL to be returned in the case where there are no terms Returns: String of SQL """ return f'({" AND ".join(f"({term})" for term in terms) or default})' def sql_or(terms: Iterable[str], *, default: str = "FALSE") -> str: """Join a list of SQL statements together in an OR clause. Args: terms: a list of SQL strings to be combined default: SQL to be returned in the case where there are no terms Returns: String of SQL """ return f'({" OR ".join(f"({term})" for term in terms) or default})'