()
| 31 | |
| 32 | @create_drop_database(base_config=ormar_base_config) |
| 33 | async def run_query(): |
| 34 | await Book.objects.create( |
| 35 | title="Tom Sawyer", author="Twain, Mark", genre="Adventure" |
| 36 | ) |
| 37 | await Book.objects.create( |
| 38 | title="War and Peace", author="Tolstoy, Leo", genre="Fiction" |
| 39 | ) |
| 40 | await Book.objects.create( |
| 41 | title="Anna Karenina", author="Tolstoy, Leo", genre="Fiction" |
| 42 | ) |
| 43 | |
| 44 | # if not exist the instance will be persisted in db |
| 45 | vol2 = await Book.objects.update_or_create( |
| 46 | title="Volume II", author="Anonymous", genre="Fiction" |
| 47 | ) |
| 48 | assert await Book.objects.count() == 4 |
| 49 | |
| 50 | # if pk or pkname passed in kwargs (like id here) the object will be updated |
| 51 | assert await Book.objects.update_or_create(id=vol2.id, genre="Historic") |
| 52 | assert await Book.objects.count() == 4 |
| 53 | |
| 54 | |
| 55 | asyncio.run(run_query()) |
no test coverage detected