本文整理匯總了Python中sqlalchemy.sql.table.constraints方法的典型用法代碼示例。如果您正苦於以下問題:Python table.constraints方法的具體用法?Python table.constraints怎麽用?Python table.constraints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.sql.table
的用法示例。
在下文中一共展示了table.constraints方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: from_table
# 需要導入模塊: from sqlalchemy.sql import table [as 別名]
# 或者: from sqlalchemy.sql.table import constraints [as 別名]
def from_table(cls, table):
return cls(
table.name,
list(table.c) + list(table.constraints),
schema=table.schema,
_orig_table=table,
**table.kwargs
)
示例2: create_check_constraint
# 需要導入模塊: from sqlalchemy.sql import table [as 別名]
# 或者: from sqlalchemy.sql.table import constraints [as 別名]
def create_check_constraint(
cls, operations,
constraint_name, table_name, condition,
schema=None, **kw):
"""Issue a "create check constraint" instruction using the
current migration context.
e.g.::
from alembic import op
from sqlalchemy.sql import column, func
op.create_check_constraint(
"ck_user_name_len",
"user",
func.len(column('name')) > 5
)
CHECK constraints are usually against a SQL expression, so ad-hoc
table metadata is usually needed. The function will convert the given
arguments into a :class:`sqlalchemy.schema.CheckConstraint` bound
to an anonymous table in order to emit the CREATE statement.
:param name: Name of the check constraint. The name is necessary
so that an ALTER statement can be emitted. For setups that
use an automated naming scheme such as that described at
:ref:`sqla:constraint_naming_conventions`,
``name`` here can be ``None``, as the event listener will
apply the name to the constraint object when it is associated
with the table.
:param table_name: String name of the source table.
:param condition: SQL expression that's the condition of the
constraint. Can be a string or SQLAlchemy expression language
structure.
:param deferrable: optional bool. If set, emit DEFERRABLE or
NOT DEFERRABLE when issuing DDL for this constraint.
:param initially: optional string. If set, emit INITIALLY <value>
when issuing DDL for this constraint.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
.. versionchanged:: 0.8.0 The following positional argument names
have been changed:
* name -> constraint_name
* source -> table_name
"""
op = cls(constraint_name, table_name, condition, schema=schema, **kw)
return operations.invoke(op)