Skip to content

Commit

Permalink
rename Photon to Prisma Client JS
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Jan 15, 2020
1 parent 94a8d11 commit cfdc0fe
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 62 deletions.
10 changes: 5 additions & 5 deletions docs/photon/migrating-from-sequelize.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ app.use(bodyParser.json())
const prisma = new PrismaClient()

app.get('/users', async (req, res) => {
const users = await photon.users.findMany()
const users = await prisma.users.findMany()
res.json(users)
})

Expand Down Expand Up @@ -518,7 +518,7 @@ So to implement the same route and endpoint in your Prisma Client JS project, go
//...
app.get(`/users/:id`, async (req, res) => {
const { id } = req.params
const user = await photon.users.findOne({
const user = await prisma.users.findOne({
where: {
id: Number(id),
},
Expand Down Expand Up @@ -550,7 +550,7 @@ To implement the same route and endpoint in your Prisma Client JS project, go to
//...
app.post(`/tasks`, async (req, res) => {
const { title } = req.body
const post = await photon.tasks.create({
const post = await prisma.tasks.create({
data: {
title,
},
Expand Down Expand Up @@ -582,7 +582,7 @@ To implement the same route and endpoint in your Prisma Client JS project, go to
//...
app.delete(`/tasks/:id`, async (req, res) => {
const { id } = req.params
const task = await photon.tasks.delete({
const task = await prisma.tasks.delete({
where: {
id: Number(id),
},
Expand Down Expand Up @@ -621,7 +621,7 @@ The sample project that was used demonstrated the fundamental capabilities of bo

## Next steps

- Learn more about [Photon's relation API](https://github.com/prisma/prisma2/blob/master/docs/photon/api.md#relations)
- Learn more about [Prisma Client JS' relation API](https://github.com/prisma/prisma2/blob/master/docs/photon/api.md#relations)
- Engage with our [community](https://www.prisma.io/community/)!
- The Prisma Framework is not production-ready [yet](https://github.com/prisma/prisma2/blob/master/docs/limitations.md), so we value your [feedback](https://github.com/prisma/prisma2/blob/master/docs/prisma2-feedback.md)!

Expand Down
10 changes: 5 additions & 5 deletions docs/photon/migrating-from-typeorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ npm install @prisma/client
npm install prisma2 --save-dev
```

### Migrating to the Photon constructor
### Migrating to the `PrismaClient` constructor

Make sure you are in your `photonjs_app` project directory. Then, in your terminal, run:

Expand Down Expand Up @@ -392,7 +392,7 @@ app.use(bodyParser.json())
const prisma = new PrismaClient()

app.get('/posts', async (req, res) => {
const posts = await photon.posts.findMany()
const posts = await prisma.posts.findMany()
res.send(posts)
})

Expand Down Expand Up @@ -430,7 +430,7 @@ So to implement the same route and endpoint in your Prisma Client JS project, go
//...
app.get(`/posts/:id`, async (req, res) => {
const { id } = req.params
const post = await photon.posts.findOne({
const post = await prisma.posts.findOne({
where: {
id: Number(id),
},
Expand Down Expand Up @@ -459,7 +459,7 @@ To implement the same route and endpoint in your Prisma Client JS project, go to
//...
app.post(`/posts`, async (req, res) => {
const { text, title } = req.body
const post = await photon.posts.create({
const post = await prisma.posts.create({
data: {
text,
title,
Expand Down Expand Up @@ -488,7 +488,7 @@ To implement the same route and endpoint in your Prisma Client JS project, go to
//...
app.delete(`/posts/:id`, async (req, res) => {
const { id } = req.params
const post = await photon.posts.delete({
const post = await prisma.posts.delete({
where: {
id: Number(id),
},
Expand Down
20 changes: 10 additions & 10 deletions docs/photon/use-only-photon.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Using only Photon (without Lift)
# Using only Prisma Client JS (without Lift)

You can use Photon as an ORM in your application without using Lift for database migrations. This is useful for _existing applications_ when there already is a working migration system or when you don't have the rights inside your organization to perform database migrations yourself.
You can use Prisma Client JS as an ORM replacement in your application without using Lift for database migrations. This is useful for _existing applications_ when there already is a working migration system or when you don't have the rights inside your organization to perform database migrations yourself.

When using Photon without Lift, you obtain your data model definition by _introspecting_ your database schema and generating the Prisma data model from it. The generated data model then serves as foundation for Photon's generated CRUD API. Whenever a schema migration is performed on the database afterwards, you need to re-introspect your database (which updates your data model) and re-generate your Prisma Client JS API.
When using Prisma Client JS without Lift, you obtain your data model definition by _introspecting_ your database schema and generating the Prisma data model from it. The generated data model then serves as foundation for Prisma Client JS's generated CRUD API. Whenever a schema migration is performed on the database afterwards, you need to re-introspect your database (which updates your data model) and re-generate your Prisma Client JS API.

**This page is about using Photon with an existing database**. Learn more about getting started from scratch with Photon and Lift [here](./).
**This page is about using Prisma Client JS with an existing database**. Learn more about getting started from scratch with Prisma Client JS and Lift [here](./).

## Getting started with Photon
## Getting started with Prisma Client JS

### 1. Set up project using `prisma2 init`

Expand All @@ -26,7 +26,7 @@ Then follow the interactive prompt:
- MongoDB (coming soon)
1. Provide your database credentials ([more info](#database-credentials))
1. Select the database (MySQL) or schema (PostgreSQL) to introspect
1. Select **Only Photon** (i.e. uncheck Lift using <kbd>SPACE</kbd>)
1. Select **Only Prisma Client** (i.e. uncheck Lift using <kbd>SPACE</kbd>)
1. Select your programming language
- **JavaScript**
- **TypeScript**
Expand All @@ -41,9 +41,9 @@ Once you're done with the interactive prompt, the CLI sets out for 3 major tasks

Plus, if you've selected a boilerplate to get started, it downloads the boilerplate code and configures it to connect to your database and match the generated data model.

### 2. Integrate Photon in your application
### 2. Integrate Prisma Client JS in your application

To start using Photon in your application, you first need to install it as an npm dependecy:
To start using Prisma Client JS in your application, you first need to install it as an npm dependecy:

```
npm install @prisma/client
Expand Down Expand Up @@ -73,7 +73,7 @@ model _customers {
By default, the generated API is based the model and fields names, e.g.:

```ts
await photon._customers.findMany({
await prisma._customers.findMany({
where: { number_of_orders: 5 }
})
```
Expand All @@ -90,7 +90,7 @@ model Customer @@map(name: "_customers") {
After running another `prisma2 generate`, your Prisma Client JS API now looks as follows:

```ts
await photon.customers.findMany({
await prisma.customers.findMany({
where: { orderCount: 5 }
})
```
Expand Down
2 changes: 1 addition & 1 deletion docs/prisma-schema-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ generator js {
generator js_custom_output {
provider = "prisma-client-js"
output = "../src/generated/photon"
output = "../src/generated/client"
}
generator ts {
Expand Down
22 changes: 11 additions & 11 deletions docs/relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ The fluent API lets you _fluently_ traverse the relations of your models via fun
This request returns all posts by a specific user:

```ts
const postsByUser: Post[] = await photon.users
const postsByUser: Post[] = await prisma.users
.findOne({ where: { email: 'ada@prisma.io' } })
.posts()
```

This request returns all categories by a specific post:

```ts
const categoriesOfPost: Category[] = await photon.posts
const categoriesOfPost: Category[] = await prisma.posts
.findOne({ where: { id: 1 } })
.categories()
```
Expand All @@ -362,7 +362,7 @@ While the Fluent API allows you to write chainable queries, sometimes you may wa
You can also rewrite the query like this:

```ts
const postsByUser: Post[] = await photon.posts.findMany({
const postsByUser: Post[] = await prisma.posts.findMany({
where: {
author: { id: author.id },
},
Expand Down Expand Up @@ -408,7 +408,7 @@ Here are some examples of nested writes:
```ts
// Create a new user with two posts in a
// single transaction
const newUser: User = await photon.users.create({
const newUser: User = await prisma.users.create({
data: {
email: 'alice@prisma.io',
posts: {
Expand All @@ -423,7 +423,7 @@ const newUser: User = await photon.users.create({

```ts
// Change the author of a post in a single transaction
const updatedPost: Post = await photon.posts.update({
const updatedPost: Post = await prisma.posts.update({
where: { id: 5424 },
data: {
author: {
Expand All @@ -435,7 +435,7 @@ const updatedPost: Post = await photon.posts.update({

```ts
// Remove the author from an existing post in a single transaction
const post: Post = await photon.posts.update({
const post: Post = await prisma.posts.update({
data: {
author: { disconnect: true },
},
Expand Down Expand Up @@ -478,7 +478,7 @@ Because there are circular relations between `User`, `Post` and `Comment`, you c
```ts
// Create a new post, connect to an existing user and create new,
// comments, users and posts in deeply nested operations
const post = await photon.posts.create({
const post = await prisma.posts.create({
data: {
author: {
connect: {
Expand Down Expand Up @@ -529,7 +529,7 @@ You can eagerly load relations on a model via `select` and `include` (learn more
```ts
// The returned post objects will only have the `id` and
// `author` property which carries the respective user object
const allPosts = await photon.posts.findMany({
const allPosts = await prisma.posts.findMany({
select: {
id: true,
author: true,
Expand All @@ -540,7 +540,7 @@ const allPosts = await photon.posts.findMany({
```ts
// The returned posts objects will have all scalar fields of the `Post` model
// and additionally all the categories for each post
const allPosts = await photon.posts.findMany({
const allPosts = await prisma.posts.findMany({
include: {
categories: true,
},
Expand All @@ -550,7 +550,7 @@ const allPosts = await photon.posts.findMany({
```ts
// The returned objects will have all scalar fields of the `User` model
// and additionally all the posts with their authors with their posts
await photon.users.findMany({
await prisma.users.findMany({
include: {
posts: {
include: {
Expand All @@ -572,7 +572,7 @@ A relation filter is a filter operation that's applied to a related object of a
```ts
// Retrieve all posts of a particular user
// that start with "Hello"
const posts: Post[] = await photon.users
const posts: Post[] = await prisma.users
.findOne({
where: { email: 'ada@prisma.io' },
})
Expand Down
14 changes: 7 additions & 7 deletions docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Here are examples for nested writes in the Prisma Client JS API:
```ts
// Create a new user with two posts in a
// single transaction
const newUser: User = await photon.users.create({
const newUser: User = await prisma.users.create({
data: {
email: 'alice@prisma.io',
posts: {
Expand All @@ -41,7 +41,7 @@ const newUser: User = await photon.users.create({

```ts
// Change the author of a post in a single transaction
const updatedPost: Post = await photon.posts.update({
const updatedPost: Post = await prisma.posts.update({
where: { id: 42 },
data: {
author: {
Expand All @@ -61,16 +61,16 @@ Transactions are a commonly used feature in relational as well as non-relational
The first use case of sending multiple operations in bulk could be implemented with an API similar to this:

```ts
const write1 = photon.users.create()
const write2 = photon.orders.create()
const write3 = photon.invoices.create()
const write1 = prisma.users.create()
const write2 = prisma.orders.create()
const write3 = prisma.invoices.create()

await prisma.transaction([write1, write2, write3])
```

Instead of immediately awaiting the result of each operation when it's performed, the operation itself is stored in a variable first which later is submitted to the database via a method called `transaction`. Photon will ensure that either all three `create`-operations or none of them succeed.
Instead of immediately awaiting the result of each operation when it's performed, the operation itself is stored in a variable first which later is submitted to the database via a method called `transaction`. Prisma Client JS will ensure that either all three `create`-operations or none of them succeed.

The second use case of longer-running transactions where operations can depend on each other is a bit more involved. Photon would need to expose a _transaction API_ which enables developers to initiate and commit a transaction themselves while Photon takes care of ensuring the safety guarantees associated with transactions. It could look similar to this:
The second use case of longer-running transactions where operations can depend on each other is a bit more involved. Prisma Client JS would need to expose a _transaction API_ which enables developers to initiate and commit a transaction themselves while Prisma Client JS takes care of ensuring the safety guarantees associated with transactions. It could look similar to this:

```ts
prisma.transaction(async tx => {
Expand Down
28 changes: 14 additions & 14 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The `prisma2 init`-wizard created the following directory structure:
hello-prisma2
├── node_modules
│ └── @prisma
│ └── photon
│ └── client
├── package.json
├── prisma
│ ├── migrations
Expand Down Expand Up @@ -285,7 +285,7 @@ const prisma = new PrismaClient()
// A `main` function so that we can use async/await
async function main() {
// Seed the database with users and posts
const user1 = await photon.users.create({
const user1 = await prisma.users.create({
data: {
email: 'alice@prisma.io',
name: 'Alice',
Expand All @@ -301,7 +301,7 @@ async function main() {
posts: true,
},
})
const user2 = await photon.users.create({
const user2 = await prisma.users.create({
data: {
email: 'bob@prisma.io',
name: 'Bob',
Expand All @@ -327,13 +327,13 @@ async function main() {
console.log(`Created users: ${user1.name} (${user1.posts.length} post) and (${user2.posts.length} posts) `)

// Retrieve all published posts
const allPosts = await photon.posts.findMany({
const allPosts = await prisma.posts.findMany({
where: { published: true },
})
console.log(`Retrieved all published posts: `, allPosts)

// Create a new post (written by an already existing user with email alice@prisma.io)
const newPost = await photon.posts.create({
const newPost = await prisma.posts.create({
data: {
title: 'Join the Prisma Slack community',
content: 'http://slack.prisma.io',
Expand All @@ -348,7 +348,7 @@ async function main() {
console.log(`Created a new post: `, newPost)

// Publish the new post
const updatedPost = await photon.posts.update({
const updatedPost = await prisma.posts.update({
where: {
id: newPost.id,
},
Expand All @@ -359,7 +359,7 @@ async function main() {
console.log(`Published the newly created post: `, updatedPost)

// Retrieve all posts by user with email alice@prisma.io
const postsByUser = await photon.users
const postsByUser = await prisma.users
.findOne({
where: {
email: 'alice@prisma.io',
Expand All @@ -372,19 +372,19 @@ async function main() {
main()
.catch(e => console.error(e))
.finally(async () => {
await photon.disconnect()
await prisma.disconnect()
})
```

Here's a quick rundown of what's happening in the code:

1. Create two users named _Alice_ and _Bob_ using `photon.users.create(...)`
1. Create two users named _Alice_ and _Bob_ using `prisma.users.create(...)`
- _Alice_ has one post titled _Watch the talks from Prisma Day 2019_
- _Bob_ has two posts titled _Subscribe to GraphQL Weekly for community news_ and _Follow Prisma on Twitter_
1. Retrieve all _published_ posts using `photon.posts.findMany(...)`
1. Retrieve all _published_ posts using `prisma.posts.findMany(...)`
1. Create a new post titled _Join the Prisma Slack community_ connected to the user _Alice_ by her email address
1. Publish _Alice_'s newly created post using `photon.posts.update(...)`
1. Retrieve all posts by _Alice_ using `photon.users.findOne(...).posts()`
1. Publish _Alice_'s newly created post using `prisma.posts.update(...)`
1. Retrieve all posts by _Alice_ using `prisma.users.findOne(...).posts()`

Notice that the result of each of these operations is printed to the console using `console.log`.

Expand Down Expand Up @@ -474,7 +474,7 @@ Be sure to **save the file**. As you save it, you can observe your terminal wind
Since the Prisma Client JS API has been updated, you can now update the code in `script.ts` to create new categories and connect them to existing (or new) posts. As an example, this code snippet would create a new category called "prisma" and connect it to two existing posts:

```ts
const category = await photon.categories.create({
const category = await prisma.categories.create({
data: {
name: "prisma",
posts: {
Expand Down Expand Up @@ -527,7 +527,7 @@ hello-prisma2
├── README.md
├── node_modules
│ ├── @prisma
│ │ └── photon
│ │ └── client
├── package-lock.json
├── package.json
├── prisma
Expand Down

0 comments on commit cfdc0fe

Please sign in to comment.