AnnebladFelix / FiskeLycka

xarbete FiskeLycke
MIT License
2 stars 0 forks source link

Prisma db #11

Open AnnebladFelix opened 2 months ago

Mrmbengan commented 2 months ago

can i connect prisma to react native

Prisma, a powerful database toolkit, is primarily designed to work with Node.js and server-side environments. As of now, Prisma does not directly support React Native applications. However, there are some workarounds and community efforts to make it work.

Here are a couple of approaches you can consider:

react-native-prisma: The react-native-prisma project is an adaptation of the Prisma engine for React Native. It allows you to use Prisma in your React Native app. To get started, you can install the necessary packages using the following command:

yarn add --exact react-native-prisma react-native-quick-base64 react-native-url-polyfill @prisma/client

For bare React Native projects, you’ll need to modify the build process to bundle the migrations generated by Prisma into the final app bundle. The steps differ for iOS and Android:

iOS: Modify your Xcode project settings to include the necessary scripts for bundling migrations.

Android: Modify your app/Build.gradle file to apply the react-native-prisma plugin.

Keep in mind that this solution might introduce large re-renders in your app when using reactive queries. You can use the reactive queries extension provided by this package to handle real-time data updates.

Custom Backend: Since Prisma works on the server side, you can create a separate backend (using Node.js or any other server technology) that interacts with Prisma. Your React Native app can then communicate with this backend via APIs (REST or GraphQL). The backend handles database operations using Prisma, and your app consumes the data. While this approach adds an extra layer, it allows you to keep Prisma on the server side where it’s currently supported.

Remember that using Prisma directly from a React Native app is not a common practice for production applications due to security and performance considerations. However, for prototyping or personal projects, you can explore these options and choose the one that best fits your needs.

If you decide to use Prisma in your React Native project, make sure to stay updated with community efforts and any official Prisma announcements regarding React Native support.