How to use the pypika.terms.Field function in PyPika

To help you get started, we’ve selected a few PyPika examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kayak / pypika / pypika / dialects.py View on Github external
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)))
github kayak / pypika / pypika / queries.py View on Github external
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")))
github kayak / pypika / pypika / queries.py View on Github external
def set(self, field, value):
        field = Field(field) if not isinstance(field, Field) else field
        self._updates.append((field, ValueWrapper(value)))
github kayak / pypika / pypika / queries.py View on Github external
def field(self, name):
        return Field(name, table=self)
github kayak / pypika / pypika / terms.py View on Github external
def __init__(
        self, field,
    ):
        super().__init__(None)
        self.field = Field(field) if not isinstance(field, Field) else field
github kayak / pypika / pypika / terms.py View on Github external
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))
github kayak / pypika / pypika / queries.py View on Github external
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)
github kayak / pypika / pypika / queries.py View on Github external
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)