MCPcopy
hub / github.com/ormar-orm/ormar / run_query

Function run_query

docs_src/queries/docs003.py:33–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31
32@create_drop_database(base_config=ormar_base_config)
33async 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
55asyncio.run(run_query())

Callers 1

docs003.pyFile · 0.70

Calls 3

createMethod · 0.45
update_or_createMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected