Python sqlalchemy 模块,type_coerce() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sqlalchemy.type_coerce()

项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:QualquerMerdaAPI    作者:tiagovizoto    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:flask    作者:bobohope    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_([0, 1]),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:marvin    作者:sdss    | 项目源码 | 文件源码
def __getitem__(self, index):
            super_ = super(ARRAY_D.Comparator, self).__getitem__(index)
            if not isinstance(index, slice) and self.type.dimensions > 1:
                super_ = type_coerce(
                    super_,
                    ARRAY_D(
                        self.type.item_type,
                        dimensions=self.type.dimensions - 1,
                        zero_indexes=self.type.zero_indexes)
                )
            return super_
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint),
            _type_bound=True
        )
        assert e.table is table
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if not self.create_constraint:
            return

        e = schema.CheckConstraint(
            type_coerce(column, self).in_([0, 1]),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint),
            _type_bound=True
        )
        assert e.table is table
项目:QualquerMerdaAPI    作者:tiagovizoto    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_([0, 1]),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_([0, 1]),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint),
            _type_bound=True
        )
        assert e.table is table
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if not self.create_constraint:
            return

        e = schema.CheckConstraint(
            type_coerce(column, self).in_([0, 1]),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint),
            _type_bound=True
        )
        assert e.table is table
项目:flask    作者:bobohope    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if not self.create_constraint:
            return

        variant_mapping = self._variant_mapping_for_set_table(column)

        e = schema.CheckConstraint(
            type_coerce(column, self).in_([0, 1]),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint,
                {"variant_mapping": variant_mapping}),
            _type_bound=True
        )
        assert e.table is table
项目:Chorus    作者:DonaldBough    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if self.native_enum:
            SchemaType._set_table(self, column, table)

        if not self.create_constraint:
            return

        e = schema.CheckConstraint(
            type_coerce(column, self).in_(self.enums),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint),
            _type_bound=True
        )
        assert e.table is table
项目:Chorus    作者:DonaldBough    | 项目源码 | 文件源码
def _set_table(self, schema, column, table):
        if not self.create_constraint:
            return

        e = schema.CheckConstraint(
            type_coerce(column, self).in_([0, 1]),
            name=_defer_name(self.name),
            _create_rule=util.portable_instancemethod(
                self._should_create_constraint),
            _type_bound=True
        )
        assert e.table is table
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:python_ddd_flask    作者:igorvinnicius    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:python_ddd_flask    作者:igorvinnicius    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:QualquerMerdaAPI    作者:tiagovizoto    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:Data-visualization    作者:insta-code1    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:Data-visualization    作者:insta-code1    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:python-flask-security    作者:weinbergdavid    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:python-flask-security    作者:weinbergdavid    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def type_coerce(expression, type_):
    """Associate a SQL expression with a particular type, without rendering
    ``CAST``.

    E.g.::

        from sqlalchemy import type_coerce

        stmt = select([type_coerce(log_table.date_string, StringDateTime())])

    The above construct will produce SQL that is usually otherwise unaffected
    by the :func:`.type_coerce` call::

        SELECT date_string FROM log

    However, when result rows are fetched, the ``StringDateTime`` type
    will be applied to result rows on behalf of the ``date_string`` column.

    A type that features bound-value handling will also have that behavior
    take effect when literal values or :func:`.bindparam` constructs are
    passed to :func:`.type_coerce` as targets.
    For example, if a type implements the :meth:`.TypeEngine.bind_expression`
    method or :meth:`.TypeEngine.bind_processor` method or equivalent,
    these functions will take effect at statement compilation/execution time
    when a literal value is passed, as in::

        # bound-value handling of MyStringType will be applied to the
        # literal value "some string"
        stmt = select([type_coerce("some string", MyStringType)])

    :func:`.type_coerce` is similar to the :func:`.cast` function,
    except that it does not render the ``CAST`` expression in the resulting
    statement.

    :param expression: A SQL expression, such as a :class:`.ColumnElement`
     expression or a Python string which will be coerced into a bound literal
     value.

    :param type_: A :class:`.TypeEngine` class or instance indicating
     the type to which the expression is coerced.

    .. seealso::

        :func:`.cast`

    """
    type_ = type_api.to_instance(type_)

    if hasattr(expression, '__clause_element__'):
        return type_coerce(expression.__clause_element__(), type_)
    elif isinstance(expression, BindParameter):
        bp = expression._clone()
        bp.type = type_
        return bp
    elif not isinstance(expression, Visitable):
        if expression is None:
            return Null()
        else:
            return literal(expression, type_=type_)
    else:
        return Label(None, expression, type_=type_)
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:flask    作者:bobohope    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)
项目:Chorus    作者:DonaldBough    | 项目源码 | 文件源码
def __init__(self, expression, type_):
        """Produce a ``CAST`` expression.

        :func:`.cast` returns an instance of :class:`.Cast`.

        E.g.::

            from sqlalchemy import cast, Numeric

            stmt = select([
                        cast(product_table.c.unit_price, Numeric(10, 4))
                    ])

        The above statement will produce SQL resembling::

            SELECT CAST(unit_price AS NUMERIC(10, 4)) FROM product

        The :func:`.cast` function performs two distinct functions when
        used.  The first is that it renders the ``CAST`` expression within
        the resulting SQL string.  The second is that it associates the given
        type (e.g. :class:`.TypeEngine` class or instance) with the column
        expression on the Python side, which means the expression will take
        on the expression operator behavior associated with that type,
        as well as the bound-value handling and result-row-handling behavior
        of the type.

        .. versionchanged:: 0.9.0 :func:`.cast` now applies the given type
           to the expression such that it takes effect on the bound-value,
           e.g. the Python-to-database direction, in addition to the
           result handling, e.g. database-to-Python, direction.

        An alternative to :func:`.cast` is the :func:`.type_coerce` function.
        This function performs the second task of associating an expression
        with a specific type, but does not render the ``CAST`` expression
        in SQL.

        :param expression: A SQL expression, such as a :class:`.ColumnElement`
         expression or a Python string which will be coerced into a bound
         literal value.

        :param type_: A :class:`.TypeEngine` class or instance indicating
         the type to which the ``CAST`` should apply.

        .. seealso::

            :func:`.type_coerce` - Python-side type coercion without emitting
            CAST.

        """
        self.type = type_api.to_instance(type_)
        self.clause = _literal_as_binds(expression, type_=self.type)
        self.typeclause = TypeClause(self.type)