本文整理汇总了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,)],
)
示例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))"
)
示例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]),
)
示例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]),
)