本文整理汇总了Python中sqlalchemy.true方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.true方法的具体用法?Python sqlalchemy.true怎么用?Python sqlalchemy.true使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.true方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_join_lateral_w_select_subquery
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_join_lateral_w_select_subquery(self):
table1 = self.tables.people
table2 = self.tables.books
subq = (
select([table2.c.book_id])
.correlate(table1)
.where(table1.c.people_id == table2.c.book_owner_id)
.subquery()
.lateral()
)
stmt = select([table1, subq.c.book_id]).select_from(
table1.join(subq, true())
)
self.assert_compile(
stmt,
"SELECT people.people_id, people.age, people.name, anon_1.book_id "
"FROM people JOIN LATERAL (SELECT books.book_id AS book_id "
"FROM books "
"WHERE people.people_id = books.book_owner_id) AS anon_1 ON true",
)
示例2: test_join_lateral_w_select_implicit_subquery
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_join_lateral_w_select_implicit_subquery(self):
table1 = self.tables.people
table2 = self.tables.books
subq = (
select([table2.c.book_id])
.correlate(table1)
.where(table1.c.people_id == table2.c.book_owner_id)
.lateral()
)
stmt = select([table1, subq.c.book_id]).select_from(
table1.join(subq, true())
)
self.assert_compile(
stmt,
"SELECT people.people_id, people.age, people.name, "
"anon_1.book_id "
"FROM people JOIN LATERAL (SELECT books.book_id AS book_id "
"FROM books "
"WHERE people.people_id = books.book_owner_id) "
"AS anon_1 ON true",
)
示例3: test_true_short_circuit
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_true_short_circuit(self):
t = table("t", column("x"))
self.assert_compile(
select([t]).where(true()),
"SELECT t.x FROM t WHERE 1 = 1",
dialect=default.DefaultDialect(supports_native_boolean=False),
)
self.assert_compile(
select([t]).where(true()),
"SELECT t.x FROM t WHERE true",
dialect=default.DefaultDialect(supports_native_boolean=True),
)
self.assert_compile(
select([t]),
"SELECT t.x FROM t",
dialect=default.DefaultDialect(supports_native_boolean=True),
)
示例4: test_keyed_accessor_composite_keys_precedent
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_keyed_accessor_composite_keys_precedent(self, connection):
keyed1 = self.tables.keyed1
keyed3 = self.tables.keyed3
row = connection.execute(
select([keyed1, keyed3]).select_from(keyed1.join(keyed3, true()))
).first()
eq_(row.q, "c1")
# prior to 1.4 #4887, this raised an "ambiguous column name 'a'""
# message, because "b" is linked to "a" which is a dupe. but we know
# where "b" is in the row by position.
eq_(row.b, "a1")
# "a" is of course ambiguous
assert_raises_message(
exc.InvalidRequestError,
"Ambiguous column name 'a'",
getattr,
row,
"a",
)
eq_(row.d, "d3")
示例5: test_keyed_accessor_composite_labeled
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_keyed_accessor_composite_labeled(self, connection):
keyed1 = self.tables.keyed1
keyed2 = self.tables.keyed2
row = connection.execute(
select([keyed1, keyed2])
.select_from(keyed1.join(keyed2, true()))
.apply_labels()
).first()
eq_(row.keyed1_b, "a1")
eq_(row.keyed1_a, "a1")
eq_(row.keyed1_q, "c1")
eq_(row.keyed1_c, "c1")
eq_(row.keyed2_a, "a2")
eq_(row.keyed2_b, "b2")
assert_raises(KeyError, lambda: row["keyed2_c"])
assert_raises(KeyError, lambda: row["keyed2_q"])
assert_raises(KeyError, lambda: row._mapping["keyed2_c"])
assert_raises(KeyError, lambda: row._mapping["keyed2_q"])
示例6: test_from_function_select_entity_from
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_from_function_select_entity_from(self):
Bookcase = self.classes.Bookcase
s = Session()
subq = s.query(Bookcase).subquery()
srf = lateral(func.generate_series(1, Bookcase.bookcase_shelves))
self.assert_compile(
s.query(Bookcase).select_entity_from(subq).join(srf, true()),
"SELECT anon_1.bookcase_id AS anon_1_bookcase_id, "
"anon_1.bookcase_owner_id AS anon_1_bookcase_owner_id, "
"anon_1.bookcase_shelves AS anon_1_bookcase_shelves, "
"anon_1.bookcase_width AS anon_1_bookcase_width "
"FROM (SELECT bookcases.bookcase_id AS bookcase_id, "
"bookcases.bookcase_owner_id AS bookcase_owner_id, "
"bookcases.bookcase_shelves AS bookcase_shelves, "
"bookcases.bookcase_width AS bookcase_width FROM bookcases) "
"AS anon_1 "
"JOIN LATERAL "
"generate_series(:generate_series_1, anon_1.bookcase_shelves) "
"AS anon_2 ON true",
)
示例7: test_overlap_plain
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_overlap_plain(self):
s = Session()
row = (
s.query(self.classes.Foo, self.classes.Bar)
.join(self.classes.Bar, true())
.all()[0]
)
def go():
eq_(row.Foo.id, 1)
eq_(row.Foo.bar_id, 2)
eq_(row.Bar.id, 3)
# all three columns are loaded independently without
# overlap, no additional SQL to load all attributes
self.assert_sql_count(testing.db, go, 0)
示例8: test_overlap_subquery
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_overlap_subquery(self):
s = Session()
row = (
s.query(self.classes.Foo, self.classes.Bar)
.join(self.classes.Bar, true())
.from_self()
.all()[0]
)
def go():
eq_(row.Foo.id, 1)
eq_(row.Foo.bar_id, 2)
eq_(row.Bar.id, 3)
# all three columns are loaded independently without
# overlap, no additional SQL to load all attributes
self.assert_sql_count(testing.db, go, 0)
示例9: test_nested_future
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_nested_future(self):
User, Address = self.classes.User, self.classes.Address
s = create_session()
stmt = future_select(User, Address).join(Address, true()).limit(2)
eq_(
s.scalar(future_select(func.count()).select_from(stmt.subquery())),
2,
)
stmt = future_select(User, Address).join(Address, true()).limit(100)
eq_(
s.scalar(future_select(func.count()).select_from(stmt.subquery())),
20,
)
stmt = future_select(User, Address).join(Address).limit(100)
eq_(
s.scalar(future_select(func.count()).select_from(stmt.subquery())),
5,
)
示例10: test_cols
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def test_cols(self):
"""test that column-based queries always nest."""
User, Address = self.classes.User, self.classes.Address
s = create_session()
q = s.query(func.count(distinct(User.name)))
eq_(q.count(), 1)
q = s.query(func.count(distinct(User.name))).distinct()
eq_(q.count(), 1)
q = s.query(User.name)
eq_(q.count(), 4)
q = s.query(User.name, Address).join(Address, true())
eq_(q.count(), 20)
q = s.query(Address.user_id)
eq_(q.count(), 5)
eq_(q.distinct().count(), 3)
示例11: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def upgrade():
op.add_column('departments', sa.Column('is_public_assaults_on_officers', sa.Boolean(), server_default=sa.true(), nullable=False))
op.add_column('departments', sa.Column('is_public_citizen_complaints', sa.Boolean(), server_default=sa.true(), nullable=False))
op.add_column('departments', sa.Column('is_public_officer_involved_shootings', sa.Boolean(), server_default=sa.true(), nullable=False))
op.add_column('departments', sa.Column('is_public_use_of_force_incidents', sa.Boolean(), server_default=sa.true(), nullable=False))
示例12: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('departments', sa.Column('is_public', sa.Boolean(), server_default=sa.true(), nullable=False))
### end Alembic commands ###
示例13: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def upgrade():
alembic.op.add_column('users',
sqlalchemy.Column('stream_delay', sqlalchemy.Integer, nullable=False, server_default='10')
)
alembic.op.add_column('users',
sqlalchemy.Column('chat_timestamps', sqlalchemy.Integer, nullable=False, server_default='0')
)
alembic.op.add_column('users',
sqlalchemy.Column('chat_timestamps_24hr', sqlalchemy.Boolean, nullable=False, server_default=sqlalchemy.true())
)
alembic.op.add_column('users',
sqlalchemy.Column('chat_timestamps_secs', sqlalchemy.Boolean, nullable=False, server_default=sqlalchemy.false())
)
示例14: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def upgrade(): # noqa: D103
columns_and_constraints = [
sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
sa.Column("resource_version", sa.String(255))
]
conn = op.get_bind()
# alembic creates an invalid SQL for mssql and mysql dialects
if conn.dialect.name in {"mysql"}:
columns_and_constraints.append(
sa.CheckConstraint("one_row_id<>0", name="kube_resource_version_one_row_id")
)
elif conn.dialect.name not in {"mssql"}:
columns_and_constraints.append(
sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id")
)
table = op.create_table(
RESOURCE_TABLE,
*columns_and_constraints
)
op.bulk_insert(table, [
{"resource_version": ""}
])
示例15: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import true [as 别名]
def upgrade(): # noqa: D103
columns_and_constraints = [
sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
sa.Column("worker_uuid", sa.String(255))
]
conn = op.get_bind()
# alembic creates an invalid SQL for mssql and mysql dialects
if conn.dialect.name in {"mysql"}:
columns_and_constraints.append(
sa.CheckConstraint("one_row_id<>0", name="kube_worker_one_row_id")
)
elif conn.dialect.name not in {"mssql"}:
columns_and_constraints.append(
sa.CheckConstraint("one_row_id", name="kube_worker_one_row_id")
)
table = op.create_table(
RESOURCE_TABLE,
*columns_and_constraints
)
op.bulk_insert(table, [
{"worker_uuid": ""}
])