本文整理汇总了Python中sqlalchemy.schema.AddConstraint方法的典型用法代码示例。如果您正苦于以下问题:Python schema.AddConstraint方法的具体用法?Python schema.AddConstraint怎么用?Python schema.AddConstraint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.schema
的用法示例。
在下文中一共展示了schema.AddConstraint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exclude_constraint_full
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_exclude_constraint_full(self):
m = MetaData()
room = Column("room", Integer, primary_key=True)
tbl = Table("testtbl", m, room, Column("during", TSRANGE))
room = Column("room", Integer, primary_key=True)
cons = ExcludeConstraint(
(room, "="),
("during", "&&"),
name="my_name",
using="gist",
where="room > 100",
deferrable=True,
initially="immediate",
)
tbl.append_constraint(cons)
self.assert_compile(
schema.AddConstraint(cons),
"ALTER TABLE testtbl ADD CONSTRAINT my_name "
"EXCLUDE USING gist "
"(room WITH =, during WITH "
"&&) WHERE "
"(room > 100) DEFERRABLE INITIALLY immediate",
dialect=postgresql.dialect(),
)
示例2: test_exclude_constraint_copy_where_using
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_exclude_constraint_copy_where_using(self):
m = MetaData()
tbl = Table("testtbl", m, Column("room", Integer, primary_key=True))
cons = ExcludeConstraint(
(tbl.c.room, "="), where=tbl.c.room > 5, using="foobar"
)
tbl.append_constraint(cons)
self.assert_compile(
schema.AddConstraint(cons),
"ALTER TABLE testtbl ADD EXCLUDE USING foobar "
"(room WITH =) WHERE (testtbl.room > 5)",
)
m2 = MetaData()
tbl2 = tbl.to_metadata(m2)
self.assert_compile(
schema.CreateTable(tbl2),
"CREATE TABLE testtbl (room SERIAL NOT NULL, "
"PRIMARY KEY (room), "
"EXCLUDE USING foobar "
"(room WITH =) WHERE (testtbl.room > 5))",
)
示例3: test_render_ck_constraint_inline
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_render_ck_constraint_inline(self):
t, t2 = self._constraint_create_fixture()
CheckConstraint(
"a < b",
name="my_test_constraint",
deferrable=True,
initially="DEFERRED",
table=t,
)
# before we create an AddConstraint,
# the CONSTRAINT comes out inline
self.assert_compile(
schema.CreateTable(t),
"CREATE TABLE tbl ("
"a INTEGER, "
"b INTEGER, "
"CONSTRAINT my_test_constraint CHECK (a < b) "
"DEFERRABLE INITIALLY DEFERRED"
")",
)
示例4: test_render_ck_constraint_external
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_render_ck_constraint_external(self):
t, t2 = self._constraint_create_fixture()
constraint = CheckConstraint(
"a < b",
name="my_test_constraint",
deferrable=True,
initially="DEFERRED",
table=t,
)
self.assert_compile(
schema.AddConstraint(constraint),
"ALTER TABLE tbl ADD CONSTRAINT my_test_constraint "
"CHECK (a < b) DEFERRABLE INITIALLY DEFERRED",
)
示例5: test_external_ck_constraint_cancels_internal
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_external_ck_constraint_cancels_internal(self):
t, t2 = self._constraint_create_fixture()
constraint = CheckConstraint(
"a < b",
name="my_test_constraint",
deferrable=True,
initially="DEFERRED",
table=t,
)
schema.AddConstraint(constraint)
# once we make an AddConstraint,
# inline compilation of the CONSTRAINT
# is disabled
self.assert_compile(
schema.CreateTable(t),
"CREATE TABLE tbl (" "a INTEGER, " "b INTEGER" ")",
)
示例6: test_fk_illegal_sql_phrases
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_fk_illegal_sql_phrases(self):
a = Table("a", MetaData(), Column("q", Integer))
b = Table("b", MetaData(), Column("p", Integer))
for kw in ("onupdate", "ondelete", "initially"):
for phrase in (
"NOT SQL",
"INITALLY NOT SQL",
"FOO RESTRICT",
"CASCADE WRONG",
"SET NULL",
):
const = schema.AddConstraint(
schema.ForeignKeyConstraint(
[a.c.q], [b.c.p], **{kw: phrase}
)
)
assert_raises_message(
exc.CompileError,
r"Unexpected SQL phrase: '%s'" % phrase,
const.compile,
)
示例7: add_constraint
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def add_constraint(self, const):
if const._create_rule is None or \
const._create_rule(self):
self._exec(schema.AddConstraint(const))
示例8: add_constraint
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def add_constraint(self, const):
if const._create_rule is None or const._create_rule(self):
self._exec(schema.AddConstraint(const))
示例9: add_foreignkey
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def add_foreignkey(self, fk):
self.connection.execute(AddConstraint(fk))
示例10: _visit_constraint
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def _visit_constraint(self, constraint):
constraint.name = self.get_constraint_name(constraint)
self.append(self.process(AddConstraint(constraint)))
self.execute()
示例11: test_exclude_constraint_min
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_exclude_constraint_min(self):
m = MetaData()
tbl = Table("testtbl", m, Column("room", Integer, primary_key=True))
cons = ExcludeConstraint(("room", "="))
tbl.append_constraint(cons)
self.assert_compile(
schema.AddConstraint(cons),
"ALTER TABLE testtbl ADD EXCLUDE USING gist " "(room WITH =)",
dialect=postgresql.dialect(),
)
示例12: test_exclude_constraint_copy
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_exclude_constraint_copy(self):
m = MetaData()
cons = ExcludeConstraint(("room", "="))
tbl = Table(
"testtbl", m, Column("room", Integer, primary_key=True), cons
)
# apparently you can't copy a ColumnCollectionConstraint until
# after it has been bound to a table...
cons_copy = cons.copy()
tbl.append_constraint(cons_copy)
self.assert_compile(
schema.AddConstraint(cons_copy),
"ALTER TABLE testtbl ADD EXCLUDE USING gist " "(room WITH =)",
)
示例13: test_exclude_constraint_text
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_exclude_constraint_text(self):
m = MetaData()
cons = ExcludeConstraint((text("room::TEXT"), "="))
Table("testtbl", m, Column("room", String), cons)
self.assert_compile(
schema.AddConstraint(cons),
"ALTER TABLE testtbl ADD EXCLUDE USING gist "
"(room::TEXT WITH =)",
)
示例14: test_exclude_constraint_with_using_unusual_conditions
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_exclude_constraint_with_using_unusual_conditions(self):
m = MetaData()
cons = ExcludeConstraint(("q", "="), using="not a keyword")
Table("testtbl", m, Column("q", String), cons)
assert_raises_message(
exc.CompileError,
"Unexpected SQL phrase: 'not a keyword'",
schema.AddConstraint(cons).compile,
dialect=postgresql.dialect(),
)
示例15: test_exclude_constraint_cast
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import AddConstraint [as 别名]
def test_exclude_constraint_cast(self):
m = MetaData()
tbl = Table("testtbl", m, Column("room", String))
cons = ExcludeConstraint((cast(tbl.c.room, Text), "="))
tbl.append_constraint(cons)
self.assert_compile(
schema.AddConstraint(cons),
"ALTER TABLE testtbl ADD EXCLUDE USING gist "
"(CAST(room AS TEXT) WITH =)",
)