Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_duplicate_key_update(self, field, value):
field = Field(field) if not isinstance(field, Field) else field
self._duplicate_updates.append((field, ValueWrapper(value)))
def orderby(self, *fields, **kwargs):
for field in fields:
field = (
Field(field, table=self.base_query._from[0])
if isinstance(field, str)
else self.base_query.wrap_constant(field)
)
self._orderbys.append((field, kwargs.get("order")))
def set(self, field, value):
field = Field(field) if not isinstance(field, Field) else field
self._updates.append((field, ValueWrapper(value)))
def field(self, name):
return Field(name, table=self)
def __init__(
self, field,
):
super().__init__(None)
self.field = Field(field) if not isinstance(field, Field) else field
field_sql, field_alias, quote_char=quote_char, **kwargs
)
return field_sql
class Index(Term):
def __init__(self, name, alias=None):
super(Index, self).__init__(alias)
self.name = name
def get_sql(self, quote_char=None, **kwargs):
return format_quotes(self.name, quote_char)
class Star(Field):
def __init__(self, table=None):
super(Star, self).__init__("*", table=table)
@property
def tables_(self):
if self.table is None:
return {}
return {self.table}
def get_sql(
self, with_alias=False, with_namespace=False, quote_char=None, **kwargs
):
if self.table and (with_namespace or self.table.alias):
namespace = self.table.alias or getattr(self.table, "_table_name")
return "{}.*".format(format_quotes(namespace, quote_char))
def columns(self, *terms):
if self._insert_table is None:
raise AttributeError("'Query' object has no attribute '%s'" % "insert")
for term in terms:
if isinstance(term, str):
term = Field(term, table=self._insert_table)
self._columns.append(term)
def groupby(self, *terms):
for term in terms:
if isinstance(term, str):
term = Field(term, table=self._from[0])
elif isinstance(term, int):
term = Field(str(term), table=self._from[0]).wrap_constant(term)
self._groupbys.append(term)