當前位置: 首頁>>代碼示例>>Python>>正文


Python types.UserDefinedType方法代碼示例

本文整理匯總了Python中sqlalchemy.types.UserDefinedType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.UserDefinedType方法的具體用法?Python types.UserDefinedType怎麽用?Python types.UserDefinedType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.types的用法示例。


在下文中一共展示了types.UserDefinedType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: coerce_compared_value

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def coerce_compared_value(self, op, value):
        """Suggest a type for a 'coerced' Python value in an expression.

        Default behavior for :class:`.UserDefinedType` is the
        same as that of :class:`.TypeDecorator`; by default it returns
        ``self``, assuming the compared value should be coerced into
        the same type as this one.  See
        :meth:`.TypeDecorator.coerce_compared_value` for more detail.

        .. versionchanged:: 0.8 :meth:`.UserDefinedType.coerce_compared_value`
           now returns ``self`` by default, rather than falling onto the
           more fundamental behavior of
           :meth:`.TypeEngine.coerce_compared_value`.

        """

        return self 
開發者ID:jpush,項目名稱:jbox,代碼行數:19,代碼來源:type_api.py

示例2: _type_affinity

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def _type_affinity(self):
        """Return a rudimental 'affinity' value expressing the general class
        of type."""

        typ = None
        for t in self.__class__.__mro__:
            if t in (TypeEngine, UserDefinedType):
                return typ
            elif issubclass(t, (TypeEngine, UserDefinedType)):
                typ = t
        else:
            return self.__class__ 
開發者ID:jpush,項目名稱:jbox,代碼行數:14,代碼來源:type_api.py

示例3: _adapt_expression

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def _adapt_expression(self, op, other_comparator):
            if hasattr(self.type, 'adapt_operator'):
                util.warn_deprecated(
                    "UserDefinedType.adapt_operator is deprecated.  Create "
                    "a UserDefinedType.Comparator subclass instead which "
                    "generates the desired expression constructs, given a "
                    "particular operator."
                )
                return self.type.adapt_operator(op), self.type
            else:
                return op, self.type 
開發者ID:jpush,項目名稱:jbox,代碼行數:13,代碼來源:type_api.py

