-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): add create_many action method
closes #8
- Loading branch information
1 parent
6d7ff25
commit cc2872c
Showing
14 changed files
with
1,115 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pytest | ||
from prisma import Client | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_many(client: Client) -> None: | ||
async with client.batch_() as batcher: | ||
batcher.user.create({'name': 'Robert'}) | ||
batcher.user.create({'name': 'Tegan'}) | ||
|
||
assert await client.user.count() == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
import prisma | ||
from prisma import Client | ||
from prisma.enums import Role | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_many(client: Client) -> None: | ||
total = await client.user.create_many( | ||
[{'name': 'Robert', 'role': Role.ADMIN}, {'name': 'Tegan'}] | ||
) | ||
assert total == 2 | ||
|
||
user = await client.user.find_first(where={'name': 'Robert'}) | ||
assert user is not None | ||
assert user.name == 'Robert' | ||
assert user.role == Role.ADMIN | ||
|
||
assert await client.user.count() == 2 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_skip_duplicates(client: Client) -> None: | ||
user = await client.user.create({'name': 'Robert'}) | ||
|
||
with pytest.raises(prisma.errors.UniqueViolationError) as exc: | ||
await client.user.create_many([{'id': user.id, 'name': 'Robert 2'}]) | ||
|
||
assert exc.match(r'Unique constraint failed on the fields: \(`id`\)') | ||
|
||
count = await client.user.create_many( | ||
[{'id': user.id, 'name': 'Robert 2'}, {'name': 'Tegan'}], skip_duplicates=True | ||
) | ||
assert count == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.