Gathering detailed insights and metrics for @prisma/react-native
Gathering detailed insights and metrics for @prisma/react-native
Gathering detailed insights and metrics for @prisma/react-native
Gathering detailed insights and metrics for @prisma/react-native
@prisma/client
Prisma Client is an auto-generated, type-safe and modern JavaScript/TypeScript ORM for Node.js that's tailored to your data. Supports PostgreSQL, CockroachDB, MySQL, MariaDB, SQL Server, SQLite & MongoDB databases.
@op-engineering/react-native-prisma
Prisma for react-native
create-uni-app
Typesafe setup to build fullstack Expo universal native apps
veloria
Veloria is a SQLite-based ORM that aims to bring prisma-like experience for React Native.
npm install @prisma/react-native
Typescript
Module System
Min. Node Version
39.6
Supply Chain
57.5
Quality
81.2
Maintenance
50
Vulnerability
88.3
License
TypeScript (45.33%)
C++ (21.26%)
JavaScript (9.89%)
Java (8.02%)
Ruby (3.6%)
Objective-C++ (3.17%)
Objective-C (3.12%)
Kotlin (3.09%)
CMake (1.5%)
C (0.53%)
Shell (0.36%)
CSS (0.07%)
Swift (0.07%)
Total Downloads
30,048
Last Day
25
Last Week
202
Last Month
1,437
Last Year
30,048
217 Stars
393 Commits
9 Forks
8 Watching
8 Branches
44 Contributors
Latest Version
6.0.1
Package Id
@prisma/react-native@6.0.1
Unpacked Size
126.27 MB
Size
38.72 MB
File Count
111
Publised On
04 Dec 2024
Cumulative downloads
Total Downloads
Last day
-16.7%
25
Compared to previous day
Last week
-56.4%
202
Compared to previous week
Last month
-62.9%
1,437
Compared to previous month
Last year
0%
30,048
Compared to previous year
2
5
28
A Prisma engine adaptation for React Native. Please note that this is in Early Access
Install @prisma/client
, @prisma/react-native
and the react-native-quick-base64
dependency:
npm i --save --save-exact @prisma/client@latest @prisma/react-native@latest react-native-quick-base64
To ensure migration files are copied into the app bundle you need to either enable the Expo plugin or configure ios and Android manually:
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:
1{ 2 "expo": { 3 // ... The rest of your expo config 4 "plugins": ["@prisma/react-native"] 5 } 6}
To activate the plugin, run prebuild:
npx expo prebuild --clean
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:
Go into Xcode
→ Build Phases
→ Bundle React Native Code and images
and modify it so that it looks like this:
1set -e 2 3WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh" 4REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh" 5PRISMA_MIGRATIONS="../node_modules/@prisma/react-native/copy-migrations.sh" # Add this 6 7/bin/sh -c "$WITH_ENVIRONMENT $PRISMA_MIGRATIONS $REACT_NATIVE_XCODE" # Add it to the list of running scripts
For Android you need to modify your apps app/Build.gradle
. Add the following at the top of the file.
1apply from: "../../node_modules/@prisma/react-native/react-native-prisma.gradle"
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:
1generator client { 2 provider = "prisma-client-js" 3 previewFeatures = ["reactNative"] 4} 5 6datasource db { 7 provider = "sqlite" 8 url = "file:./app.db" 9} 10 11// Your data model 12 13model User { 14 id Int @id @default(autoincrement()) 15 name String 16}
You can create the database file and initial migration using Prisma migrate:
npx prisma@latest migrate dev
you can now generate the Prisma Client like this:
npx prisma@latest generate
This package contains an extension to the Prisma client that allows you to use reactive queries. Use at your own convenience and care since it might introduce large re-renders in your app.
1import { PrismaClient } from '@prisma/client/react-native'; 2import { reactiveHooksExtension } from '@prisma/react-native'; 3 4const baseClient = new PrismaClient(); 5 6export const extendedClient = baseClient.$extends(reactiveHooksExtension());
Then in your React component you can use the hook:
1import { Text } from 'react-native'; 2import { extendedClient } from './myDbModule'; 3 4export default function App { 5 6 // Will automatically re-render the component with new data 7 const users = extendedClient.user.useFindMany(); 8 9 return ( 10 <Text>{ users }</Text> 11 ) 12}
Bear in mind, for the reactive queries to work you have to use the extended client to modify the data:
1extendedClient.user.create({ ...userData });
There are several hooks you can use for your reactive queries:
1useFindMany(); 2useFindFirst(); 3useFindUnique();
It is also possible to use callbacks for this queries in case you are not using hooks, but you still want to get notified when data changes
1import { PrismaClient } from '@prisma/client/react-native'; 2import { reactiveQueriesExtension } from '@prisma/react-native'; 3 4const baseClient = new PrismaClient(); 5 6export const extendedClient = baseClient.$extends(reactiveQueriesExtension());
On application start you need to run the migrations to make sure the database is in a consistent state with your Prisma generated client:
1import '@prisma/react-native';
2import { PrismaClient } from '@prisma/client/react-native';
3
4const baseClient = new PrismaClient();
5
6async function initializeDb() {
7 try {
8 baseClient.$applyPendingMigrations();
9 } catch (e) {
10 console.error(`failed to apply migrations: ${e}`);
11 throw new Error(
12 'Applying migrations failed, your app is now in an inconsistent state. We cannot guarantee safety, it is now your responsibility to reset the database or tell the user to re-install the app'
13 );
14 }
15}
Care must be taken to ensure migrations will always succeed. Migrations will be executed on the users device at runtime, and if they fail to run, your application will most likely be unable to work correctly. In such a situation, the only option for the user might be to delete all app data and start over.
🎥 Watch the introduction at App.js here: https://www.youtube.com/watch?v=keZYUjAYSJM
📖 Read the announcement post here: https://www.prisma.io/blog/bringing-prisma-orm-to-react-native-and-expo
📹 Watch Catalin build an app with Prisma and Expo here: https://www.youtube.com/watch?v=65Iqes0lxpQ
No vulnerabilities found.
No security vulnerabilities found.