Skip to content

Commit 4e0ea97

Browse files
update
1 parent 3bf085d commit 4e0ea97

91 files changed

Lines changed: 545 additions & 317 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

content/200-orm/050-overview/100-introduction/100-what-is-prisma.mdx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ Every project that uses a tool from the Prisma ORM toolkit starts with a [Prisma
4141
```prisma
4242
datasource db {
4343
provider = "postgresql"
44-
url = env("DATABASE_URL")
4544
}
4645
4746
generator client {
48-
provider = "prisma-client-js"
47+
provider = "prisma-client"
48+
output = "./generated"
4949
}
5050
5151
model Post {
@@ -101,10 +101,35 @@ model User {
101101
102102
In this schema, you configure three things:
103103

104-
- **Data source**: Specifies your database connection (via an environment variable)
104+
- **Data source**: Specifies your database connection. Database connection URLs are configured in `prisma.config.ts`.
105105
- **Generator**: Indicates that you want to generate Prisma Client
106106
- **Data model**: Defines your application models
107107

108+
### Configuring database connections
109+
110+
Database connection URLs are configured in a `prisma.config.ts` file. Create a `prisma.config.ts` file in your project root:
111+
112+
```ts file=prisma.config.ts
113+
import { defineConfig, env } from 'prisma/config'
114+
115+
export default defineConfig({
116+
schema: 'prisma/schema.prisma',
117+
migrations: {
118+
path: 'prisma/migrations',
119+
seed: 'tsx ./prisma/seed.ts',
120+
},
121+
datasource: {
122+
url: env('DATABASE_URL'),
123+
},
124+
})
125+
```
126+
127+
<Admonition type="info">
128+
129+
**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell.
130+
131+
</Admonition>
132+
108133
### The Prisma schema data model
109134

110135
On this page, the focus is on the data model. You can learn more about [Data sources](/orm/prisma-schema/overview/data-sources) and [Generators](/orm/prisma-schema/overview/generators) on the respective docs pages.
@@ -142,9 +167,9 @@ Then, you can run `prisma generate`:
142167
npx prisma generate
143168
```
144169

145-
The `prisma generate` command reads your Prisma schema and _generates_ Prisma Client code. The code is [generated into the `node_modules/.prisma/client` folder by default](/orm/prisma-client/setup-and-configuration/generating-prisma-client#the-prismaclient-npm-package).
170+
The `prisma generate` command reads your Prisma schema and _generates_ Prisma Client code. The code is generated into the path specified in the `output` field of your generator block (e.g., `./generated` as shown in the schema example above).
146171

147-
After you change your data model, you'll need to manually re-generate Prisma Client by running `prisma generate` to ensure the code inside `node_modules/.prisma/client` gets updated.
172+
After you change your data model, you'll need to manually re-generate Prisma Client by running `prisma generate` to ensure the generated code gets updated.
148173

149174
#### Using Prisma Client to send queries to your database
150175

@@ -156,7 +181,7 @@ Once Prisma Client has been generated, you can import it in your code and send q
156181
<TabItem value="import">
157182

158183
```ts
159-
import { PrismaClient } from '@prisma/client'
184+
import { PrismaClient } from './generated/client'
160185

161186
const prisma = new PrismaClient()
162187
```
@@ -165,7 +190,7 @@ const prisma = new PrismaClient()
165190
<TabItem value="require">
166191

167192
```js
168-
const { PrismaClient } = require('@prisma/client')
193+
const { PrismaClient } = require('./generated/client')
169194

170195
const prisma = new PrismaClient()
171196
```

content/200-orm/050-overview/100-introduction/300-data-modeling.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ export type User = {
211211
In addition to the generated types, Prisma Client also provides a data access API that you can use once you've installed the `@prisma/client` package:
212212
213213
```js
214-
import { PrismaClient } from '@prisma/client'
214+
import { PrismaClient } from '../prisma/generated/client'
215215
// or
216-
// const { PrismaClient } = require('@prisma/client')
216+
// const { PrismaClient } = require('../prisma/generated/client')
217217

218218
const prisma = new PrismaClient()
219219

content/200-orm/050-overview/300-prisma-in-your-stack/01-rest.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ datasource db {
4343
}
4444
4545
generator client {
46-
provider = "prisma-client-js"
46+
provider = "prisma-client"
47+
output = "./generated"
4748
}
4849
4950
model Post {

content/200-orm/050-overview/300-prisma-in-your-stack/03-fullstack.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ datasource db {
4141
}
4242
4343
generator client {
44-
provider = "prisma-client-js"
44+
provider = "prisma-client"
45+
output = "./generated"
4546
}
4647
4748
model Post {

content/200-orm/050-overview/300-prisma-in-your-stack/04-is-prisma-an-orm.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ As an example, here's a Prisma schema for a blog:
228228
```prisma
229229
datasource db {
230230
provider = "postgresql"
231-
url = env("DATABASE_URL")
232231
}
233232
234233
generator client {
235-
provider = "prisma-client-js"
234+
provider = "prisma-client"
235+
output = "./generated"
236236
}
237237
238238
model Post {
@@ -308,7 +308,8 @@ datasource db {
308308
}
309309
310310
generator client {
311-
provider = "prisma-client-js"
311+
provider = "prisma-client"
312+
output = "./generated"
312313
}
313314
```
314315

@@ -338,7 +339,8 @@ datasource db {
338339
}
339340
340341
generator client {
341-
provider = "prisma-client-js"
342+
provider = "prisma-client"
343+
output = "./generated"
342344
}
343345
344346
model Post {
@@ -380,7 +382,7 @@ So far, the article covered the concepts behind Prisma ORM, its implementation o
380382
Accessing the database with Prisma Client happens through the query methods it exposes. All queries return plain old JavaScript objects. Given the blog schema from above, fetching a user looks as follows:
381383

382384
```ts
383-
import { PrismaClient } from '@prisma/client'
385+
import { PrismaClient } from '../prisma/generated/client'
384386

385387
const prisma = new PrismaClient()
386388

content/200-orm/050-overview/500-databases/200-database-drivers.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ As of [v6.15.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without
1818

1919
```prisma
2020
generator client {
21-
provider = "prisma-client-js" // or "prisma-client"
21+
provider = "prisma-client"
2222
output = "../src/generated/prisma"
2323
engineType = "client" // no Rust engine
2424
}
@@ -102,7 +102,7 @@ Earlier versions of Prisma ORM required you to first instantiate the driver itse
102102
```typescript
103103
import { createClient } from '@libsql/client'
104104
import { PrismaLibSQL } from '@prisma/adapter-libsql'
105-
import { PrismaClient } from '@prisma/client'
105+
import { PrismaClient } from '../prisma/generated/client'
106106

107107
// Old way of using driver adapters (before 6.6.0)
108108
const driver = createClient({
@@ -137,7 +137,7 @@ When using Prisma ORM's built-in drivers, the connection string is read from the
137137
On the other hand, when using a driver adapter, the connection string needs to be provided in your _application code_ when the driver adapter is set up initially. Here is how this is done for the `pg` driver and the `@prisma/adapter-pg` adapter:
138138

139139
```ts
140-
import { PrismaClient } from '@prisma/client'
140+
import { PrismaClient } from '../prisma/generated/client'
141141
import { PrismaPg } from '@prisma/adapter-pg'
142142

143143
const adapter = new PrismaPg({ connectionString: env.DATABASE_URL })
@@ -154,7 +154,7 @@ Let's assume you had `output` in your Prisma schema set to `../src/generated/cli
154154

155155
```prisma
156156
generator client {
157-
provider = "prisma-client-js"
157+
provider = "prisma-client"
158158
output = "../src/generated/client"
159159
}
160160
```

content/200-orm/050-overview/500-databases/300-postgresql.mdx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,32 @@ To connect to a PostgreSQL database server, you need to configure a [`datasource
2525
```prisma file=schema.prisma
2626
datasource db {
2727
provider = "postgresql"
28-
url = env("DATABASE_URL")
2928
}
3029
```
3130

31+
The database connection URL is configured in `prisma.config.ts`:
32+
33+
```ts file=prisma.config.ts
34+
import { defineConfig, env } from 'prisma/config'
35+
36+
export default defineConfig({
37+
schema: 'prisma/schema.prisma',
38+
datasource: {
39+
url: env('DATABASE_URL'),
40+
},
41+
})
42+
```
43+
44+
<Admonition type="info">
45+
46+
**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell.
47+
48+
</Admonition>
49+
3250
The fields passed to the `datasource` block are:
3351

3452
- `provider`: Specifies the `postgresql` data source connector.
35-
- `url`: Specifies the [connection URL](#connection-url) for the PostgreSQL database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL.
53+
- The `url` field is configured in `prisma.config.ts` and specifies the [connection URL](#connection-url) for the PostgreSQL database server.
3654

3755
## Using the `node-postgres` driver
3856

@@ -56,7 +74,7 @@ Now, when you instantiate Prisma Client, you need to pass an instance of Prisma
5674

5775
```ts
5876
import { PrismaPg } from '@prisma/adapter-pg'
59-
import { PrismaClient } from '@prisma/client'
77+
import { PrismaClient } from '../prisma/generated/client'
6078

6179
const connectionString = `${process.env.DATABASE_URL}`
6280

content/200-orm/050-overview/500-databases/400-mysql.mdx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,32 @@ To connect to a MySQL database server, you need to configure a [`datasource`](/o
1616
```prisma file=schema.prisma showLineNumbers
1717
datasource db {
1818
provider = "mysql"
19-
url = env("DATABASE_URL")
2019
}
2120
```
2221

22+
The database connection URL is configured in `prisma.config.ts`:
23+
24+
```ts file=prisma.config.ts
25+
import { defineConfig, env } from 'prisma/config'
26+
27+
export default defineConfig({
28+
schema: 'prisma/schema.prisma',
29+
datasource: {
30+
url: env('DATABASE_URL'),
31+
},
32+
})
33+
```
34+
35+
<Admonition type="info">
36+
37+
**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell.
38+
39+
</Admonition>
40+
2341
The fields passed to the `datasource` block are:
2442

2543
- `provider`: Specifies the `mysql` data source connector, which is used both for MySQL and MariaDB.
26-
- `url`: Specifies the [connection URL](#connection-url) for the MySQL database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL.
44+
- The `url` field is configured in `prisma.config.ts` and specifies the [connection URL](#connection-url) for the MySQL database server.
2745

2846
## Using the `mariadb` driver
2947

content/200-orm/050-overview/500-databases/500-sqlite.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ npm install @prisma/adapter-better-sqlite3
4646
Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor:
4747

4848
```ts
49-
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
49+
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
5050
import { PrismaClient } from './generated/prisma';
5151

52-
const adapter = new PrismaBetterSQLite3({
52+
const adapter = new PrismaBetterSqlite3({
5353
url: "file:./prisma/dev.db"
5454
});
5555
const prisma = new PrismaClient({ adapter });
@@ -64,10 +64,10 @@ By default, driver adapters store `DateTime` values as **ISO 8601 strings**, whi
6464
However, if you need **100% backward compatibility** with Prisma ORM's native SQLite driver (for example, when migrating an existing database), you should use the `unixepoch-ms` format, which stores timestamps as the number of milliseconds since the Unix epoch:
6565

6666
```ts
67-
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
67+
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
6868
import { PrismaClient } from './generated/prisma';
6969

70-
const adapter = new PrismaBetterSQLite3({
70+
const adapter = new PrismaBetterSqlite3({
7171
url: "file:./prisma/dev.db"
7272
}, {
7373
timestampFormat: 'unixepoch-ms'

content/200-orm/050-overview/500-databases/800-sql-server/index.mdx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,32 @@ To connect to a Microsoft SQL Server database, you need to configure a [`datasou
1515
```prisma file=schema.prisma showLineNumbers
1616
datasource db {
1717
provider = "sqlserver"
18-
url = env("DATABASE_URL")
1918
}
2019
```
2120

21+
The database connection URL is configured in `prisma.config.ts`:
22+
23+
```ts file=prisma.config.ts
24+
import { defineConfig, env } from 'prisma/config'
25+
26+
export default defineConfig({
27+
schema: 'prisma/schema.prisma',
28+
datasource: {
29+
url: env('DATABASE_URL'),
30+
},
31+
})
32+
```
33+
34+
<Admonition type="info">
35+
36+
**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell.
37+
38+
</Admonition>
39+
2240
The fields passed to the `datasource` block are:
2341

2442
- `provider`: Specifies the `sqlserver` data source connector.
25-
- `url`: Specifies the [connection URL](#connection-details) for the Microsoft SQL Server database. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL.
43+
- The `url` field is configured in `prisma.config.ts` and specifies the [connection URL](#connection-details) for the Microsoft SQL Server database.
2644

2745

2846
## Using the `node-mssql` driver
@@ -47,7 +65,7 @@ Now, when you instantiate Prisma Client, you need to pass an instance of Prisma
4765

4866
```ts
4967
import { PrismaMssql } from '@prisma/adapter-mssql'
50-
import { PrismaClient } from '@prisma/client'
68+
import { PrismaClient } from '../prisma/generated/client'
5169

5270
const config = {
5371
server: 'localhost',

0 commit comments

Comments
 (0)