本文整理汇总了Python中sqlalchemy.sql.column函数的典型用法代码示例。如果您正苦于以下问题:Python column函数的具体用法?Python column怎么用?Python column使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了column函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_annotate_fromlist_preservation
def test_annotate_fromlist_preservation(self):
"""test the FROM list in select still works
even when multiple annotate runs have created
copies of the same selectable
#2453, continued
"""
table1 = table('table1', column('x'))
table2 = table('table2', column('y'))
a1 = table1.alias()
s = select([a1.c.x]).select_from(
a1.join(table2, a1.c.x==table2.c.y)
)
assert_s = select([select([s])])
for fn in (
sql_util._deep_deannotate,
lambda s: sql_util._deep_annotate(s, {'foo':'bar'}),
lambda s:visitors.cloned_traverse(s, {}, {}),
lambda s:visitors.replacement_traverse(s, {}, lambda x:None)
):
sel = fn(select([fn(select([fn(s)]))]))
eq_(str(assert_s), str(sel))
示例2: _insert_operation_operation_form
def _insert_operation_operation_form():
tb = table(
'operation_operation_form',
column('operation_id', Integer),
column('operation_form_id', Integer))
columns = ('operation_id', 'operation_form_id')
data = [
(3022, 39),#normalize
(3022, 40),
(3022, 41),
(3022, 43),
(3022, 110),
(3022, 3022),
(3012, 39),#feature-indexer'
(3012, 40),
(3012, 41),
(3012, 43),
(3012, 110),
(3012,3012),
]
rows = [dict(zip(columns, row)) for row in data]
op.bulk_insert(tb, rows)
示例3: _insert_operation_operation_form
def _insert_operation_operation_form():
tb = table(
'operation_operation_form',
column('operation_id', Integer),
column('operation_form_id', Integer))
columns = [c.name for c in tb.columns]
data = [
[REGRESSION_MODEL, 102],
[ISOTONIC_REGRESSION, 103],
[AFT_SURVIVAL_REGRESSION, 104],
[GBT_REGRESSOR, 105],
[RANDOM_FOREST_REGRESSOR, 106],
[GENERALIZED_LINEAR_REGRESSOR, 107],
[REGRESSION_MODEL, 41],
[ISOTONIC_REGRESSION, 41],
[AFT_SURVIVAL_REGRESSION, 41],
[GBT_REGRESSOR, 41],
[RANDOM_FOREST_REGRESSOR, 41],
[GENERALIZED_LINEAR_REGRESSOR, 41],
]
rows = [dict(zip(columns, row)) for row in data]
op.bulk_insert(tb, rows)
示例4: _insert_operation_form_translation
def _insert_operation_form_translation():
tb = table(
'operation_form_translation',
column('id', Integer),
column('locale', String),
column('name', String))
columns = ('id', 'locale', 'name')
data = [
(3024, 'en', 'Execution'),
(3024, 'pt', 'Execução'),
(3025, 'en', 'Execution'),
(3025, 'pt', 'Execução'),
(3026, 'en', 'Execution'),
(3026, 'pt', 'Execução'),
(3027, 'en', 'Execution'),
(3027, 'pt', 'Execução'),
(3028, 'en', 'Execution'),
(3028, 'pt', 'Execução'),
(3029, 'en', 'Execution'),
(3029, 'pt', 'Execução'),
(3030, 'en', 'Execution'),
(3030, 'pt', 'Execução'),
(3031, 'en', 'Execution'),
(3031, 'pt', 'Execução'),
]
rows = [dict(zip(columns, row)) for row in data]
op.bulk_insert(tb, rows)
示例5: test_limit_offset_with_correlated_order_by
def test_limit_offset_with_correlated_order_by(self):
t1 = table('t1', column('x', Integer), column('y', Integer))
t2 = table('t2', column('x', Integer), column('y', Integer))
order_by = select([t2.c.y]).where(t1.c.x == t2.c.x).as_scalar()
s = select([t1]).where(t1.c.x == 5).order_by(order_by) \
.limit(10).offset(20)
self.assert_compile(
s,
"SELECT anon_1.x, anon_1.y "
"FROM (SELECT t1.x AS x, t1.y AS y, "
"ROW_NUMBER() OVER (ORDER BY "
"(SELECT t2.y FROM t2 WHERE t1.x = t2.x)"
") AS mssql_rn "
"FROM t1 "
"WHERE t1.x = :x_1) AS anon_1 "
"WHERE mssql_rn > :param_1 AND mssql_rn <= :param_2 + :param_1",
checkparams={'param_1': 20, 'param_2': 10, 'x_1': 5}
)
c = s.compile(dialect=mssql.MSDialect())
eq_(len(c._result_columns), 2)
assert t1.c.x in set(c._create_result_map()['x'][1])
assert t1.c.y in set(c._create_result_map()['y'][1])
示例6: test_annotations
def test_annotations(self):
"""test that annotated clause constructs use the
decorated class' compiler.
"""
t1 = table('t1', column('c1'), column('c2'))
dispatch = Select._compiler_dispatch
try:
@compiles(Select)
def compile(element, compiler, **kw):
return "OVERRIDE"
s1 = select([t1])
self.assert_compile(
s1, "OVERRIDE"
)
self.assert_compile(
s1._annotate({}),
"OVERRIDE"
)
finally:
Select._compiler_dispatch = dispatch
if hasattr(Select, '_compiler_dispatcher'):
del Select._compiler_dispatcher
示例7: test_cube_operators
def test_cube_operators(self):
t = table('t', column('value'),
column('x'), column('y'), column('z'), column('q'))
stmt = select([func.sum(t.c.value)])
self.assert_compile(
stmt.group_by(func.cube(t.c.x, t.c.y)),
"SELECT sum(t.value) AS sum_1 FROM t GROUP BY CUBE(t.x, t.y)"
)
self.assert_compile(
stmt.group_by(func.rollup(t.c.x, t.c.y)),
"SELECT sum(t.value) AS sum_1 FROM t GROUP BY ROLLUP(t.x, t.y)"
)
self.assert_compile(
stmt.group_by(
func.grouping_sets(t.c.x, t.c.y)
),
"SELECT sum(t.value) AS sum_1 FROM t "
"GROUP BY GROUPING SETS(t.x, t.y)"
)
self.assert_compile(
stmt.group_by(
func.grouping_sets(
sql.tuple_(t.c.x, t.c.y),
sql.tuple_(t.c.z, t.c.q),
)
),
"SELECT sum(t.value) AS sum_1 FROM t GROUP BY "
"GROUPING SETS((t.x, t.y), (t.z, t.q))"
)
示例8: test_noorderby_parameters_insubquery
def test_noorderby_parameters_insubquery(self):
"""test that the ms-sql dialect does not include ORDER BY
positional parameters in subqueries"""
table1 = table(
"mytable",
column("myid", Integer),
column("name", String),
column("description", String),
)
q = select(
[table1.c.myid, sql.literal('bar').label('c1')],
order_by=[table1.c.name + '-']
).alias("foo")
crit = q.c.myid == table1.c.myid
dialect = mssql.dialect()
dialect.paramstyle = "qmark"
dialect.positional = True
self.assert_compile(
select(["*"], crit),
"SELECT * FROM (SELECT mytable.myid AS "
"myid, ? AS c1 FROM mytable) AS foo, mytable WHERE "
"foo.myid = mytable.myid",
dialect=dialect,
checkparams={'param_1': 'bar'},
# if name_1 is included, too many parameters are passed to dbapi
checkpositional=('bar', )
)
示例9: test_insert_returning
def test_insert_returning(self):
table1 = table(
"mytable",
column("myid", Integer),
column("name", String(128)),
column("description", String(128)),
)
i = insert(table1, values=dict(name="foo")).returning(
table1.c.myid, table1.c.name
)
self.assert_compile(
i,
"INSERT INTO mytable (name) OUTPUT "
"inserted.myid, inserted.name VALUES "
"(:name)",
)
i = insert(table1, values=dict(name="foo")).returning(table1)
self.assert_compile(
i,
"INSERT INTO mytable (name) OUTPUT "
"inserted.myid, inserted.name, "
"inserted.description VALUES (:name)",
)
i = insert(table1, values=dict(name="foo")).returning(
func.length(table1.c.name)
)
self.assert_compile(
i,
"INSERT INTO mytable (name) OUTPUT "
"LEN(inserted.name) AS length_1 VALUES "
"(:name)",
)
示例10: upgrade
def upgrade():
### commands auto generated by Alembic ###
op.create_table('employees_attendance',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('attendanceDate', sa.Date(), nullable=False),
sa.Column('arriveTime', sa.Time(), nullable=False),
sa.Column('leaveTime', sa.Time(), nullable=False),
sa.Column('employee_id', sa.Integer(), nullable=False),
sa.Column('createdBy_id', sa.Integer(), nullable=True),
sa.Column('issueDateTime', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['createdBy_id'], ['users.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['employee_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
abilities_table = table('abilities',
column('id', Integer),
column('name', String),
)
op.bulk_insert(abilities_table,
[
{'name': "employeeAttendances.list"},
{'name': "employeeAttendances.show"},
{'name': "employeeAttendances.delete"},
{'name': "employeeAttendances.update"},
{'name': "employeeAttendances.create"},
{'name': "feedbacks.list"},
{'name': "feedbacks.show"}
]
)
示例11: test_delete_extra_froms
def test_delete_extra_froms(self):
t1 = table("t1", column("c1"))
t2 = table("t2", column("c1"))
q = sql.delete(t1).where(t1.c.c1 == t2.c.c1)
self.assert_compile(
q, "DELETE FROM t1 FROM t1, t2 WHERE t1.c1 = t2.c1"
)
示例12: genericize_thread
def genericize_thread():
class Thread_(Base):
__table__ = Base.metadata.tables['thread']
# Get data from columns-to-be-dropped
with session_scope() as db_session:
results = db_session.query(Thread_.id, Thread_.g_thrid).all()
to_insert = [dict(id=r[0], g_thrid=r[1]) for r in results]
# Add new columns
op.add_column('thread', sa.Column('type', sa.String(16)))
# Create new table, insert data
# The table
op.create_table('imapthread',
sa.Column('g_thrid', sa.BigInteger(), nullable=True,
index=True),
sa.Column('id', sa.Integer()),
sa.ForeignKeyConstraint(['id'], ['thread.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'))
# The ad-hoc table for insert
table_ = table('imapthread',
column('g_thrid', sa.BigInteger),
column('id', sa.Integer))
if to_insert:
op.bulk_insert(table_, to_insert)
# Drop columns now
op.drop_column('thread', 'g_thrid')
示例13: genericize_imapaccount
def genericize_imapaccount():
class ImapAccount_(Base):
__table__ = Base.metadata.tables['imapaccount']
# Get data from columns-to-be-dropped
with session_scope() as db_session:
results = db_session.query(ImapAccount_.id,
ImapAccount_.imap_host).all()
to_insert = [dict(id=r[0], imap_host=r[1]) for r in results]
# Rename table, add new columns.
op.rename_table('imapaccount', 'account')
op.add_column('account', sa.Column('type', sa.String(16)))
# Create new table, insert data
# The table
op.create_table('imapaccount',
sa.Column('imap_host', sa.String(512)),
sa.Column('id', sa.Integer()),
sa.ForeignKeyConstraint(['id'], ['account.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'))
# The ad-hoc table for insert
table_ = table('imapaccount',
column('imap_host', sa.String()),
column('id', sa.Integer))
if to_insert:
op.bulk_insert(table_, to_insert)
# Drop columns now
op.drop_column('account', 'imap_host')
示例14: downgrade_imapthread
def downgrade_imapthread():
class ImapThread_(Base):
__table__ = Base.metadata.tables['imapthread']
# Get data from table-to-be-dropped
with session_scope() as db_session:
results = db_session.query(ImapThread_.id, ImapThread_.g_thrid).all()
to_insert = [dict(id=r[0], g_thrid=r[1]) for r in results]
# Drop columns, add new columns + insert data
op.drop_column('thread', 'type')
op.add_column('thread', sa.Column('g_thrid', sa.BigInteger(),
nullable=True, index=True))
table_ = table('thread',
column('g_thrid', sa.BigInteger),
column('id', sa.Integer))
for r in to_insert:
op.execute(
table_.update().
where(table_.c.id == r['id']).
values({'g_thrid': r['g_thrid']})
)
# Drop table
op.drop_table('imapthread')
示例15: _by_search_tsearch
def _by_search_tsearch(self, query, operand, maybe_negate):
# type: (Query, str, ConditionTransform) -> Query
tsquery = func.plainto_tsquery(literal("zulip.english_us_search"), literal(operand))
ts_locs_array = func.ts_match_locs_array
query = query.column(ts_locs_array(literal("zulip.english_us_search"),
column("rendered_content"),
tsquery).label("content_matches"))
# We HTML-escape the subject in Postgres to avoid doing a server round-trip
query = query.column(ts_locs_array(literal("zulip.english_us_search"),
func.escape_html(column("subject")),
tsquery).label("subject_matches"))
# Do quoted string matching. We really want phrase
# search here so we can ignore punctuation and do
# stemming, but there isn't a standard phrase search
# mechanism in Postgres
for term in re.findall('"[^"]+"|\S+', operand):
if term[0] == '"' and term[-1] == '"':
term = term[1:-1]
term = '%' + connection.ops.prep_for_like_query(term) + '%'
cond = or_(column("content").ilike(term),
column("subject").ilike(term))
query = query.where(maybe_negate(cond))
cond = column("search_tsvector").op("@@")(tsquery)
return query.where(maybe_negate(cond))