Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client): rename Client to Prisma #267

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -144,3 +144,5 @@ src/prisma/generator/debug-params.json

# OS files
.DS_Store
# .scratchpad/
.dmypy.json
30 changes: 15 additions & 15 deletions README.md
Expand Up @@ -167,20 +167,20 @@ The simplest asynchronous Prisma Client Python application will either look some

```py
import asyncio
from prisma import Client
from prisma import Prisma

async def main() -> None:
client = Client()
await client.connect()
conn = Prisma()
await conn.connect()

# write your queries here
user = await client.user.create(
user = await conn.user.create(
data={
'name': 'Robert',
}.
)

await client.disconnect()
await conn.disconnect()

if __name__ == '__main__':
asyncio.run(main())
Expand All @@ -190,13 +190,13 @@ or like this:

```py
import asyncio
from prisma import Client, register
from prisma import Prisma, register
from prisma.models import User

async def main() -> None:
client = Client()
conn = Prisma()
register(client)
await client.connect()
await conn.connect()

# write your queries here
user = await User.prisma().create(
Expand All @@ -205,7 +205,7 @@ async def main() -> None:
}.
)

await client.disconnect()
await conn.disconnect()

if __name__ == '__main__':
asyncio.run(main())
Expand All @@ -220,13 +220,13 @@ All query methods return [pydantic models](https://pydantic-docs.helpmanual.io/u
**Retrieve all `User` records from the database**

```py
users = await client.user.find_many()
users = await conn.user.find_many()
```

**Include the `posts` relation on each returned `User` object**

```py
users = await client.user.find_many(
users = await conn.user.find_many(
include={
'posts': True,
},
Expand All @@ -236,7 +236,7 @@ users = await client.user.find_many(
**Retrieve all `Post` records that contain `"prisma"`**

```py
posts = await client.post.find_many(
posts = await conn.post.find_many(
where={
'OR': [
{'title': {'contains': 'prisma'}},
Expand All @@ -249,7 +249,7 @@ posts = await client.post.find_many(
**Create a new `User` and a new `Post` record in the same query**

```py
user = await client.user.create(
user = await conn.user.create(
data={
'name': 'Robert',
'email': 'robert@craigie.dev',
Expand All @@ -265,7 +265,7 @@ user = await client.user.create(
**Update an existing `Post` record**

```py
post = await client.post.update(
post = await conn.post.update(
where={
'id': 42,
},
Expand Down Expand Up @@ -297,7 +297,7 @@ Supported editors / extensions:
- Sublime Text with [LSP-Pyright](https://github.com/sublimelsp/LSP-pyright) v1.1.96 or higher

```py
user = await client.user.find_first(
user = await conn.user.find_first(
where={
'|'
}
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/contributing.md
Expand Up @@ -141,7 +141,7 @@ To add a test case find the appropriate test file in the `tests` directory (if n

```py
import pytest
from prisma import Client
from prisma import Prisma

@pytest.mark.asyncio
async def test_example(client: Client) -> None:
Expand Down
16 changes: 8 additions & 8 deletions docs/getting_started/advanced.md
Expand Up @@ -42,13 +42,13 @@ prisma generate
In order to create comments, we can either create a post, and then connect that post when creating a comment or create a post while creating the comment.

```py
post = await client.post.create({
post = await conn.post.create({
'title': 'My new post',
'published': True,
})
print(f'post: {post.json(indent=2)}\n')

first = await client.comment.create({
first = await conn.comment.create({
'content': 'First comment',
'post': {
'connect': {
Expand All @@ -58,7 +58,7 @@ first = await client.comment.create({
})
print(f'first comment: {first.json(indent=2)}\n')

second = await client.comment.create({
second = await conn.comment.create({
'content': 'Second comment',
'post': {
'connect': {
Expand All @@ -71,7 +71,7 @@ print(f'second comment: {second.json(indent=2)}\n')

??? note "Alternative method"
```py
first = await client.comment.create(
first = await conn.comment.create(
data={
'content': 'First comment',
'post': {
Expand All @@ -83,7 +83,7 @@ print(f'second comment: {second.json(indent=2)}\n')
},
include={'post': True}
)
second = await client.comment.create({
second = await conn.comment.create({
'content': 'Second comment',
'post': {
'connect': {
Expand All @@ -97,15 +97,15 @@ Now that a post and comments have been created, you can query for them as follow

```py
# find all comments on a post
comments = await client.comments.find_many({
comments = await conn.comments.find_many({
'where': {
'post_id': post.id
}
})
print(f'comments of post with id {post.id}: {json.dumps(comments, indent=2)}')

# find at most 3 comments on a post
filtered = await client.comments.find_many({
filtered = await conn.comments.find_many({
'where': {
'post_id': post.id
},
Expand All @@ -119,7 +119,7 @@ few of their comments in just a few lines and with full type-safety:

```py
# fetch a post and 3 of it's comments
post = await client.post.find_unique(
post = await conn.post.find_unique(
where={
'id': post.id,
},
Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started/partial-types.md
Expand Up @@ -90,7 +90,7 @@ One situation where partial types are particularly useful is in FastAPI endpoint

```py
from typing import Optional
from prisma.client import Client
from prisma import Prisma
from prisma.partials import UserWithoutRelations
from fastapi import FastAPI, Depends
from .utils import get_db
Expand All @@ -110,7 +110,7 @@ or for making raw queries type safe
```py
from prisma.partials import UserInLogin

user = await client.query_first(
user = await conn.query_first(
'SELECT name, email FROM User WHERE id = ?',
'abc',
model=UserInLogin,
Expand Down
18 changes: 9 additions & 9 deletions docs/getting_started/setup.md
@@ -1,6 +1,6 @@
# Setup

As Prisma Client Python supports generating both async and non-async clients, there is some differences required when generating the client.
As Prisma Client Python supports generating both async and non-async clients, there is some differences required when generating the conn.

## Installing

Expand All @@ -27,15 +27,15 @@ The minimum code required to get starting using asyncio:

```py
import asyncio
from prisma import Client
from prisma import Prisma

async def main() -> None:
client = Client()
await client.connect()
conn = Prisma()
await conn.connect()

# write your queries here

await client.disconnect()
await conn.disconnect()

if __name__ == '__main__':
asyncio.run(main())
Expand All @@ -57,15 +57,15 @@ generator client {
The minimum code required to get starting using a synchronous client:

```py
from prisma import Client
from prisma import Prisma

def main() -> None:
client = Client()
client.connect()
conn = Prisma()
conn.connect()

# write your queries here

client.disconnect()
conn.disconnect()

if __name__ == '__main__':
main()
Expand Down
30 changes: 15 additions & 15 deletions docs/index.md
Expand Up @@ -167,20 +167,20 @@ The simplest asynchronous Prisma Client Python application will either look some

```py
import asyncio
from prisma import Client
from prisma import Prisma

async def main() -> None:
client = Client()
await client.connect()
conn = Prisma()
await conn.connect()

# write your queries here
user = await client.user.create(
user = await conn.user.create(
data={
'name': 'Robert',
}.
)

await client.disconnect()
await conn.disconnect()

if __name__ == '__main__':
asyncio.run(main())
Expand All @@ -190,13 +190,13 @@ or like this:

```py
import asyncio
from prisma import Client, register
from prisma import Prisma, register
from prisma.models import User

async def main() -> None:
client = Client()
conn = Prisma()
register(client)
await client.connect()
await conn.connect()

# write your queries here
user = await User.prisma().create(
Expand All @@ -205,7 +205,7 @@ async def main() -> None:
}.
)

await client.disconnect()
await conn.disconnect()

if __name__ == '__main__':
asyncio.run(main())
Expand All @@ -220,13 +220,13 @@ All query methods return [pydantic models](https://pydantic-docs.helpmanual.io/u
**Retrieve all `User` records from the database**

```py
users = await client.user.find_many()
users = await conn.user.find_many()
```

**Include the `posts` relation on each returned `User` object**

```py
users = await client.user.find_many(
users = await conn.user.find_many(
include={
'posts': True,
},
Expand All @@ -236,7 +236,7 @@ users = await client.user.find_many(
**Retrieve all `Post` records that contain `"prisma"`**

```py
posts = await client.post.find_many(
posts = await conn.post.find_many(
where={
'OR': [
{'title': {'contains': 'prisma'}},
Expand All @@ -249,7 +249,7 @@ posts = await client.post.find_many(
**Create a new `User` and a new `Post` record in the same query**

```py
user = await client.user.create(
user = await conn.user.create(
data={
'name': 'Robert',
'email': 'robert@craigie.dev',
Expand All @@ -265,7 +265,7 @@ user = await client.user.create(
**Update an existing `Post` record**

```py
post = await client.post.update(
post = await conn.post.update(
where={
'id': 42,
},
Expand Down Expand Up @@ -297,7 +297,7 @@ Supported editors / extensions:
- Sublime Text with [LSP-Pyright](https://github.com/sublimelsp/LSP-pyright) v1.1.96 or higher

```py
user = await client.user.find_first(
user = await conn.user.find_first(
where={
'|'
}
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/batching.md
Expand Up @@ -9,13 +9,13 @@ Queries are not executed until `commit()` is called or the context manager exits
## Examples

```py
async with client.batch_() as batcher:
async with conn.batch_() as batcher:
batcher.user.create({'name': 'Robert'})
batcher.user.create({'name': 'Tegan'})
```

```py
batcher = client.batch_()
batcher = conn.batch_()
batcher.user.create({'name': 'Robert'})
batcher.user.create({'name': 'Tegan'})
await batcher.commit()
Expand Down