本文整理汇总了Python中sqlalchemy.types.NULLTYPE属性的典型用法代码示例。如果您正苦于以下问题:Python types.NULLTYPE属性的具体用法?Python types.NULLTYPE怎么用?Python types.NULLTYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy.types
的用法示例。
在下文中一共展示了types.NULLTYPE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_detect_coercion_of_builtins
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def test_detect_coercion_of_builtins(self):
@inspection._self_inspects
class SomeSQLAThing(object):
def __repr__(self):
return "some_sqla_thing()"
class SomeOtherThing(object):
pass
assert_raises_message(
exc.ArgumentError,
r"SQL expression element or literal value expected, got "
r"some_sqla_thing\(\).",
lambda: column("a", String) == SomeSQLAThing(),
)
is_(bindparam("x", SomeOtherThing()).type, types.NULLTYPE)
示例2: to_constraint
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def to_constraint(self, migration_context=None):
if not util.sqla_100:
raise NotImplementedError(
"ExcludeConstraint not supported until SQLAlchemy 1.0")
if self._orig_constraint is not None:
return self._orig_constraint
schema_obj = schemaobj.SchemaObjects(migration_context)
t = schema_obj.table(self.table_name, schema=self.schema)
excl = ExcludeConstraint(
*self.elements,
name=self.constraint_name,
where=self.where,
**self.kw
)
for expr, name, oper in excl._render_exprs:
t.append_column(Column(name, NULLTYPE))
t.append_constraint(excl)
return excl
示例3: _get_column_info
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def _get_column_info(self, name, type_, nullable, autoincrement, default,
precision, scale, length):
coltype = self.ischema_names.get(type_, None)
kwargs = {}
if coltype in (NUMERIC, DECIMAL):
args = (precision, scale)
elif coltype == FLOAT:
args = (precision,)
elif coltype in (CHAR, VARCHAR, UNICHAR, UNIVARCHAR, NCHAR, NVARCHAR):
args = (length,)
else:
args = ()
if coltype:
coltype = coltype(*args, **kwargs)
# is this necessary
# if is_array:
# coltype = ARRAY(coltype)
else:
util.warn("Did not recognize type '%s' of column '%s'" %
(type_, name))
coltype = sqltypes.NULLTYPE
if default:
default = re.sub("DEFAULT", "", default).strip()
default = re.sub("^'(.*)'$", lambda m: m.group(1), default)
else:
default = None
column_info = dict(name=name, type=coltype, nullable=nullable,
default=default, autoincrement=autoincrement)
return column_info
示例4: _setup_referent
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def _setup_referent(self, metadata, constraint):
spec = constraint.elements[0]._get_colspec()
parts = spec.split(".")
tname = parts[-2]
if len(parts) == 3:
referent_schema = parts[0]
else:
referent_schema = None
if tname != '_alembic_batch_temp':
key = sql_schema._get_table_key(tname, referent_schema)
if key in metadata.tables:
t = metadata.tables[key]
for elem in constraint.elements:
colname = elem._get_colspec().split(".")[-1]
if not t.c.contains_column(colname):
t.append_column(
Column(colname, sqltypes.NULLTYPE)
)
else:
Table(
tname, metadata,
*[Column(n, sqltypes.NULLTYPE) for n in
[elem._get_colspec().split(".")[-1]
for elem in constraint.elements]],
schema=referent_schema)
示例5: to_column
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def to_column(self, migration_context=None):
if self._orig_column is not None:
return self._orig_column
schema_obj = schemaobj.SchemaObjects(migration_context)
return schema_obj.column(self.column_name, NULLTYPE)
示例6: primary_key_constraint
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def primary_key_constraint(self, name, table_name, cols, schema=None):
m = self.metadata()
columns = [sa_schema.Column(n, NULLTYPE) for n in cols]
t = sa_schema.Table(
table_name, m,
*columns,
schema=schema)
p = sa_schema.PrimaryKeyConstraint(
*[t.c[n] for n in cols], name=name)
t.append_constraint(p)
return p
示例7: _ensure_table_for_fk
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def _ensure_table_for_fk(self, metadata, fk):
"""create a placeholder Table object for the referent of a
ForeignKey.
"""
if isinstance(fk._colspec, string_types):
table_key, cname = fk._colspec.rsplit('.', 1)
sname, tname = self._parse_table_key(table_key)
if table_key not in metadata.tables:
rel_t = sa_schema.Table(tname, metadata, schema=sname)
else:
rel_t = metadata.tables[table_key]
if cname not in rel_t.c:
rel_t.append_column(sa_schema.Column(cname, NULLTYPE))
示例8: _textual_index_column
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def _textual_index_column(table, text_):
"""a workaround for the Index construct's severe lack of flexibility"""
if isinstance(text_, compat.string_types):
c = Column(text_, sqltypes.NULLTYPE)
table.append_column(c)
return c
elif isinstance(text_, TextClause):
return _textual_index_element(table, text_)
else:
raise ValueError("String or text() construct expected")
示例9: __init__
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def __init__(self, table, text):
self.table = table
self.text = text
self.key = text.text
self.fake_column = schema.Column(self.text.text, sqltypes.NULLTYPE)
table.append_column(self.fake_column)
示例10: _setup_referent
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def _setup_referent(self, metadata, constraint):
spec = constraint.elements[0]._get_colspec()
parts = spec.split(".")
tname = parts[-2]
if len(parts) == 3:
referent_schema = parts[0]
else:
referent_schema = None
if tname != self.temp_table_name:
key = sql_schema._get_table_key(tname, referent_schema)
if key in metadata.tables:
t = metadata.tables[key]
for elem in constraint.elements:
colname = elem._get_colspec().split(".")[-1]
if not t.c.contains_column(colname):
t.append_column(Column(colname, sqltypes.NULLTYPE))
else:
Table(
tname,
metadata,
*[
Column(n, sqltypes.NULLTYPE)
for n in [
elem._get_colspec().split(".")[-1]
for elem in constraint.elements
]
],
schema=referent_schema
)
示例11: primary_key_constraint
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def primary_key_constraint(self, name, table_name, cols, schema=None):
m = self.metadata()
columns = [sa_schema.Column(n, NULLTYPE) for n in cols]
t = sa_schema.Table(table_name, m, *columns, schema=schema)
p = sa_schema.PrimaryKeyConstraint(*[t.c[n] for n in cols], name=name)
t.append_constraint(p)
return p
示例12: unique_constraint
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def unique_constraint(self, name, source, local_cols, schema=None, **kw):
t = sa_schema.Table(
source,
self.metadata(),
*[sa_schema.Column(n, NULLTYPE) for n in local_cols],
schema=schema
)
kw["name"] = name
uq = sa_schema.UniqueConstraint(*[t.c[n] for n in local_cols], **kw)
# TODO: need event tests to ensure the event
# is fired off here
t.append_constraint(uq)
return uq
示例13: to_constraint
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def to_constraint(self, migration_context=None):
if self._orig_constraint is not None:
return self._orig_constraint
schema_obj = schemaobj.SchemaObjects(migration_context)
t = schema_obj.table(self.table_name, schema=self.schema)
excl = ExcludeConstraint(
*self.elements,
name=self.constraint_name,
where=self.where,
**self.kw
)
for expr, name, oper in excl._render_exprs:
t.append_column(Column(name, NULLTYPE))
t.append_constraint(excl)
return excl
示例14: test_skip_null_type_comparison_reflected
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def test_skip_null_type_comparison_reflected(self):
ac = ops.AlterColumnOp("sometable", "somecol")
autogenerate.compare._compare_type(
self.autogen_context,
ac,
None,
"sometable",
"somecol",
Column("somecol", NULLTYPE),
Column("somecol", Integer()),
)
diff = ac.to_diff_tuple()
assert not diff
示例15: test_skip_null_type_comparison_local
# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NULLTYPE [as 别名]
def test_skip_null_type_comparison_local(self):
ac = ops.AlterColumnOp("sometable", "somecol")
autogenerate.compare._compare_type(
self.autogen_context,
ac,
None,
"sometable",
"somecol",
Column("somecol", Integer()),
Column("somecol", NULLTYPE),
)
diff = ac.to_diff_tuple()
assert not diff