本文整理匯總了Python中sqlalchemy.types.String方法的典型用法代碼示例。如果您正苦於以下問題:Python types.String方法的具體用法?Python types.String怎麽用?Python types.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.types
的用法示例。
在下文中一共展示了types.String方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _render_server_default_for_compare
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def _render_server_default_for_compare(metadata_default,
metadata_col, autogen_context):
rendered = _user_defined_render(
"server_default", metadata_default, autogen_context)
if rendered is not False:
return rendered
if isinstance(metadata_default, sa_schema.DefaultClause):
if isinstance(metadata_default.arg, compat.string_types):
metadata_default = metadata_default.arg
else:
metadata_default = str(metadata_default.arg.compile(
dialect=autogen_context.dialect))
if isinstance(metadata_default, compat.string_types):
if metadata_col.type._type_affinity is sqltypes.String:
metadata_default = re.sub(r"^'|'$", "", metadata_default)
return repr(metadata_default)
else:
return metadata_default
else:
return None
示例2: get_type
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def get_type(data_type):
type_map = {
"bytes": types.LargeBinary,
"boolean": types.Boolean,
"date": types.Date,
"datetime": types.DateTime,
"double": types.Numeric,
"text": types.String,
"keyword": types.String,
"integer": types.Integer,
"half_float": types.Float,
"geo_point": types.String,
# TODO get a solution for nested type
"nested": types.String,
# TODO get a solution for object
"object": types.BLOB,
"long": types.BigInteger,
"float": types.Float,
"ip": types.String,
}
type_ = type_map.get(data_type)
if not type_:
logger.warning(f"Unknown type found {data_type} reverting to string")
type_ = types.String
return type_
示例3: define_field_function
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def define_field_function():
@register(Model)
class Test:
id = Integer(primary_key=True)
first_name = String()
last_name = String()
name = Function(fget='fget', fset='fset', fdel='fdel',
fexpr='fexpr')
def fget(self):
return '{0} {1}'.format(self.first_name, self.last_name)
def fset(self, value):
self.first_name, self.last_name = value.split(' ', 1)
def fdel(self):
self.first_name = self.last_name = None
@classmethod
def fexpr(cls):
return func.concat(cls.first_name, ' ', cls.last_name)
示例4: _mysql_colspec
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def _mysql_colspec(
compiler, nullable, server_default, type_, autoincrement, comment
):
spec = "%s %s" % (
compiler.dialect.type_compiler.process(type_),
"NULL" if nullable else "NOT NULL",
)
if autoincrement:
spec += " AUTO_INCREMENT"
if server_default is not False and server_default is not None:
spec += " DEFAULT %s" % _render_value(compiler, server_default)
if comment:
spec += " COMMENT %s" % compiler.sql_compiler.render_literal_value(
comment, sqltypes.String()
)
return spec
示例5: visit_column_comment
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def visit_column_comment(element, compiler, **kw):
ddl = "COMMENT ON COLUMN {table_name}.{column_name} IS {comment}"
comment = (
compiler.sql_compiler.render_literal_value(
element.comment, sqltypes.String()
)
if element.comment is not None
else "NULL"
)
return ddl.format(
table_name=format_table_name(
compiler, element.table_name, element.schema
),
column_name=format_column_name(compiler, element.column_name),
comment=comment,
)
示例6: bind_processor
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def bind_processor(self, dialect):
if dialect._cx_oracle_with_unicode:
def process(value):
if value is None:
return value
else:
return unicode(value)
return process
else:
return super(
_NativeUnicodeMixin, self).bind_processor(dialect)
# we apply a connection output handler that returns
# unicode in all cases, so the "native_unicode" flag
# will be set for the default String.result_processor.
示例7: with_variant
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def with_variant(self, type_, dialect_name):
"""Produce a new type object that will utilize the given
type when applied to the dialect of the given name.
e.g.::
from sqlalchemy.types import String
from sqlalchemy.dialects import mysql
s = String()
s = s.with_variant(mysql.VARCHAR(collation='foo'), 'mysql')
The construction of :meth:`.TypeEngine.with_variant` is always
from the "fallback" type to that which is dialect specific.
The returned type is an instance of :class:`.Variant`, which
itself provides a :meth:`.Variant.with_variant`
that can be called repeatedly.
:param type_: a :class:`.TypeEngine` that will be selected
as a variant from the originating type, when a dialect
of the given name is in use.
:param dialect_name: base name of the dialect which uses
this type. (i.e. ``'postgresql'``, ``'mysql'``, etc.)
.. versionadded:: 0.7.2
"""
return Variant(self, {dialect_name: to_instance(type_)})
示例8: define_tables
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def define_tables(cls, metadata):
Table('test_table', metadata,
Column('id', Integer, primary_key=True),
Column('data', String(50))
)
示例9: test_varchar_reflection
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def test_varchar_reflection(self):
typ = self._type_round_trip(sql_types.String(52))[0]
assert isinstance(typ, sql_types.String)
eq_(typ.length, 52)
示例10: assert_tables_equal
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def assert_tables_equal(self, table, reflected_table, strict_types=False):
assert len(table.c) == len(reflected_table.c)
for c, reflected_c in zip(table.c, reflected_table.c):
eq_(c.name, reflected_c.name)
assert reflected_c is reflected_table.c[c.name]
eq_(c.primary_key, reflected_c.primary_key)
eq_(c.nullable, reflected_c.nullable)
if strict_types:
msg = "Type '%s' doesn't correspond to type '%s'"
assert isinstance(reflected_c.type, type(c.type)), \
msg % (reflected_c.type, c.type)
else:
self.assert_types_base(reflected_c, c)
if isinstance(c.type, sqltypes.String):
eq_(c.type.length, reflected_c.type.length)
eq_(
set([f.column.name for f in c.foreign_keys]),
set([f.column.name for f in reflected_c.foreign_keys])
)
if c.server_default:
assert isinstance(reflected_c.server_default,
schema.FetchedValue)
assert len(table.primary_key) == len(reflected_table.primary_key)
for c in table.primary_key:
assert reflected_table.primary_key.columns[c.name] is not None
示例11: load_dialect_imp
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def load_dialect_imp(self, dialect):
return dialect.type_descriptor(String(255))
示例12: load_dialect_impl
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def load_dialect_impl(self, dialect):
if dialect.name == 'postgresql':
return dialect.type_descriptor(JSONB())
elif dialect.name == 'mysql':
return dialect.type_descriptor(types.JSON())
elif dialect.name == 'oracle':
return dialect.type_descriptor(CLOB())
else:
return dialect.type_descriptor(String())
示例13: coerce_compared_value
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def coerce_compared_value(self, op, value):
if op in (operators.like_op, operators.notlike_op):
return String()
else:
return self
示例14: get_columns
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def get_columns(self, connection, table_name, schema=None, **kw):
# Extend types supported by PrestoDialect as defined in PyHive
type_map = {
'bigint': sql_types.BigInteger,
'integer': sql_types.Integer,
'boolean': sql_types.Boolean,
'double': sql_types.Float,
'varchar': sql_types.String,
'timestamp': sql_types.TIMESTAMP,
'date': sql_types.DATE,
'array<bigint>': sql_types.ARRAY(sql_types.Integer),
'array<varchar>': sql_types.ARRAY(sql_types.String)
}
rows = self._get_table_columns(connection, table_name, schema)
result = []
for row in rows:
try:
coltype = type_map[row.Type]
except KeyError:
logger.warn("Did not recognize type '%s' of column '%s'" % (row.Type, row.Column))
coltype = sql_types.NullType
result.append({
'name': row.Column,
'type': coltype,
# newer Presto no longer includes this column
'nullable': getattr(row, 'Null', True),
'default': None,
})
return result
示例15: test_reflect_select
# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import String [as 別名]
def test_reflect_select(table, table_using_test_dataset):
for table in [table, table_using_test_dataset]:
assert len(table.c) == 18
assert isinstance(table.c.integer, Column)
assert isinstance(table.c.integer.type, types.Integer)
assert isinstance(table.c.timestamp.type, types.TIMESTAMP)
assert isinstance(table.c.string.type, types.String)
assert isinstance(table.c.float.type, types.Float)
assert isinstance(table.c.boolean.type, types.Boolean)
assert isinstance(table.c.date.type, types.DATE)
assert isinstance(table.c.datetime.type, types.DATETIME)
assert isinstance(table.c.time.type, types.TIME)
assert isinstance(table.c.bytes.type, types.BINARY)
assert isinstance(table.c['record.age'].type, types.Integer)
assert isinstance(table.c['record.name'].type, types.String)
assert isinstance(table.c['nested_record.record.age'].type, types.Integer)
assert isinstance(table.c['nested_record.record.name'].type, types.String)
assert isinstance(table.c.array.type, types.ARRAY)
rows = table.select().execute().fetchall()
assert len(rows) == 1000