Here are the examples of the python api sqlalchemy.sql.select.where taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
33 Examples
3
View Complete Implementation : test_jobs.py
Copyright GNU Affero General Public License v3.0
Author : ckan
Copyright GNU Affero General Public License v3.0
Author : ckan
def get_load_logs(self, task_id):
conn = jobs_db.ENGINE.connect()
logs = jobs_db.LOGS_TABLE
result = conn.execute(select([logs.c.level, logs.c.message])
.where(logs.c.job_id == task_id))
return Logs(result.fetchall())
3
View Complete Implementation : db_ops.py
Copyright GNU General Public License v3.0
Author : deepdivesec
Copyright GNU General Public License v3.0
Author : deepdivesec
def get_recent_hash(self, r_id):
"""Get the hash of the most recent commit."""
cnxn, enxn = self.create_conn()
result = ''
tbl = self.get_table('repo_info', enxn)
stmt = select([tbl.c.repo_latest_commit]).where(tbl.c.repo_id == r_id)
try:
res = cnxn.execute(stmt)
except:
res = 'no commit in db'
for row in res:
result = row[0]
res.close()
return result
3
View Complete Implementation : util.py
Copyright GNU General Public License v3.0
Author : dismantl
Copyright GNU General Public License v3.0
Author : dismantl
def get_detail_loc(case_number):
with db_session() as db:
detail_loc = db.execute(
select([Case.detail_loc])\
.where(Case.case_number == case_number)
).scalar()
return detail_loc
3
View Complete Implementation : portfolio_manager.py
Copyright GNU General Public License v3.0
Author : exdx
Copyright GNU General Public License v3.0
Author : exdx
def get_profit_for_pair(exchange, pair):
"""Iterates through all trades for given exchange pair over the course of trading. Starts by subtracting the long positions (the buys) and adding the short positions (the sells) to arrive at the difference (profit"""
"""The buys are always the even rows and the sells are the odd rows (buy always before sell starting from zero)"""
profit = 0
counter = 0
s = select([database.TradingPositions]).where(and_(database.TradingPositions.c.Exchange == exchange, database.TradingPositions.c.Pair == pair))
result = conn.execute(s)
for row in result:
if counter % 2 == 0:
profit = profit - row[5]
counter += 1
else:
profit = profit + row[5]
counter += 1
return profit
3
View Complete Implementation : portfolio_manager.py
Copyright GNU General Public License v3.0
Author : exdx
Copyright GNU General Public License v3.0
Author : exdx
def get_trades_for_pair_as_df(exchange, pair):
"""Returns all trades for given exchange pair over the course of trading in a dataframe"""
s = select([database.TradingPositions]).where(and_(database.TradingPositions.c.Exchange == exchange, database.TradingPositions.c.Pair == pair))
result = conn.execute(s)
df = pd.DataFrame(result.fetchall())
df.columns = result.keys()
result.close()
return df
3
View Complete Implementation : persist.py
Copyright Apache License 2.0
Author : kelvinguu
Copyright Apache License 2.0
Author : kelvinguu
def contains_batch(self, keys):
if len(keys) == 0: return []
# select all rows matching any of the keys
condition = self._key_conditions(keys)
cmd = select(self._key_cols).where(condition)
# get the set of keys found
with self._transaction() as conn:
result = conn.execute(cmd)
present_keys = set(self._key_orm.from_row(row) for row in result)
return [key in present_keys for key in keys]
3
View Complete Implementation : persist.py
Copyright Apache License 2.0
Author : kelvinguu
Copyright Apache License 2.0
Author : kelvinguu
def get_batch(self, keys):
if len(keys) == 0: return []
key_to_index = {k: i for i, k in enumerate(keys)}
condition = self._key_conditions(keys)
cmd = select([self.table]).where(condition)
with self._transaction() as conn:
results = conn.execute(cmd)
no_result_failure = Failure.silent('No result returned from TableDict.')
vals = [no_result_failure] * len(keys)
for row in results:
key = self._key_orm.from_row(row)
val = self._val_orm.from_row(row)
index = key_to_index[key]
vals[index] = val
return vals
3
View Complete Implementation : corpus.py
Copyright Apache License 2.0
Author : naturalness
Copyright Apache License 2.0
Author : naturalness
@property
def language(self) -> str:
"""
The main laguage of the mined sources.
"""
query = select([meta.c.value]).\
where(meta.c.key == 'language')
try:
result, = self.conn.execute(query)
except ValueError:
raise NewCorpusError
else:
return result[meta.c.value]
3
View Complete Implementation : corpus.py
Copyright Apache License 2.0
Author : naturalness
Copyright Apache License 2.0
Author : naturalness
def get_source(self, filehash: str) -> bytes:
"""
Returns the source code for one file.
"""
query = select([source_file.c.source])\
.where(source_file.c.hash == filehash)
result, = self.conn.execute(query)
return result[source_file.c.source]
3
View Complete Implementation : cache.py
Copyright Apache License 2.0
Author : openeemeter
Copyright Apache License 2.0
Author : openeemeter
def retrieve_json(self, key):
s = select([self.items.c.data]).where(self.items.c.key == key)
result = s.execute()
data = result.fetchone()
if data is None:
return None
else:
return json.loads(data[0])