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


Python func.abs方法代碼示例

本文整理匯總了Python中sqlalchemy.func.abs方法的典型用法代碼示例。如果您正苦於以下問題:Python func.abs方法的具體用法?Python func.abs怎麽用?Python func.abs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.func的用法示例。


在下文中一共展示了func.abs方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_expression_with_function_default

# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import abs [as 別名]
def test_expression_with_function_default(self):
        t = Table(
            "t",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("x", Integer(), server_default=func.abs(-5) + 17),
        )
        t.create(testing.db)
        with testing.db.connect() as conn:
            conn.execute(t.insert())
            conn.execute(t.insert().values(x=35))
            eq_(
                conn.execute(select([t.c.x]).order_by(t.c.id)).fetchall(),
                [(22,), (35,)],
            ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:17,代碼來源:test_sqlite.py

示例2: test_column_defaults_ddl

# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import abs [as 別名]
def test_column_defaults_ddl(self):

        t = Table(
            "t",
            MetaData(),
            Column(
                "x",
                Boolean(create_constraint=True),
                server_default=sql.false(),
            ),
        )

        self.assert_compile(
            CreateTable(t),
            "CREATE TABLE t (x BOOLEAN DEFAULT (0), CHECK (x IN (0, 1)))",
        )

        t = Table(
            "t",
            MetaData(),
            Column("x", String(), server_default=func.sqlite_version()),
        )
        self.assert_compile(
            CreateTable(t),
            "CREATE TABLE t (x VARCHAR DEFAULT (sqlite_version()))",
        )

        t = Table(
            "t",
            MetaData(),
            Column("x", Integer(), server_default=func.abs(-5) + 17),
        )
        self.assert_compile(
            CreateTable(t), "CREATE TABLE t (x INTEGER DEFAULT (abs(-5) + 17))"
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:37,代碼來源:test_sqlite.py

示例3: test_indexes

# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import abs [as 別名]
def test_indexes(self):
        meta = MetaData()

        table = Table(
            "mytable",
            meta,
            Column("id", Integer, primary_key=True),
            Column("data1", Integer, index=True),
            Column("data2", Integer),
            Index("text", text("data1 + 1")),
        )
        Index("multi", table.c.data1, table.c.data2)
        Index("func", func.abs(table.c.data1))
        Index("multi-func", table.c.data1, func.abs(table.c.data2))

        meta2 = MetaData()
        table_c = table.to_metadata(meta2)

        def _get_key(i):
            return (
                [i.name, i.unique]
                + sorted(i.kwargs.items())
                + [str(col) for col in i.expressions]
            )

        eq_(
            sorted([_get_key(i) for i in table.indexes]),
            sorted([_get_key(i) for i in table_c.indexes]),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:31,代碼來源:test_metadata.py

示例4: test_indexes_with_col_redefine

# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import abs [as 別名]
def test_indexes_with_col_redefine(self):
        meta = MetaData()

        table = Table(
            "mytable",
            meta,
            Column("id", Integer, primary_key=True),
            Column("data1", Integer),
            Column("data2", Integer),
            Index("text", text("data1 + 1")),
        )
        Index("multi", table.c.data1, table.c.data2)
        Index("func", func.abs(table.c.data1))
        Index("multi-func", table.c.data1, func.abs(table.c.data2))

        table = Table(
            "mytable",
            meta,
            Column("data1", Integer),
            Column("data2", Integer),
            extend_existing=True,
        )

        meta2 = MetaData()
        table_c = table.to_metadata(meta2)

        def _get_key(i):
            return (
                [i.name, i.unique]
                + sorted(i.kwargs.items())
                + [str(col) for col in i.expressions]
            )

        eq_(
            sorted([_get_key(i) for i in table.indexes]),
            sorted([_get_key(i) for i in table_c.indexes]),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:39,代碼來源:test_metadata.py


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