File: save_with_session.py

package info (click to toggle)
python-odmantic 1.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,640 kB
  • sloc: python: 8,547; sh: 37; makefile: 34; xml: 13; javascript: 3
file content (23 lines) | stat: -rw-r--r-- 498 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from odmantic import SyncEngine, Model


class Player(Model):
    name: str
    game: str


engine = SyncEngine()

leeroy = Player(name="Leeroy Jenkins", game="World of Warcraft")

with engine.session() as session:
    session.save_all(
        [
            Player(name="Shroud", game="Counter-Strike"),
            Player(name="Serral", game="Starcraft"),
            Player(name="TLO", game="Starcraft"),
        ]
    )
    player_count = session.count(Player)
    print(player_count)
    #> 3