Here are the examples of the python api sqlalchemy.func.max taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
58 Examples
3
View Complete Implementation : finance.py
Copyright Apache License 2.0
Author : agdsn
Copyright Apache License 2.0
Author : agdsn
@hybrid_property
def last_imported_at(self):
return object_session(self).execute(
select([func.max(BankAccountActivity.imported_at)])
.where(BankAccountActivity.bank_account_id == self.id)
).fetchone()[0]
3
View Complete Implementation : blocks.py
Copyright Apache License 2.0
Author : analyseether
Copyright Apache License 2.0
Author : analyseether
@clastmethod
def get_max_block_number(cls):
current_session = get_current_session()
with current_session.db_session_scope():
max_block_number = current_session.db_session.query(
func.max(cls.block_number)).scalar()
return max_block_number
3
View Complete Implementation : computer.py
Copyright Apache License 2.0
Author : catalyst-team
Copyright Apache License 2.0
Author : catalyst-team
def all_with_last_activtiy(self):
query = self.query(Computer, func.max(Docker.last_activity)). \
join(Docker, Docker.computer == Computer.name). \
group_by(Computer.name)
res = []
for c, a in query.all():
c.last_activity = a
res.append(c)
return res
3
View Complete Implementation : project.py
Copyright Apache License 2.0
Author : catalyst-team
Copyright Apache License 2.0
Author : catalyst-team
def all_last_activity(self):
query = self.query(Project,
func.max(Task.last_activity)). \
join(Dag, Dag.project == Project.id, isouter=True). \
join(Task, isouter=True). \
group_by(Project.id)
res = query.all()
for p, last_activity in res:
p.last_activity = last_activity
return [r[0] for r in res]
3
View Complete Implementation : api.py
Copyright GNU Affero General Public License v3.0
Author : cloudbase
Copyright GNU Affero General Public License v3.0
Author : cloudbase
@enginefacade.writer
def add_replica_tasks_execution(context, execution):
if is_user_context(context):
if execution.action.project_id != context.tenant:
raise exception.NotAuthorized()
# include deleted records
max_number = _model_query(
context, func.max(models.TasksExecution.number)).filter_by(
action_id=execution.action.id).first()[0] or 0
execution.number = max_number + 1
context.session.add(execution)
3
View Complete Implementation : twitter.py
Copyright MIT License
Author : csvance
Copyright MIT License
Author : csvance
def __init__(self, credentials: TwitterApiCredentials, screen_name: str):
self._credentials = credentials
self.screen_name = screen_name
self.session = Session()
row = self.session.query(func.max(Tweet.status_id)).first()
if row is not None:
since_id = row[0] if row[0] is not None else 0
else:
since_id = 0
self._latest_tweet_processed_id = since_id
self.scraper_status = self.session.query(ScraperStatus).filter(
ScraperStatus.screen_name == self.screen_name).first()
if self.scraper_status is None:
self.scraper_status = ScraperStatus(screen_name=screen_name, since_id=since_id)
self.session.add(self.scraper_status)
self.session.commit()
3
View Complete Implementation : headers_repository.py
Copyright MIT License
Author : gdassori
Copyright MIT License
Author : gdassori
def get_best_blockhash(self) -> str:
session = self.session()
_id = session.query(func.max(database.Header.id)).one_or_none()
best_header = _id and session.query(database.Header).filter_by(id=_id[0]).one_or_none()
best_blockhash = best_header and best_header.blockhash
return best_blockhash and binascii.hexlify(best_blockhash).decode()
3
View Complete Implementation : blocks.py
Copyright Apache License 2.0
Author : grin-pool
Copyright Apache License 2.0
Author : grin-pool
@clastmethod
def get_latest(cls, n=None):
highest = database.db.getSession().query(func.max(Blocks.height)).scalar()
if n == None:
return database.db.getSession().query(Blocks).filter(Blocks.height == highest).first()
else:
return list(database.db.getSession().query(Blocks).filter(Blocks.height >= highest-n).order_by(asc(Blocks.height)))
3
View Complete Implementation : grin_stats.py
Copyright Apache License 2.0
Author : grin-pool
Copyright Apache License 2.0
Author : grin-pool
@clastmethod
def get_latest(cls, range=None):
highest = database.db.getSession().query(func.max(Grin_stats.height)).scalar()
if range == None:
return database.db.getSession().query(Grin_stats).filter(Grin_stats.height == highest).first()
else:
h_start = highest-(range-1)
return list(database.db.getSession().query(Grin_stats).filter(Grin_stats.height >= h_start).order_by(asc(Grin_stats.height)))
3
View Complete Implementation : pool_blocks.py
Copyright Apache License 2.0
Author : grin-pool
Copyright Apache License 2.0
Author : grin-pool
@clastmethod
def get_latest(cls, n=None, id=None):
highest = database.db.getSession().query(func.max(Pool_blocks.height)).scalar()
if n is None:
if id is None:
return database.db.getSession().query(Pool_blocks).filter(Pool_blocks.height == highest).first()
else:
return database.db.getSession().query(Pool_blocks).filter(and_(Pool_blocks.height == highest, Pool_blocks.found_by == id)).first()
else:
if id is None:
return list(database.db.getSession().query(Pool_blocks).filter(Pool_blocks.height >= highest-n).order_by(asc(Pool_blocks.height)))
else:
return list(database.db.getSession().query(Pool_blocks).filter(and_(Pool_blocks.height >= highest-n, Pool_blocks.found_by == id)).order_by(asc(Pool_blocks.height)))