本文整理汇总了Python中sqlalchemy.types.String方法的典型用法代码示例。如果您正苦于以下问题:Python types.String方法的具体用法?Python types.String怎么用?Python types.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块sqlalchemy.types的用法示例。
在下文中一共展示了types.String方法的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _render_server_default_for_compare
点赞 6
# 需要导入模块: 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
开发者ID:jpush,项目名称:jbox,代码行数:23,
示例2: get_type
点赞 6
# 需要导入模块: 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_
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:27,
示例3: define_field_function
点赞 6
# 需要导入模块: 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)
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:25,
示例4: _mysql_colspec
点赞 6
# 需要导入模块: 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
开发者ID:sqlalchemy,项目名称:alembic,代码行数:19,
示例5: visit_column_comment
点赞 6
# 需要导入模块: 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,
)
开发者ID:sqlalchemy,项目名称:alembic,代码行数:19,
示例6: bind_processor
点赞 5
# 需要导入模块: 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.
开发者ID:jpush,项目名称:jbox,代码行数:17,
示例7: with_variant
点赞 5
# 需要导入模块: 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_)})
开发者ID:jpush,项目名称:jbox,代码行数:31,
示例8: define_tables
点赞 5
# 需要导入模块: 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))
)
开发者ID:jpush,项目名称:jbox,代码行数:7,
示例9: test_varchar_reflection
点赞 5
# 需要导入模块: 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)
开发者ID:jpush,项目名称:jbox,代码行数:6,
示例10: assert_tables_equal
点赞 5
# 需要导入模块: 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
开发者ID:jpush,项目名称:jbox,代码行数:31,
示例11: load_dialect_imp
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def load_dialect_imp(self, dialect):
return dialect.type_descriptor(String(255))
开发者ID:rucio,项目名称:rucio,代码行数:4,
示例12: load_dialect_impl
点赞 5
# 需要导入模块: 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())
开发者ID:rucio,项目名称:rucio,代码行数:11,
示例13: coerce_compared_value
点赞 5
# 需要导入模块: 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
开发者ID:rucio,项目名称:rucio,代码行数:7,
示例14: get_columns
点赞 5
# 需要导入模块: 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': sql_types.ARRAY(sql_types.Integer),
'array': 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
开发者ID:airbnb,项目名称:omniduct,代码行数:32,
示例15: test_reflect_select
点赞 5
# 需要导入模块: 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
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:24,
示例16: get_descendent_subjects
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def get_descendent_subjects(cls, subject_id, of_type_id, from_date, to_date, whole_time_required):
if whole_time_required:
datestr = "(%(ss)s.joined_at<=:from_date AND (%(ss)s.left_at IS NULL OR %(ss)s.left_at >= :to_date))"
else:
datestr = "((%(ss)s.joined_at<=:from_date AND (%(ss)s.left_at IS NULL OR %(ss)s.left_at >= :from_date))" \
"OR (%(ss)s.joined_at >= :from_date AND %(ss)s.joined_at <= :to_date)" \
"OR (%(ss)s.left_at >= :from_date AND %(ss)s.left_at <= :to_date))"
sq = text("""
WITH RECURSIVE nodes_cte(subject_id, name, part_of_id, depth, path) AS (
SELECT g1.id, g1.name, NULL::bigint as part_of_id, 1::INT as depth, g1.id::TEXT as path
FROM subjects as g1
LEFT JOIN subjects_subjects ss ON ss.subject_id=g1.id
WHERE ss.part_of_id = :subject_id AND """+(datestr % {'ss': 'ss'})+"""
UNION ALL
SELECT c.subject_id, g2.name, c.part_of_id, p.depth + 1 AS depth,
(p.path || '->' || g2.id ::TEXT)
FROM nodes_cte AS p, subjects_subjects AS c
JOIN subjects AS g2 ON g2.id=c.subject_id
WHERE c.part_of_id = p.subject_id AND """+(datestr % {'ss': 'c'})+"""
) SELECT * FROM nodes_cte
""").bindparams(subject_id=subject_id, from_date=from_date, to_date=to_date).columns(subject_id=Integer, name=String, part_of_id=Integer, depth=Integer, path=String).alias()
j = t_subjects.join(sq, sq.c.subject_id == t_subjects.c.id)
q = select([
sq.c.path.label("subject_path"),
sq.c.subject_id.label("subject_id"),
sq.c.name.label("subject_name"),
t_subjects.c.subjecttype_id.label("subjecttype_id")
], from_obj=j)
if of_type_id is not None:
q = q.where(t_subjects.c.subjecttype_id == of_type_id)
rows = DBSession.execute(q).fetchall()
subjects = {r["subject_id"]: r for r in rows if r["subject_id"]}
return subjects
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:40,
示例17: test_field_json_related_exp_1
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def test_field_json_related_exp_1(self, registry_json_related):
registry = registry_json_related
Test = registry.Test
Test.insert()
query = registry.Test.query().filter(
Test.name.cast(types.String) == '"jssuzanne"')
assert not (query.count())
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:9,
示例18: test_field_json_related_exp_2
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def test_field_json_related_exp_2(self, registry_json_related):
registry = registry_json_related
Test = registry.Test
Test.insert(properties={})
query = registry.Test.query().filter(
Test.name.cast(types.String) == '"jssuzanne"')
assert not (query.count())
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:9,
示例19: test_field_json_related_exp_3
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def test_field_json_related_exp_3(self, registry_json_related):
registry = registry_json_related
Test = registry.Test
Test.insert(properties={'name': 'jssuzanne'})
query = registry.Test.query().filter(
Test.name.cast(types.String) == '"jssuzanne"')
assert query.count()
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:9,
示例20: test_field_json_related_exp_4
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def test_field_json_related_exp_4(self, registry_json_related2):
registry = registry_json_related2
Test = registry.Test
Test.insert(properties={'sub': {'name': 'jssuzanne'}})
query = registry.Test.query().filter(
Test.name.cast(types.String) == '"jssuzanne"')
assert query.count()
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:9,
示例21: __init__
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def __init__(self, *args, **kwargs):
self.size = kwargs.pop('size', 64)
kwargs.pop('type_', None)
self.sqlalchemy_type = StringType(self.size)
super(String, self).__init__(*args, **kwargs)
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:7,
示例22: autodoc_get_properties
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def autodoc_get_properties(self):
"""Return properties for autodoc
:return: autodoc properties
"""
res = super(String, self).autodoc_get_properties()
res['size'] = self.size
return res
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:10,
示例23: __init__
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def __init__(self, table):
super(Model, self).__init__()
self.table = table
self.schema = table.schema
# Adapt column types to the most reasonable generic types (ie. VARCHAR -> String)
for column in table.columns:
try:
column.type = self._get_adapted_type(column.type, column.table.bind)
except:
# print('Failed to get col type for {}, {}'.format(column, column.type))
print("#Failed to get col type for {}".format(column))
开发者ID:thomaxxl,项目名称:safrs,代码行数:14,
示例24: render_metadata_declarations
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def render_metadata_declarations(self):
if "sqlalchemy.ext.declarative" in self.collector:
return """
########################################################################################################################
# Manually Added for safrs, TODO: improve this crap
#
from safrs import SAFRSBase
Base = db.Model
metadata = Base.metadata
NullType = db.String
TIMESTAMP= db.TIMESTAMP
if db.session.bind.dialect.name == "mysql":
from sqlalchemy.dialects.mysql import *
def BIGINT(_):
return db.SMALLINT
def SMALLINT(_):
return db.SMALLINT
def INTEGER(_):
return db.INTEGER
def TIME(**kwargs):
return db.TIME
########################################################################################################################
"""
# return 'Base = declarative_base()\nmetadata = Base.metadata'
return "metadata = MetaData()"
开发者ID:thomaxxl,项目名称:safrs,代码行数:36,
示例25: _render_server_default_for_compare
点赞 5
# 需要导入模块: 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,
compile_kwargs={"literal_binds": True},
)
)
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
开发者ID:sqlalchemy,项目名称:alembic,代码行数:29,
示例26: new_wikipedia_tag
点赞 5
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import String [as 别名]
def new_wikipedia_tag(self, languages):
sitelinks = {code[:-4]: link['title']
for code, link in self.item.sitelinks().items()
if code.endswith('wiki')}
for lang in languages:
code = lang if isinstance(lang, str) else lang.wikimedia_language_code
if code in sitelinks:
return (code, sitelinks[code])
return (None, None)
# class ItemCandidateTag(Base):
# __tablename__ = 'item_candidate_tag'
# __table_args__ = (
# ForeignKeyConstraint(['item_id', 'osm_id', 'osm_type'],
# [ItemCandidate.item_id,
# ItemCandidate.osm_id,
# ItemCandidate.osm_type]),
# )
#
# item_id = Column(Integer, primary_key=True)
# osm_id = Column(BigInteger, primary_key=True)
# osm_type = Column(osm_type_enum, primary_key=True)
# k = Column(String, primary_key=True)
# v = Column(String, primary_key=True)
#
# item_candidate = relationship(ItemCandidate,
# backref=backref('tag_table', lazy='dynamic'))
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:30,
注:本文中的sqlalchemy.types.String方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。