本文整理汇总了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)
示例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
)
示例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)
示例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
)
示例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
示例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})
)
示例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
示例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)
示例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
示例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,
)
示例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
示例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()
示例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)
)
示例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
示例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"))