def where(self, criterion: Criterion) -> "PostgreQueryBuilder": with copy_if_immutable(self) as this: if not this._on_conflict: return super(PostgreQueryBuilder, this).where(criterion) if isinstance(criterion, EmptyCriterion): return this if this._on_conflict_do_nothing: raise QueryException('DO NOTHING doest not support WHERE') if this._on_conflict_fields and this._on_conflict_do_updates: if this._on_conflict_do_update_wheres: this._on_conflict_do_update_wheres &= criterion else: this._on_conflict_do_update_wheres = criterion elif this._on_conflict_fields: if this._on_conflict_wheres: this._on_conflict_wheres &= criterion else: this._on_conflict_wheres = criterion else: raise QueryException( 'Can not have fieldless ON CONFLICT WHERE') return this
def on_duplicate_key_ignore(self) -> "MySQLQueryBuilder": with copy_if_immutable(self) as this: if this._duplicate_updates: raise QueryException("Can not have two conflict handlers") this._ignore_duplicates = True return this
def distinct_on(self, *fields: Union[str, Term]) -> "PostgreQueryBuilder": with copy_if_immutable(self) as this: for field in fields: if isinstance(field, str): this._distinct_on.append(Field(field)) elif isinstance(field, Term): this._distinct_on.append(field) return this
def preserve_rows(self) -> "VerticaCreateQueryBuilder": with copy_if_immutable(self) as this: if not this._temporary: raise AttributeError( "'Query' object has no attribute temporary") this._preserve_rows = True return this
def on_duplicate_key_update(self, field: Union[Field, str], value: Any) -> "MySQLQueryBuilder": with copy_if_immutable(self) as this: if this._ignore_duplicates: raise QueryException("Can not have two conflict handlers") field = Field(field) if not isinstance(field, Field) else field this._duplicate_updates.append((field, ValueWrapper(value))) return this
def modifier(self, value: str) -> "MySQLQueryBuilder": """ Adds a modifier such as SQL_CALC_FOUND_ROWS to the query. https://dev.mysql.com/doc/refman/5.7/en/select.html :param value: The modifier value e.g. SQL_CALC_FOUND_ROWS """ with copy_if_immutable(self) as this: this._modifiers.append(value) return this
def top(self, value: Union[str, int]) -> "MSSQLQueryBuilder": """ Implements support for simple TOP clauses. Does not include support for PERCENT or WITH TIES. https://docs.microsoft.com/en-us/sql/t-sql/queries/top-transact-sql?view=sql-server-2017 """ with copy_if_immutable(self) as this: try: this._top = int(value) except ValueError: raise QueryException("TOP value must be an integer") return this
def returning(self, *terms: Any) -> "PostgreQueryBuilder": with copy_if_immutable(self) as this: for term in terms: if isinstance(term, Field): this._return_field(term) elif isinstance(term, str): this._return_field_str(term) elif isinstance(term, ArithmeticExpression): this._return_other(term) elif isinstance(term, Function): raise QueryException( "Aggregate functions are not allowed in returning") else: this._return_other( this.wrap_constant(term, this._wrapper_cls)) return this
def do_update(self, update_field: Union[str, Field], update_value: Any) -> "PostgreQueryBuilder": with copy_if_immutable(self) as this: if this._on_conflict_do_nothing: raise QueryException("Can not have two conflict handlers") if isinstance(update_field, str): field = this._conflict_field_str(update_field) elif isinstance(update_field, Field): field = update_field else: raise QueryException("Unsupported update_field") this._on_conflict_do_updates.append( (field, ValueWrapper(update_value))) return this
def on_conflict(self, *target_fields: Union[str, Term]) -> "PostgreQueryBuilder": with copy_if_immutable(self) as this: if not this._insert_table: raise QueryException( "On conflict only applies to insert query") this._on_conflict = True for target_field in target_fields: if isinstance(target_field, str): this._on_conflict_fields.append( this._conflict_field_str(target_field)) elif isinstance(target_field, Term): this._on_conflict_fields.append(target_field) return this
def fetch_next(self, limit: int) -> "MSSQLQueryBuilder": # Overridden to provide a more domain-specific API for T-SQL users with copy_if_immutable(self) as this: this._limit = limit return this
def load(self, fp: str) -> "MySQLQueryBuilder": with copy_if_immutable(self) as this: this._load_file = fp return this
def copy_(self, table: Union[str, Table]) -> "VerticaCopyQueryBuilder": with copy_if_immutable(self) as this: this._copy_table = table if isinstance(table, Table) else Table(table) return this
def from_file(self, fp: str) -> "VerticaCopyQueryBuilder": with copy_if_immutable(self) as this: this._from_file = fp return this
def hint(self, label: str) -> "VerticaQueryBuilder": with copy_if_immutable(self) as this: this._hint = label return this
def into(self, table: Union[str, Table]) -> "MySQLQueryBuilder": with copy_if_immutable(self) as this: this._into_table = table if isinstance(table, Table) else Table(table) return this
def do_nothing(self) -> "PostgreQueryBuilder": with copy_if_immutable(self) as this: if len(this._on_conflict_do_updates) > 0: raise QueryException("Can not have two conflict handlers") this._on_conflict_do_nothing = True return this
def distinct(self): with copy_if_immutable(self) as this: this._distinct = True return this