本文整理匯總了Python中pony.orm.select方法的典型用法代碼示例。如果您正苦於以下問題:Python orm.select方法的具體用法?Python orm.select怎麽用?Python orm.select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pony.orm
的用法示例。
在下文中一共展示了orm.select方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def main():
config_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path.home() / '.config' / 'whereisit.toml'
with open(config_path) as f:
config = toml.load(f)
import logging
logging.getLogger('aiohttp.client').setLevel(logging.ERROR)
db_path = Path.home() / '.local' / 'share' / config['database']['path']
orm.sql_debug(config['database'].get('debug', False))
database.bind("sqlite", str(db_path), create_db=True)
database.generate_mapping(create_tables=True)
with orm.db_session():
orm.select(t for t in database.Tracking
if t.id not in list(config['trackings'].keys())).delete(bulk=True)
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
with contextlib.closing(asyncio.get_event_loop()) as loop:
tracker = Tracker(loop=loop, db=database, config=config)
loop.create_task(tracker.run())
loop.run_forever()
示例2: test_common_pony
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def test_common_pony():
db = orm.Database()
class Account(db.Entity):
name = orm.Required(str)
msgn_id = orm.Required(int)
auth_code = orm.Required(str)
db.bind('sqlite', ':memory:', create_db=True)
db.generate_mapping(create_tables=True)
orm.sql_debug(True)
@orm.db_session
def test():
Account(name="haje01", msgn_id=3498, auth_code="1234")
a = Account(name="haje02", msgn_id=2345, auth_code="1234")
assert len(orm.select(a for a in Account)) == 2
assert len(orm.select(a for a in Account if a.msgn_id == 2345)) == 1
a.delete()
assert len(orm.select(a for a in Account)) == 1
test()
示例3: get_table
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def get_table(self, group):
championship_id = self.championship.id
stage = self.id
championship = self.championship
pwinner = championship.points_winner
ploser = championship.points_loser
pdraw = championship.points_draw
result = db.select("""SELECT * FROM positions_table
WHERE championship=$championship_id and
stage=$stage and `group`=$group
ORDER BY pg * $pwinner + pp * $ploser + pe * $pdraw DESC,
gf - gc DESC, gf DESC, gc ASC
""")
for r in result:
team, championship, stage, group, pg, pp, pe, gf, gc = r
yield (
Team[team],
pg, pe, pp,
gf, gc,
pg*pwinner + pp*ploser + pe*pdraw
)
示例4: get_logged_account_link
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def get_logged_account_link(target_id):
al = orm.select(a for a in AccountLink if a.id == target_id)[:]
if len(al) > 0:
return al[0]
示例5: _handle_postback_msg
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def _handle_postback_msg(self, postback, sender_id, results):
"""Handle postback message.
Note: It is important to verify the postback is valid.
Does it have valid token?
Didn't it already processed?
"""
need_handle = False
payload = json.loads(postback['payload'])
if 'token' not in payload:
# predefined button payload
need_handle = True
else:
# app defined button payload
token = payload['token']
pid = payload['id']
pts = PostbackToken.select(lambda t: t.value == token)[:]
if len(pts) == 0:
self.logger.error("Invalid postback: payload '{}'".format(payload))
res = "Invalid postback."
pt = pts[0]
if pt.close_dt is not None:
res = "The choice is not valid anymore."
else:
# set done time
pt.close_dt = datetime.fromtimestamp(time.time())
need_handle = True
if need_handle:
res = self.app.evth.handle_postback(postback)
if res is not None:
self.send_message(sender_id, res)
results.append(res)
return True
示例6: get_tweets
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def get_tweets():
return orm.select(t for t in Tweet)[:].show()
示例7: validate_player
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def validate_player(team, player, number):
error = ""
if player in team.players:
error = "El jugador ya se encuentra registrado en el equipo."
elif player.team:
error = "El jugador ya pertenece a otro equipo."
elif team.players.select(lambda player: player.number == number):
error = "El número {} ya está ocupado.".format(number)
if error:
raise FbcmError(error)
示例8: get_match
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def get_match(championship, stage, group, round, match):
return select(
m
for c in Championship
for s in c.stages
for m in s.matches
if (c.id == championship and
s.id == stage and
m.id == match and
m.group == group and
m.round == round)
).first()
示例9: players
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def players():
players = Player.select()
form = PlayerForm()
return render_template(
'players.html',
players=players,
form=form
)
示例10: teams
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def teams():
return render_template(
'teams.html',
teams=Team.select(),
form=TeamForm()
)
示例11: championships
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def championships():
return render_template(
'championships.html',
championships=Championship.select(),
form=ChampionshipForm()
)
示例12: stages
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def stages(championship_id):
stage_id = int(request.args.get('stage', '0'))
group = int(request.args.get('group', '1'))
stage = Stage.get(
id=stage_id,
championship=championship_id
)
if not stage:
abort(404)
if not (0 < group <= stage.num_groups):
abort(404)
return render_template(
"stage.html",
stage=stage,
group=group,
stages=Stage.select(
lambda s: s.championship.id == championship_id
).prefetch(
Championship
).order_by(
lambda stage: stage.id
)
)
示例13: goal
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def goal(championship, stage, group, round, match):
player = request.form['player']
team = request.form['team']
team_match = select(
tm
for c in Championship
for s in c.stages
for m in s.matches
for tm in m.team_matches
if (c.id == championship and
s.id == stage and
m.id == match and
m.group == group and
m.round == round and
tm.team.team == Team[team])
).first()
team_match.goals.create(
player=player
)
return redirect(url_for(
'match',
championship=championship,
stage=stage,
group=group,
round=round,
match=match
))
示例14: state
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def state(self):
stage = self.stages.select(lambda stage: stage.id == 0)[:1][0]
if stage.matches.is_empty():
return "not_started"
else:
return (
"finished"
if all(s.is_finish for s in self.stages)
else "started"
)
示例15: top_players
# 需要導入模塊: from pony import orm [as 別名]
# 或者: from pony.orm import select [as 別名]
def top_players(self):
return select(
(p, orm.count(g.id))
for p in Player
for g in Goal
if g.team_match.team.championship.id == self.id
and g.player == p
).order_by(orm.desc(2)).limit(10)