当前位置: 首页>>代码示例>>Python>>正文


Python types.Unicode方法代码示例

本文整理汇总了Python中sqlalchemy.types.Unicode方法的典型用法代码示例。如果您正苦于以下问题:Python types.Unicode方法的具体用法?Python types.Unicode怎么用?Python types.Unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.types的用法示例。


在下文中一共展示了types.Unicode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_should_composite_convert

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_should_composite_convert():
    registry = Registry()

    class CompositeClass:
        def __init__(self, col1, col2):
            self.col1 = col1
            self.col2 = col2

    @convert_sqlalchemy_composite.register(CompositeClass, registry)
    def convert_composite_class(composite, registry):
        return graphene.String(description=composite.doc)

    field = convert_sqlalchemy_composite(
        composite(CompositeClass, (Column(types.Unicode(50)), Column(types.Unicode(50))), doc="Custom Help Text"),
        registry,
        mock_resolver,
    )
    assert isinstance(field, graphene.String) 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:20,代码来源:test_converter.py

示例2: test_no_convert_unicode

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_no_convert_unicode(self):
        """test no utf-8 encoding occurs"""

        dialect = sqlite.dialect()
        for t in (
            String(),
            sqltypes.CHAR(),
            sqltypes.Unicode(),
            sqltypes.UnicodeText(),
            String(),
            sqltypes.CHAR(),
            sqltypes.Unicode(),
            sqltypes.UnicodeText(),
        ):
            bindproc = t.dialect_impl(dialect).bind_processor(dialect)
            assert not bindproc or isinstance(
                bindproc(util.u("some string")), util.text_type
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_sqlite.py

示例3: test_reflect_unicode_no_nvarchar

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_reflect_unicode_no_nvarchar(self):
        metadata = self.metadata
        Table("tnv", metadata, Column("data", sqltypes.Unicode(255)))
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("tnv", m2, autoload=True)
        assert isinstance(t2.c.data.type, sqltypes.VARCHAR)

        if testing.against("oracle+cx_oracle"):
            assert isinstance(
                t2.c.data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleString,
            )

        data = u("m’a réveillé.")
        t2.insert().execute(data=data)
        res = t2.select().execute().first()["data"]
        eq_(res, data)
        assert isinstance(res, util.text_type) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例4: test_python_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_python_type(self):
        eq_(types.Integer().python_type, int)
        eq_(types.Numeric().python_type, decimal.Decimal)
        eq_(types.Numeric(asdecimal=False).python_type, float)
        eq_(types.LargeBinary().python_type, util.binary_type)
        eq_(types.Float().python_type, float)
        eq_(types.Interval().python_type, datetime.timedelta)
        eq_(types.Date().python_type, datetime.date)
        eq_(types.DateTime().python_type, datetime.datetime)
        eq_(types.String().python_type, str)
        eq_(types.Unicode().python_type, util.text_type)
        eq_(types.Enum("one", "two", "three").python_type, str)

        assert_raises(
            NotImplementedError, lambda: types.TypeEngine().python_type
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例5: on_connect

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def on_connect(self):
        if self.cx_oracle_ver < (5,):
            # no output type handlers before version 5
            return

        cx_Oracle = self.dbapi

        def output_type_handler(cursor, name, defaultType,
                                size, precision, scale):
            # convert all NUMBER with precision + positive scale to Decimal
            # this almost allows "native decimal" mode.
            if self.supports_native_decimal and \
                    defaultType == cx_Oracle.NUMBER and \
                    precision and scale > 0:
                return cursor.var(
                    cx_Oracle.STRING,
                    255,
                    outconverter=self._to_decimal,
                    arraysize=cursor.arraysize)
            # if NUMBER with zero precision and 0 or neg scale, this appears
            # to indicate "ambiguous".  Use a slower converter that will
            # make a decision based on each value received - the type
            # may change from row to row (!).   This kills
            # off "native decimal" mode, handlers still needed.
            elif self.supports_native_decimal and \
                    defaultType == cx_Oracle.NUMBER \
                    and not precision and scale <= 0:
                return cursor.var(
                    cx_Oracle.STRING,
                    255,
                    outconverter=self._detect_decimal,
                    arraysize=cursor.arraysize)
            # allow all strings to come back natively as Unicode
            elif self.coerce_to_unicode and \
                    defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR):
                return cursor.var(util.text_type, size, cursor.arraysize)

        def on_connect(conn):
            conn.outputtypehandler = output_type_handler

        return on_connect 
开发者ID:jpush,项目名称:jbox,代码行数:43,代码来源:cx_oracle.py

示例6: _get_default_schema_name

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def _get_default_schema_name(self, connection):
        return connection.scalar(
            text("SELECT user_name() as user_name",
                 typemap={'user_name': Unicode})
        ) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:base.py

示例7: table

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def table(self):
        """ Generate an appropriate table representation to mirror the
        fields known for this table. """
        if self._table is None:
            self._table = Table(self.table_name, self.meta)
            id_col = Column('_id', Unicode(42), primary_key=True)
            self._table.append_column(id_col)
            json_col = Column('_json', Unicode())
            self._table.append_column(json_col)
            self._fields_columns(self._table)
        return self._table 
开发者ID:openspending,项目名称:spendb,代码行数:13,代码来源:fact_table.py

示例8: _fields_columns

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def _fields_columns(self, table):
        """ Transform the (auto-detected) fields into a set of column
        specifications. """
        for field in self.dataset.fields:
            data_type = TYPES.get(field.get('type'), Unicode)
            col = Column(field.get('name'), data_type, nullable=True)
            table.append_column(col) 
开发者ID:openspending,项目名称:spendb,代码行数:9,代码来源:fact_table.py

示例9: test_should_unicode_convert_string

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_should_unicode_convert_string():
    assert get_field(types.Unicode()).type == graphene.String 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:4,代码来源:test_converter.py

示例10: test_should_unknown_sqlalchemy_composite_raise_exception

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_should_unknown_sqlalchemy_composite_raise_exception():
    class CompositeClass:
        def __init__(self, col1, col2):
            self.col1 = col1
            self.col2 = col2

    re_err = "Don't know how to convert the composite field"
    with pytest.raises(Exception, match=re_err):
        convert_sqlalchemy_composite(
            composite(CompositeFullName, (Column(types.Unicode(50)), Column(types.Unicode(50)))),
            Registry(),
            mock_resolver,
        ) 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:15,代码来源:test_converter.py

示例11: ColumnWrapper

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def ColumnWrapper(type):
    class Wrapped(types.TypeDecorator):
        impl = types.Unicode
        def process_bind_param(self, value, dialect):
            if isinstance(value, type):
                return value.value
            return value
        def process_result_value(self, value, dialect):
            return type(value)
    return Wrapped 
开发者ID:muesli-hd,项目名称:muesli,代码行数:12,代码来源:types.py

示例12: create_sa_proxies

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def create_sa_proxies(self):

        # create the table and mapper
        metadata = schema.MetaData()
        user_table = schema.Table(
            'user',
            metadata,
            schema.Column('id', types.Integer, primary_key=True),
            schema.Column('first_name', types.Unicode(25)),
            schema.Column('last_name', types.Unicode(25))
        )

        class User(object):
            pass
        orm.mapper(User, user_table)

        # create the session
        engine = create_engine('sqlite:///:memory:')
        metadata.bind = engine
        metadata.create_all()
        session = orm.sessionmaker(bind=engine)()

        # add some dummy data
        user_table.insert().execute([
            {'first_name': 'Jonathan', 'last_name': 'LaCour'},
            {'first_name': 'Yoann', 'last_name': 'Roman'}
        ])

        # get the SA objects
        self.sa_object = session.query(User).first()
        select = user_table.select()
        self.result_proxy = select.execute()
        self.row_proxy = select.execute().fetchone() 
开发者ID:pecan,项目名称:pecan,代码行数:35,代码来源:test_jsonify.py

示例13: _get_default_schema_name

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def _get_default_schema_name(self, connection):
        return connection.scalar(
            text("SELECT user_name() as user_name").columns(username=Unicode)
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:6,代码来源:base.py

示例14: test_unicode_warnings_typelevel_native_unicode

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_unicode_warnings_typelevel_native_unicode(self):

        unicodedata = self.data
        u = Unicode()
        dialect = default.DefaultDialect()
        dialect.supports_unicode_binds = True
        uni = u.dialect_impl(dialect).bind_processor(dialect)
        if util.py3k:
            assert_raises(exc.SAWarning, uni, b"x")
            assert isinstance(uni(unicodedata), str)
        else:
            assert_raises(exc.SAWarning, uni, "x")
            assert isinstance(uni(unicodedata), unicode)  # noqa 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:15,代码来源:test_types.py

示例15: test_unicode_warnings_typelevel_sqla_unicode

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import Unicode [as 别名]
def test_unicode_warnings_typelevel_sqla_unicode(self):
        unicodedata = self.data
        u = Unicode()
        dialect = default.DefaultDialect()
        dialect.supports_unicode_binds = False
        uni = u.dialect_impl(dialect).bind_processor(dialect)
        assert_raises(exc.SAWarning, uni, util.b("x"))
        assert isinstance(uni(unicodedata), util.binary_type)

        eq_(uni(unicodedata), unicodedata.encode("utf-8")) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:12,代码来源:test_types.py


注:本文中的sqlalchemy.types.Unicode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。