๐Ÿ“ฆ aminalaee / mongox

๐Ÿ“„ basic.py ยท 33 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33import asyncio

import mongox


client = mongox.Client(
    "mongodb://localhost:27017", get_event_loop=asyncio.get_running_loop
)
db = client.get_database("test_db")


class Movie(mongox.Model, db=db):
    name: str
    year: int = mongox.Field(gt=1800, lt=2050)


async def main():
    await Movie(name="Forrest Gump", year=1994).insert()

    movie = await Movie.query(Movie.name == "Forrest Gump").get()

    print(movie)

    movie.year = 1993
    movie = await movie.save()

    print(movie)

    await movie.delete()


asyncio.run(main())