示例4: test_repr_custom_type_w_sqla_prefix

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_repr_custom_type_w_sqla_prefix(self):
        self.autogen_context.opts["user_module_prefix"] = None

        class MyType(UserDefinedType):
            pass

        MyType.__module__ = "sqlalchemy_util.types"

        type_ = MyType()

        eq_ignore_whitespace(
            autogenerate.render._repr_type(type_, self.autogen_context),
            "sqlalchemy_util.types.MyType()",
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:16,代碼來源:test_autogen_render.py

示例5: test_repr_user_type_user_prefix_None

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_repr_user_type_user_prefix_None(self):
        class MyType(UserDefinedType):
            def get_col_spec(self):
                return "MYTYPE"

        type_ = MyType()
        self.autogen_context.opts["user_module_prefix"] = None

        eq_ignore_whitespace(
            autogenerate.render._repr_type(type_, self.autogen_context),
            "tests.test_autogen_render.MyType()",
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:14,代碼來源:test_autogen_render.py

示例6: test_repr_user_type_user_prefix_present

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_repr_user_type_user_prefix_present(self):
        from sqlalchemy.types import UserDefinedType

        class MyType(UserDefinedType):
            def get_col_spec(self):
                return "MYTYPE"

        type_ = MyType()

        self.autogen_context.opts["user_module_prefix"] = "user."

        eq_ignore_whitespace(
            autogenerate.render._repr_type(type_, self.autogen_context),
            "user.MyType()",
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:17,代碼來源:test_autogen_render.py

示例7: _adapt_expression

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def _adapt_expression(self, op, other_comparator):
            if hasattr(self.type, 'adapt_operator'):
                util.warn_deprecated(
                    "UserDefinedType.adapt_operator is deprecated.  Create "
                    "a UserDefinedType.Comparator subclass instead which "
                    "generates the desired expression constructs, given a "
                    "particular operator."
                )
                return self.type.adapt_operator(op), self.type
            else:
                return super(
                    UserDefinedType.Comparator, self
                )._adapt_expression(op, other_comparator) 
開發者ID:yfauser,項目名稱:planespotter,代碼行數:15,代碼來源:type_api.py

示例8: coerce_compared_value

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def coerce_compared_value(self, op, value):
        """Suggest a type for a 'coerced' Python value in an expression.

        Default behavior for :class:`.UserDefinedType` is the
        same as that of :class:`.TypeDecorator`; by default it returns
        ``self``, assuming the compared value should be coerced into
        the same type as this one.  See
        :meth:`.TypeDecorator.coerce_compared_value` for more detail.

        """

        return self 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:14,代碼來源:type_api.py

示例9: special_types_table

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def special_types_table(self, metadata):

        # create these types so that we can issue
        # special SQL92 INTERVAL syntax
        class y2m(types.UserDefinedType, postgresql.INTERVAL):
            def get_col_spec(self):
                return "INTERVAL YEAR TO MONTH"

        class d2s(types.UserDefinedType, postgresql.INTERVAL):
            def get_col_spec(self):
                return "INTERVAL DAY TO SECOND"

        table = Table(
            "sometable",
            metadata,
            Column("id", postgresql.UUID, primary_key=True),
            Column("flag", postgresql.BIT),
            Column("bitstring", postgresql.BIT(4)),
            Column("addr", postgresql.INET),
            Column("addr2", postgresql.MACADDR),
            Column("price", postgresql.MONEY),
            Column("addr3", postgresql.CIDR),
            Column("doubleprec", postgresql.DOUBLE_PRECISION),
            Column("plain_interval", postgresql.INTERVAL),
            Column("year_interval", y2m()),
            Column("month_interval", d2s()),
            Column("precision_interval", postgresql.INTERVAL(precision=3)),
            Column("tsvector_document", postgresql.TSVECTOR),
        )

        return table 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:33,代碼來源:test_types.py

示例10: test_ret_type_custom

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_ret_type_custom(self):
        class MyType(types.UserDefinedType):
            pass

        col = column("x", HSTORE(text_type=MyType))

        is_(col["foo"].type.__class__, MyType) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:9,代碼來源:test_types.py

示例11: test_custom_astext_type

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_custom_astext_type(self):
        class MyType(types.UserDefinedType):
            pass

        col = column("x", JSON(astext_type=MyType))

        is_(col["q"].astext.type.__class__, MyType)

        is_(col[("q", "p")].astext.type.__class__, MyType)

        is_(col["q"]["p"].astext.type.__class__, MyType) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:13,代碼來源:test_types.py

示例12: test_user_defined_dialect_specific_args

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_user_defined_dialect_specific_args(self):
        class MyType(types.UserDefinedType):
            def __init__(self, foo="foo", **kwargs):
                super(MyType, self).__init__()
                self.foo = foo
                self.dialect_specific_args = kwargs

            def adapt(self, cls):
                return cls(foo=self.foo, **self.dialect_specific_args)

        t = MyType(bar="bar")
        a = t.dialect_impl(testing.db.dialect)
        eq_(a.foo, "foo")
        eq_(a.dialect_specific_args["bar"], "bar") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:16,代碼來源:test_types.py

示例13: setup

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def setup(self):
        class UTypeOne(types.UserDefinedType):
            def get_col_spec(self):
                return "UTYPEONE"

            def bind_processor(self, dialect):
                def process(value):
                    return value + "UONE"

                return process

        class UTypeTwo(types.UserDefinedType):
            def get_col_spec(self):
                return "UTYPETWO"

            def bind_processor(self, dialect):
                def process(value):
                    return value + "UTWO"

                return process

        class UTypeThree(types.UserDefinedType):
            def get_col_spec(self):
                return "UTYPETHREE"

        self.UTypeOne = UTypeOne
        self.UTypeTwo = UTypeTwo
        self.UTypeThree = UTypeThree
        self.variant = self.UTypeOne().with_variant(
            self.UTypeTwo(), "postgresql"
        )
        self.composite = self.variant.with_variant(self.UTypeThree(), "mysql") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:34,代碼來源:test_types.py

示例14: test_bind_typing

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_bind_typing(self):
        from sqlalchemy.sql import column

        class MyFoobarType(types.UserDefinedType):
            pass

        class Foo(object):
            pass

        # unknown type + integer, right hand bind
        # coerces to given type
        expr = column("foo", MyFoobarType) + 5
        assert expr.right.type._type_affinity is MyFoobarType

        # untyped bind - it gets assigned MyFoobarType
        bp = bindparam("foo")
        expr = column("foo", MyFoobarType) + bp
        assert bp.type._type_affinity is types.NullType  # noqa
        assert expr.right.type._type_affinity is MyFoobarType

        expr = column("foo", MyFoobarType) + bindparam("foo", type_=Integer)
        assert expr.right.type._type_affinity is types.Integer

        # unknown type + unknown, right hand bind
        # coerces to the left
        expr = column("foo", MyFoobarType) + Foo()
        assert expr.right.type._type_affinity is MyFoobarType

        # including for non-commutative ops
        expr = column("foo", MyFoobarType) - Foo()
        assert expr.right.type._type_affinity is MyFoobarType

        expr = column("foo", MyFoobarType) - datetime.date(2010, 8, 25)
        assert expr.right.type._type_affinity is MyFoobarType 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:36,代碼來源:test_types.py

示例15: test_user_defined

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import UserDefinedType [as 別名]
def test_user_defined(self):
        """test that dialects pass the column through on DDL."""

        class MyType(types.UserDefinedType):
            def get_col_spec(self, **kw):
                return "FOOB %s" % kw["type_expression"].name

        m = MetaData()
        t = Table("t", m, Column("bar", MyType, nullable=False))
        self.assert_compile(ddl.CreateColumn(t.c.bar), "bar FOOB bar NOT NULL") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:12,代碼來源:test_types.py


注:本文中的sqlalchemy.types.UserDefinedType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。