當前位置: 首頁>>代碼示例>>Python>>正文


Python schema.AddConstraint方法代碼示例

本文整理匯總了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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:26,代碼來源:test_compiler.py

示例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))",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:24,代碼來源:test_compiler.py

示例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"
            ")",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:24,代碼來源:test_constraints.py

示例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",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:18,代碼來源:test_constraints.py

示例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" ")",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:22,代碼來源:test_constraints.py

示例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,
                ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:24,代碼來源:test_compiler.py

示例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)) 
開發者ID:jpush,項目名稱:jbox,代碼行數:6,代碼來源:impl.py

示例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)) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:5,代碼來源:impl.py

示例9: add_foreignkey

# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import AddConstraint [as 別名]
def add_foreignkey(self, fk):
        self.connection.execute(AddConstraint(fk)) 
開發者ID:gltn,項目名稱:stdm,代碼行數:4,代碼來源:ansisql.py

示例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() 
開發者ID:gltn,項目名稱:stdm,代碼行數:6,代碼來源:ansisql.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:12,代碼來源:test_compiler.py

示例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 =)",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:16,代碼來源:test_compiler.py

示例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 =)",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:11,代碼來源:test_compiler.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:12,代碼來源:test_compiler.py

示例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 =)",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:12,代碼來源:test_compiler.py


注:本文中的sqlalchemy.schema.AddConstraint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。