本文整理汇总了Python中sqlalchemy.literal_column方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.literal_column方法的具体用法?Python sqlalchemy.literal_column怎么用?Python sqlalchemy.literal_column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.literal_column方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_version
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def _update_version(self, from_, to_):
assert to_ not in self.heads
self.heads.remove(from_)
self.heads.add(to_)
ret = self.context.impl._exec(
self.context._version.update()
.values(version_num=literal_column("'%s'" % to_))
.where(
self.context._version.c.version_num
== literal_column("'%s'" % from_)
)
)
if (
not self.context.as_sql
and self.context.dialect.supports_sane_rowcount
and ret.rowcount != 1
):
raise util.CommandError(
"Online migration expected to match one "
"row when updating '%s' to '%s' in '%s'; "
"%d found"
% (from_, to_, self.context.version_table, ret.rowcount)
)
示例2: define_tables
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def define_tables(cls, metadata):
Table('autoinc_pk', metadata,
Column('id', Integer, primary_key=True,
test_needs_autoincrement=True),
Column('data', String(50))
)
Table('manual_pk', metadata,
Column('id', Integer, primary_key=True, autoincrement=False),
Column('data', String(50))
)
Table('includes_defaults', metadata,
Column('id', Integer, primary_key=True,
test_needs_autoincrement=True),
Column('data', String(50)),
Column('x', Integer, default=5),
Column('y', Integer,
default=literal_column("2", type_=Integer) + literal(2)))
示例3: _delete_version
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def _delete_version(self, version):
self.heads.remove(version)
ret = self.context.impl._exec(
self.context._version.delete().where(
self.context._version.c.version_num
== literal_column("'%s'" % version)
)
)
if (
not self.context.as_sql
and self.context.dialect.supports_sane_rowcount
and ret.rowcount != 1
):
raise util.CommandError(
"Online migration expected to match one "
"row when deleting '%s' in '%s'; "
"%d found"
% (version, self.context.version_table, ret.rowcount)
)
示例4: test_simple_limit_expression_offset_using_window
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_simple_limit_expression_offset_using_window(self):
t = table("t", column("x", Integer), column("y", Integer))
s = (
select([t])
.where(t.c.x == 5)
.order_by(t.c.y)
.limit(10)
.offset(literal_column("20"))
)
self.assert_compile(
s,
"SELECT anon_1.x, anon_1.y "
"FROM (SELECT t.x AS x, t.y AS y, "
"ROW_NUMBER() OVER (ORDER BY t.y) AS mssql_rn "
"FROM t "
"WHERE t.x = :x_1) AS anon_1 "
"WHERE mssql_rn > 20 AND mssql_rn <= :param_1 + 20",
checkparams={"param_1": 10, "x_1": 5},
)
示例5: test_correlated_select
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_correlated_select(self):
s = select(
[literal_column("*")], t1.c.col1 == t2.c.col1, from_obj=[t1, t2]
).correlate(t2)
class Vis(CloningVisitor):
def visit_select(self, select):
select.where.non_generative(select, t1.c.col2 == 7)
self.assert_compile(
select([t2]).where(
t2.c.col1 == Vis().traverse(s).scalar_subquery()
),
"SELECT table2.col1, table2.col2, table2.col3 "
"FROM table2 WHERE table2.col1 = "
"(SELECT * FROM table1 WHERE table1.col1 = table2.col1 "
"AND table1.col2 = :col2_1)",
)
示例6: test_select_setup_joins_adapt_element_two
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_select_setup_joins_adapt_element_two(self):
s = future_select(literal_column("1")).join_from(
t1, t2, t1.c.col1 == t2.c.col2
)
t1a = t1.alias()
s2 = sql_util.ClauseAdapter(t1a).traverse(s)
self.assert_compile(
s, "SELECT 1 FROM table1 JOIN table2 ON table1.col1 = table2.col2"
)
self.assert_compile(
s2,
"SELECT 1 FROM table1 AS table1_1 "
"JOIN table2 ON table1_1.col1 = table2.col2",
)
示例7: test_table_to_alias_5
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_table_to_alias_5(self):
t1alias = t1.alias("t1alias")
vis = sql_util.ClauseAdapter(t1alias)
self.assert_compile(
select([t1alias, t2]).where(
t1alias.c.col1
== vis.traverse(
select(
[literal_column("*")],
t1.c.col1 == t2.c.col2,
from_obj=[t1, t2],
)
.correlate(t1)
.scalar_subquery()
)
),
"SELECT t1alias.col1, t1alias.col2, t1alias.col3, "
"table2.col1, table2.col2, table2.col3 "
"FROM table1 AS t1alias, table2 WHERE t1alias.col1 = "
"(SELECT * FROM table2 WHERE t1alias.col1 = table2.col2)",
)
示例8: test_table_to_alias_6
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_table_to_alias_6(self):
t1alias = t1.alias("t1alias")
vis = sql_util.ClauseAdapter(t1alias)
self.assert_compile(
select([t1alias, t2]).where(
t1alias.c.col1
== vis.traverse(
select(
[literal_column("*")],
t1.c.col1 == t2.c.col2,
from_obj=[t1, t2],
)
.correlate(t2)
.scalar_subquery()
)
),
"SELECT t1alias.col1, t1alias.col2, t1alias.col3, "
"table2.col1, table2.col2, table2.col3 "
"FROM table1 AS t1alias, table2 "
"WHERE t1alias.col1 = "
"(SELECT * FROM table1 AS t1alias "
"WHERE t1alias.col1 = table2.col2)",
)
示例9: test_implicitly_boolean
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_implicitly_boolean(self):
# test for expressions that the database always considers as boolean
# even if there is no boolean datatype.
assert not self.table1.c.myid._is_implicitly_boolean
assert (self.table1.c.myid == 5)._is_implicitly_boolean
assert (self.table1.c.myid == 5).self_group()._is_implicitly_boolean
assert (self.table1.c.myid == 5).label("x")._is_implicitly_boolean
assert not_(self.table1.c.myid == 5)._is_implicitly_boolean
assert or_(
self.table1.c.myid == 5, self.table1.c.myid == 7
)._is_implicitly_boolean
assert not column("x", Boolean)._is_implicitly_boolean
assert not (self.table1.c.myid + 5)._is_implicitly_boolean
assert not not_(column("x", Boolean))._is_implicitly_boolean
assert (
not select([self.table1.c.myid])
.scalar_subquery()
._is_implicitly_boolean
)
assert not text("x = y")._is_implicitly_boolean
assert not literal_column("x = y")._is_implicitly_boolean
示例10: test_select_composition_six
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_select_composition_six(self):
# test that "auto-labeling of subquery columns"
# doesn't interfere with literal columns,
# exported columns don't get quoted.
# [ticket:4730] refines this but for the moment the behavior with
# no columns is being maintained.
self.assert_compile(
select(
[
literal_column("column1 AS foobar"),
literal_column("column2 AS hoho"),
table1.c.myid,
],
from_obj=[table1],
)
.subquery()
.select(),
"SELECT anon_1.column1 AS foobar, anon_1.column2 AS hoho, "
"anon_1.myid FROM "
"(SELECT column1 AS foobar, column2 AS hoho, "
"mytable.myid AS myid FROM mytable) AS anon_1",
)
示例11: test_text_in_select_nonfrom
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_text_in_select_nonfrom(self):
generate_series = text(
"generate_series(:x, :y, :z) as s(a)"
).bindparams(x=None, y=None, z=None)
s = select(
[(func.current_date() + literal_column("s.a")).label("dates")]
).select_from(generate_series)
self.assert_compile(
s,
"SELECT CURRENT_DATE + s.a AS dates FROM "
"generate_series(:x, :y, :z) as s(a)",
checkparams={"y": None, "x": None, "z": None},
)
self.assert_compile(
s.params(x=5, y=6, z=7),
"SELECT CURRENT_DATE + s.a AS dates FROM "
"generate_series(:x, :y, :z) as s(a)",
checkparams={"y": 6, "x": 5, "z": 7},
)
示例12: test_cache_key_limit_offset_values
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_cache_key_limit_offset_values(self):
s1 = select([column("q")]).limit(10)
s2 = select([column("q")]).limit(25)
s3 = select([column("q")]).limit(25).offset(5)
s4 = select([column("q")]).limit(25).offset(18)
s5 = select([column("q")]).limit(7).offset(12)
s6 = select([column("q")]).limit(literal_column("q")).offset(12)
for should_eq_left, should_eq_right in [(s1, s2), (s3, s4), (s3, s5)]:
eq_(
should_eq_left._generate_cache_key().key,
should_eq_right._generate_cache_key().key,
)
for shouldnt_eq_left, shouldnt_eq_right in [
(s1, s3),
(s5, s6),
(s2, s3),
]:
ne_(
shouldnt_eq_left._generate_cache_key().key,
shouldnt_eq_right._generate_cache_key().key,
)
示例13: test_limit_offset_no_int_coercion_two
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_limit_offset_no_int_coercion_two(self):
exp1 = literal_column("Q")
exp2 = literal_column("Y")
sel = select([1]).limit(exp1).offset(exp2)
assert_raises_message(
exc.CompileError,
"This SELECT structure does not use a simple integer "
"value for limit",
getattr,
sel,
"_limit",
)
assert_raises_message(
exc.CompileError,
"This SELECT structure does not use a simple integer "
"value for offset",
getattr,
sel,
"_offset",
)
示例14: test_keys_anon_labels
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def test_keys_anon_labels(self, connection):
"""test [ticket:3483]"""
users = self.tables.users
connection.execute(users.insert(), user_id=1, user_name="foo")
result = connection.execute(
select(
[
users.c.user_id,
users.c.user_name.label(None),
func.count(literal_column("1")),
]
).group_by(users.c.user_id, users.c.user_name)
)
eq_(result.keys(), ["user_id", "user_name_1", "count_1"])
row = result.first()
eq_(row._fields, ("user_id", "user_name_1", "count_1"))
eq_(list(row._mapping.keys()), ["user_id", "user_name_1", "count_1"])
示例15: getgroups
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import literal_column [as 别名]
def getgroups(grouplist):
groupfuture=[]
print "getgroups"
for groupid in grouplist:
if isinstance(groupid,basestring) and groupid.startswith("https"):
groupfuture.append(session.get(str(groupid)))
else:
groupfuture.append(session.get(grouplookupurl.format(groupid)))
badlist=[]
pbar = tqdm(total=len(grouplist))
for groupdata in as_completed(groupfuture):
if groupdata.result().status_code==200:
itemjson=groupdata.result().json()
item=itemjson.get('group_id')
if int(item) in sdegrouplist:
try:
connection.execute(invGroups.update().where(invGroups.c.groupID == literal_column(str(item))),
groupID=item,
groupName=itemjson['name'],
categoryID=itemjson.get('category_id',None),
published=itemjson.get('published',False),
)
except:
pass
else:
connection.execute(invGroups.insert(),
groupID=item,
groupName=itemjson['name'],
categoryID=itemjson.get('category_id',None),
published=itemjson.get('published',False),
)
else:
badlist.append(groupdata.result().url)
print groupdata.result().url
pbar.update(1)
return badlist