Skip to content

Commit 22a5417

Browse files
authored
Update README.md
1 parent e120282 commit 22a5417

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

README.md

+35-20
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,37 @@ A Prisma engine adaptation for React Native. Please note that this is in [Early
44

55
## Installation
66

7+
Install `@prisma/client`, `@prisma/react-native` and the `react-native-quick-base64` dependency:
8+
79
```
810
npm i --save --save-exact @prisma/client@latest @prisma/react-native@latest react-native-quick-base64
11+
```
12+
13+
To ensure migration files are copied into the app bundle you need to either enable the Expo plugin or configure ios and Android manually:
14+
15+
### Expo
16+
17+
If you are using Expo, you can add the expo plugin to automatically copy migration files. Modify your `app.json` by adding the react-native-prisma plugin:
18+
19+
```json
20+
{
21+
"expo": {
22+
// ... The rest of your expo config
23+
"plugins": ["@prisma/react-native"]
24+
}
25+
}
26+
```
27+
28+
To activate the plugin, run prebuild:
29+
30+
```
931
npx expo prebuild --clean
1032
```
1133

12-
### Bare React Native projects
34+
The Expo plugin simply configures the Android and ios projects during the prebuild phase. If you are not using Expo, you can do this manually:
1335

14-
For bare project you will need to modify the build process to run a couple of scripts that take care of bundling the migrations you generate inside the final app bundle.
1536

16-
#### iOS
37+
### iOS
1738

1839
Go into `Xcode``Build Phases``Bundle React Native Code and images` and modify it so that it looks like this:
1940

@@ -29,30 +50,17 @@ PRISMA_MIGRATIONS="../node_modules/@prisma/react-native/copy-migrations.sh" # Ad
2950
/bin/sh -c "$WITH_ENVIRONMENT $PRISMA_MIGRATIONS $REACT_NATIVE_XCODE" # Add it to the list of running scripts
3051
```
3152

32-
#### Android
53+
### Android
3354

3455
For Android you need to modify your apps `app/Build.gradle`. Add the following at the top of the file.
3556

3657
```groovy
3758
apply from: "../../node_modules/@prisma/react-native/react-native-prisma.gradle"
3859
```
3960

40-
### Expo
41-
42-
For expo this process is automated into prebuild. Modify your `app.json` by adding the react-native-prisma plugin.
43-
44-
```json
45-
{
46-
"expo": {
47-
// ... The rest of your expo config
48-
"plugins": ["@prisma/react-native"]
49-
}
50-
}
51-
```
52-
5361
## Enable React Native support in your schema file
5462

55-
React Native support is currently a preview feature and has to be activated in your schema.prisma file:
63+
React Native support is currently a preview feature and has to be activated in your schema.prisma file. You can place this file in the root of the application:
5664

5765
```ts
5866
generator client {
@@ -73,6 +81,13 @@ model User {
7381
}
7482
```
7583

84+
You can create the database file and initial migration using Prisma migrate:
85+
86+
```
87+
npx prisma@latest migrate dev
88+
```
89+
90+
7691
you can now generate the Prisma Client like this:
7792

7893
```
@@ -144,11 +159,11 @@ On application start you need to run the migrations to make sure the database is
144159
import '@prisma/react-native';
145160
import { PrismaClient } from '@prisma/client/react-native';
146161

147-
const basePrisma = new PrismaClient();
162+
const baseClient = new PrismaClient();
148163

149164
async function initializeDb() {
150165
try {
151-
basePrisma.$applyPendingMigrations();
166+
baseClient.$applyPendingMigrations();
152167
} catch (e) {
153168
console.error(`failed to apply migrations: ${e}`);
154169
throw new Error(

0 commit comments

Comments
 (0)