├── .eslintrc.js ├── .gitattributes ├── .github ├── actions │ └── setup │ │ └── action.yml └── workflows │ ├── check-updates.yml │ ├── ci.yml │ ├── test.yml │ └── update-and-publish.yml ├── .gitignore ├── .nvmrc ├── .ruby-version ├── .versions ├── engine ├── prisma-dev └── prisma-latest ├── .watchmanconfig ├── .yarn └── releases │ └── yarn-4.1.1.cjs ├── .yarnrc.yml ├── LICENSE ├── README.md ├── android ├── CMakeLists.txt ├── build.gradle ├── cpp-adapter.cpp ├── gradle.properties └── src │ ├── main │ ├── AndroidManifest.xml │ ├── AndroidManifestNew.xml │ └── java │ │ └── com │ │ └── prisma │ │ ├── PrismaModule.java │ │ └── PrismaPackage.java │ ├── newarch │ └── PrismaSpec.java │ └── oldarch │ └── PrismaSpec.java ├── app.plugin.js ├── babel.config.js ├── copy-migrations.sh ├── cpp ├── QueryEngineHostObject.cpp ├── QueryEngineHostObject.h ├── ThreadPool.cpp ├── ThreadPool.h ├── macros.h ├── react-native-prisma.cpp ├── react-native-prisma.h ├── utils.cpp └── utils.h ├── example ├── .bundle │ └── config ├── .detoxrc.js ├── .ruby-version ├── .watchmanconfig ├── Gemfile ├── Gemfile.lock ├── README.md ├── android │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── prismaexample │ │ │ │ └── DetoxTest.java │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── assets │ │ │ └── migrations │ │ │ │ ├── 0_init │ │ │ │ └── migration.sql │ │ │ │ ├── 20240118142005_nick2 │ │ │ │ └── migration.sql │ │ │ │ ├── 20240119102352_nick3 │ │ │ │ └── migration.sql │ │ │ │ ├── 20240119143417_nick4 │ │ │ │ └── migration.sql │ │ │ │ ├── 20240122145141_my_field │ │ │ │ └── migration.sql │ │ │ │ └── migration_lock.toml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── prismaexample │ │ │ │ ├── MainActivity.kt │ │ │ │ └── MainApplication.kt │ │ │ └── res │ │ │ ├── drawable │ │ │ └── rn_edit_text_material.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ │ └── xml │ │ │ └── network_security_config.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── dev.db ├── dev.db-journal ├── e2e │ ├── jest.config.js │ └── starter.test.js ├── global.css ├── globals.d.ts ├── index.js ├── ios │ ├── .xcode.env │ ├── .xcode.env.local │ ├── File.swift │ ├── Podfile │ ├── Podfile.lock │ ├── PrismaExample-Bridging-Header.h │ ├── PrismaExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ ├── Debug.xcscheme │ │ │ └── Release.xcscheme │ ├── PrismaExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── PrismaExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ └── Frame 20.png │ │ │ ├── Contents.json │ │ │ └── Logo.imageset │ │ │ │ ├── Contents.json │ │ │ │ └── Frame 20.png │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ └── main.m │ ├── PrismaExampleTests │ │ ├── Info.plist │ │ └── PrismaExampleTests.m │ └── link-assets-manifest.json ├── metro.config.js ├── migrations │ ├── 0_init │ │ └── migration.sql │ ├── 20240118142005_nick2 │ │ └── migration.sql │ ├── 20240119102352_nick3 │ │ └── migration.sql │ ├── 20240119143417_nick4 │ │ └── migration.sql │ ├── 20240122145141_my_field │ │ └── migration.sql │ └── migration_lock.toml ├── package.json ├── react-native.config.js ├── schema.prisma ├── src │ ├── App.tsx │ ├── Button.tsx │ ├── db.ts │ └── server.ts └── tailwind.config.js ├── expo.d.ts ├── expo.js ├── ios ├── Prisma.h └── Prisma.mm ├── lefthook.yml ├── package.json ├── plugin ├── build │ ├── index.d.ts │ ├── index.js │ ├── withPrisma.d.ts │ ├── withPrisma.js │ ├── withPrismaAndroid.d.ts │ ├── withPrismaAndroid.js │ ├── withPrismaIOS.d.ts │ └── withPrismaIOS.js ├── src │ ├── index.ts │ ├── withPrisma.ts │ ├── withPrismaAndroid.ts │ └── withPrismaIOS.ts └── tsconfig.json ├── react-native-prisma.gradle ├── react-native-prisma.podspec ├── scripts ├── bump-client.ts ├── check-updates.ts ├── download-engine.ts └── utils.ts ├── src ├── NativePrisma.ts ├── ReactiveHooksExtension.ts ├── ReactiveQueriesExtension.ts └── index.ts ├── tsconfig.build.json ├── tsconfig.json ├── xcode.png └── yarn.lock /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // @generated by expo-module-scripts 2 | module.exports = require('expo-module-scripts/eslintrc.base.js'); 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup 2 | description: Setup Node.js and install dependencies 3 | 4 | runs: 5 | using: composite 6 | steps: 7 | - name: Setup Node.js 8 | uses: actions/setup-node@v4 9 | with: 10 | node-version-file: .nvmrc 11 | cache: 'yarn' 12 | 13 | - name: Install dependencies 14 | run: yarn install --immutable 15 | shell: bash 16 | 17 | - name: Prepare project checkout 18 | run: yarn prepare 19 | shell: bash 20 | -------------------------------------------------------------------------------- /.github/workflows/check-updates.yml: -------------------------------------------------------------------------------- 1 | name: Check for a new client version 2 | on: 3 | schedule: 4 | - cron: '*/5 * * * *' 5 | workflow_dispatch: 6 | 7 | jobs: 8 | skip-duplicates: 9 | name: Skip update if job is already in progress 10 | runs-on: ubuntu-latest 11 | outputs: 12 | should-skip: ${{ steps.skip-check.outputs.should_skip }} 13 | steps: 14 | - id: skip-check 15 | uses: fkirc/skip-duplicate-actions@v5 16 | with: 17 | do_not_skip: '[]' 18 | skip_after_successful_duplicate: 'false' 19 | concurrent_skipping: 'always' 20 | 21 | check-update: 22 | runs-on: ubuntu-latest 23 | needs: skip-duplicates 24 | if: ${{ needs.skip-duplicates.outputs.should-skip != 'true' }} 25 | outputs: 26 | latest: ${{ steps.check-update.outputs.latest }} 27 | dev: ${{ steps.check-update.outputs.dev }} 28 | integration: ${{ steps.check-update.outputs.dev }} 29 | steps: 30 | - name: Checkout 31 | uses: actions/checkout@v4 32 | 33 | - name: Setup 34 | uses: ./.github/actions/setup 35 | 36 | - name: Check for updates 37 | id: check-update 38 | run: yarn check-updates 39 | 40 | update-latest: 41 | name: Update latest tag 42 | needs: 43 | - check-update 44 | if: ${{ needs.check-update.outputs.latest != ''}} 45 | uses: ./.github/workflows/update-and-publish.yml 46 | secrets: inherit 47 | with: 48 | npmTag: latest 49 | version: ${{ needs.check-update.outputs.latest }} 50 | 51 | update-dev: 52 | name: Update dev tag 53 | needs: 54 | - check-update 55 | if: ${{ needs.check-update.outputs.dev != ''}} 56 | uses: ./.github/workflows/update-and-publish.yml 57 | secrets: inherit 58 | with: 59 | npmTag: dev 60 | version: ${{ needs.check-update.outputs.dev }} 61 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | 10 | concurrency: 11 | group: ci-${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | test: 16 | name: Run test 17 | uses: ./.github/workflows/test.yml 18 | secrets: inherit 19 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: 3 | workflow_call: 4 | inputs: 5 | ref: 6 | description: Ref to run the tests on 7 | type: string 8 | required: false 9 | 10 | jobs: 11 | lint-test: 12 | name: Lint 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | with: 18 | ref: ${{ inputs.ref }} 19 | 20 | - name: Setup 21 | uses: ./.github/actions/setup 22 | 23 | - name: Lint files 24 | run: yarn lint 25 | 26 | - name: Typecheck files 27 | run: yarn typecheck 28 | 29 | test-ios: 30 | name: E2E test for iOS 31 | runs-on: macos-14 32 | steps: 33 | - name: Checkout 34 | uses: actions/checkout@v4 35 | with: 36 | ref: ${{ inputs.ref }} 37 | 38 | - name: Setup 39 | uses: ./.github/actions/setup 40 | 41 | - name: Install macOS dependencies 42 | run: | 43 | brew tap wix/brew 44 | brew install applesimutils 45 | env: 46 | HOMEBREW_NO_AUTO_UPDATE: 1 47 | HOMEBREW_NO_INSTALL_CLEANUP: 1 48 | - name: Install CocoaPods dependecies 49 | working-directory: example 50 | run: yarn pod-install 51 | 52 | - name: Detox build 53 | working-directory: example 54 | run: yarn detox build --configuration ios.sim.release 55 | 56 | - name: Detox test 57 | working-directory: example 58 | run: yarn detox test --configuration ios.sim.release --cleanup --headless 59 | 60 | test-android: 61 | name: E2E test for Android 62 | runs-on: ubuntu-latest 63 | steps: 64 | # default runner has not enough space for creating emulators 65 | - name: Free disk space 66 | uses: jlumbroso/free-disk-space@v1.3.1 67 | with: 68 | android: false 69 | tool-cache: true 70 | dotnet: true 71 | haskell: true 72 | swap-storage: true 73 | docker-images: true 74 | large-packages: false 75 | 76 | - name: Checkout 77 | uses: actions/checkout@v4 78 | with: 79 | ref: ${{ inputs.ref }} 80 | 81 | - name: Setup Java 82 | uses: actions/setup-java@v3 83 | with: 84 | cache: gradle 85 | distribution: temurin 86 | java-version: 17 87 | 88 | - name: Setup 89 | uses: ./.github/actions/setup 90 | 91 | - name: Detox build 92 | working-directory: example 93 | run: yarn detox build --configuration android.emu.release 94 | 95 | - name: Enable KVM group perms # make android simulator use KVM and run much faster 96 | run: | 97 | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules 98 | sudo udevadm control --reload-rules 99 | sudo udevadm trigger --name-match=kvm 100 | 101 | - name: Detox test 102 | uses: reactivecircus/android-emulator-runner@v2 103 | with: 104 | working-directory: example 105 | api-level: 28 106 | arch: x86_64 107 | avd-name: Pixel_API_28 108 | script: yarn detox test --configuration android.emu.release --headless 109 | -------------------------------------------------------------------------------- /.github/workflows/update-and-publish.yml: -------------------------------------------------------------------------------- 1 | name: Update prisma client and publish the package 2 | on: 3 | workflow_call: 4 | inputs: 5 | npmTag: 6 | description: npm tag to publish to 7 | type: string 8 | required: true 9 | version: 10 | description: npm version to publish 11 | type: string 12 | required: true 13 | secrets: 14 | SLACK_WEBHOOK_URL: 15 | required: true 16 | NPM_TOKEN: 17 | required: true 18 | workflow_dispatch: 19 | inputs: 20 | npmTag: 21 | description: npm tag to publish to 22 | type: string 23 | required: true 24 | version: 25 | description: npm version to publish 26 | type: string 27 | required: true 28 | 29 | concurrency: 30 | group: publish 31 | 32 | jobs: 33 | update: 34 | name: Update client & engines on a temporary branch 35 | runs-on: ubuntu-latest 36 | env: 37 | TMP_BRANCH_NAME: tmp/release-${{ inputs.npmTag }}-${{ inputs.version }} 38 | NPM_TAG: ${{ inputs.npmTag }} 39 | NPM_VERSION: ${{ inputs.version }} 40 | outputs: 41 | tmpBranch: ${{ steps.do-update.outputs.tmpBranch }} 42 | steps: 43 | - name: Checkout 44 | uses: actions/checkout@v4 45 | with: 46 | token: ${{ secrets.PRISMA_BOT_TOKEN }} 47 | 48 | - name: Setup 49 | uses: ./.github/actions/setup 50 | 51 | - name: Update version in temporary branch 52 | id: do-update 53 | run: | 54 | git checkout -b "$TMP_BRANCH_NAME" 55 | yarn bump-client "$NPM_TAG" "$NPM_VERSION" 56 | git config user.email prismabots@gmail.com 57 | git config user.name Prismo 58 | git commit -am "chore(deps): Update prisma to $NPM_VERSION on $NPM_TAG" 59 | git push origin "$TMP_BRANCH_NAME" 60 | echo "tmpBranch=$TMP_BRANCH_NAME" >> "$GITHUB_OUTPUT" 61 | 62 | test: 63 | name: Test release branch 64 | needs: 65 | - update 66 | uses: ./.github/workflows/test.yml 67 | with: 68 | ref: ${{ needs.update.outputs.tmpBranch }} 69 | secrets: inherit 70 | 71 | publish: 72 | name: Merge temp branch back and publish 73 | runs-on: ubuntu-latest 74 | needs: 75 | - update 76 | - test 77 | steps: 78 | - name: Checkout 79 | uses: actions/checkout@v4 80 | with: 81 | token: ${{ secrets.PRISMA_BOT_TOKEN }} 82 | 83 | - name: Merge temp release branch back into main 84 | env: 85 | TMP_BRANCH_NAME: ${{ needs.update.outputs.tmpBranch }} 86 | run: | 87 | git fetch origin "$TMP_BRANCH_NAME" 88 | git merge --ff-only "origin/$TMP_BRANCH_NAME" 89 | 90 | - name: Setup 91 | uses: ./.github/actions/setup 92 | 93 | - name: Publish 94 | env: 95 | NPM_TAG: ${{ inputs.npmTag }} 96 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 97 | run: yarn npm publish --tag "$NPM_TAG" 98 | 99 | - name: Push 100 | run: git push origin main 101 | 102 | notify-on-failure: 103 | name: Notify on publish failure 104 | needs: 105 | - update 106 | - test 107 | - publish 108 | if: ${{ always() && contains(needs.*.result, 'failure') }} 109 | 110 | runs-on: ubuntu-latest 111 | steps: 112 | - name: Set current job url in SLACK_FOOTER env var 113 | run: echo "SLACK_FOOTER=<$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|Click here to go to the job logs>" >> $GITHUB_ENV 114 | 115 | - name: Slack Notification on Failure 116 | uses: rtCamp/action-slack-notify@v2.3.0 117 | env: 118 | SLACK_TITLE: 'React Native publish failed' 119 | SLACK_COLOR: '#FF0000' 120 | SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} 121 | SLACK_CHANNEL: feed-react-native-publish-failures 122 | 123 | finalize: 124 | name: Cleanup 125 | runs-on: ubuntu-latest 126 | needs: 127 | - update 128 | - test 129 | - publish 130 | if: always() 131 | steps: 132 | - name: Checkout 133 | uses: actions/checkout@v4 134 | 135 | - name: Remove temporary branch 136 | env: 137 | TMP_BRANCH_NAME: ${{ needs.update.outputs.tmpBranch }} 138 | run: | 139 | git push --delete origin "$TMP_BRANCH_NAME" 140 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # Ruby 48 | example/vendor/ 49 | 50 | # node.js 51 | # 52 | node_modules/ 53 | npm-debug.log 54 | yarn-debug.log 55 | yarn-error.log 56 | 57 | # BUCK 58 | buck-out/ 59 | \.buckd/ 60 | android/app/libs 61 | android/keystores/debug.keystore 62 | 63 | # Yarn 64 | .yarn/* 65 | !.yarn/patches 66 | !.yarn/plugins 67 | !.yarn/releases 68 | !.yarn/sdks 69 | !.yarn/versions 70 | 71 | # Expo 72 | .expo/ 73 | 74 | # Turborepo 75 | .turbo/ 76 | 77 | # generated by bob 78 | lib/ 79 | 80 | # config plugin output 81 | !plugin/build 82 | 83 | # development client 84 | example/client/* 85 | engines -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v18.20.2 2 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.1.2 2 | -------------------------------------------------------------------------------- /.versions/engine: -------------------------------------------------------------------------------- 1 | c74f8976aaa3212c16a61537319f9024d0c21e85 -------------------------------------------------------------------------------- /.versions/prisma-dev: -------------------------------------------------------------------------------- 1 | 6.1.0-dev.17 -------------------------------------------------------------------------------- /.versions/prisma-latest: -------------------------------------------------------------------------------- 1 | 6.0.1 2 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | compressionLevel: mixed 2 | 3 | enableGlobalCache: false 4 | 5 | nmHoistingLimits: workspaces 6 | 7 | nodeLinker: node-modules 8 | 9 | npmAuthToken: ${NODE_AUTH_TOKEN-} 10 | 11 | yarnPath: .yarn/releases/yarn-4.1.1.cjs 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Early Access: Prisma ORM for React Native and Expo 2 | 3 | A Prisma engine adaptation for React Native. Please note that this is in [Early Access](https://www.prisma.io/docs/orm/more/releases#early-access) 4 | 5 | ## Installation 6 | 7 | Install `@prisma/client`, `@prisma/react-native` and the `react-native-quick-base64` dependency: 8 | 9 | ``` 10 | 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 | ``` 31 | npx expo prebuild --clean 32 | ``` 33 | 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: 35 | 36 | 37 | ### iOS 38 | 39 | Go into `Xcode` → `Build Phases` → `Bundle React Native Code and images` and modify it so that it looks like this: 40 | 41 | ![xcode_build_phases](xcode.png) 42 | 43 | ```bash 44 | set -e 45 | 46 | WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh" 47 | REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh" 48 | PRISMA_MIGRATIONS="../node_modules/@prisma/react-native/copy-migrations.sh" # Add this 49 | 50 | /bin/sh -c "$WITH_ENVIRONMENT $PRISMA_MIGRATIONS $REACT_NATIVE_XCODE" # Add it to the list of running scripts 51 | ``` 52 | 53 | ### Android 54 | 55 | For Android you need to modify your apps `app/Build.gradle`. Add the following at the top of the file. 56 | 57 | ```groovy 58 | apply from: "../../node_modules/@prisma/react-native/react-native-prisma.gradle" 59 | ``` 60 | 61 | ## Enable React Native support in your schema file 62 | 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: 64 | 65 | ```ts 66 | generator client { 67 | provider = "prisma-client-js" 68 | previewFeatures = ["reactNative"] 69 | } 70 | 71 | datasource db { 72 | provider = "sqlite" 73 | url = "file:./app.db" 74 | } 75 | 76 | // Your data model 77 | 78 | model User { 79 | id Int @id @default(autoincrement()) 80 | name String 81 | } 82 | ``` 83 | 84 | You can create the database file and initial migration using Prisma migrate: 85 | 86 | ``` 87 | npx prisma@latest migrate dev 88 | ``` 89 | 90 | 91 | you can now generate the Prisma Client like this: 92 | 93 | ``` 94 | npx prisma@latest generate 95 | ``` 96 | 97 | ## Reactive queries 98 | 99 | 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. 100 | 101 | ```ts 102 | import { PrismaClient } from '@prisma/client/react-native'; 103 | import { reactiveHooksExtension } from '@prisma/react-native'; 104 | 105 | const baseClient = new PrismaClient(); 106 | 107 | export const extendedClient = baseClient.$extends(reactiveHooksExtension()); 108 | ``` 109 | 110 | Then in your React component you can use the hook: 111 | 112 | ```tsx 113 | import { Text } from 'react-native'; 114 | import { extendedClient } from './myDbModule'; 115 | 116 | export default function App { 117 | 118 | // Will automatically re-render the component with new data 119 | const users = extendedClient.user.useFindMany(); 120 | 121 | return ( 122 | { users } 123 | ) 124 | } 125 | ``` 126 | 127 | Bear in mind, for the reactive queries to work you have to use the extended client to modify the data: 128 | 129 | ```ts 130 | extendedClient.user.create({ ...userData }); 131 | ``` 132 | 133 | There are several hooks you can use for your reactive queries: 134 | 135 | ```ts 136 | useFindMany(); 137 | useFindFirst(); 138 | useFindUnique(); 139 | ``` 140 | 141 | ### Non hook reactive queries 142 | 143 | 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 144 | 145 | ```ts 146 | import { PrismaClient } from '@prisma/client/react-native'; 147 | import { reactiveQueriesExtension } from '@prisma/react-native'; 148 | 149 | const baseClient = new PrismaClient(); 150 | 151 | export const extendedClient = baseClient.$extends(reactiveQueriesExtension()); 152 | ``` 153 | 154 | ## Applying migrations 155 | 156 | On application start you need to run the migrations to make sure the database is in a consistent state with your Prisma generated client: 157 | 158 | ```ts 159 | import '@prisma/react-native'; 160 | import { PrismaClient } from '@prisma/client/react-native'; 161 | 162 | const baseClient = new PrismaClient(); 163 | 164 | async function initializeDb() { 165 | try { 166 | baseClient.$applyPendingMigrations(); 167 | } catch (e) { 168 | console.error(`failed to apply migrations: ${e}`); 169 | throw new Error( 170 | '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' 171 | ); 172 | } 173 | } 174 | ``` 175 | 176 | 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. 177 | 178 | ## Material 179 | 180 | 🎥 Watch the introduction at App.js here: https://www.youtube.com/watch?v=keZYUjAYSJM 181 | 182 | 📖 Read the announcement post here: https://www.prisma.io/blog/bringing-prisma-orm-to-react-native-and-expo 183 | 184 | 📹 Watch Catalin build an app with Prisma and Expo here: https://www.youtube.com/watch?v=65Iqes0lxpQ 185 | -------------------------------------------------------------------------------- /android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9.0) 2 | project(Prisma) 3 | 4 | set (PACKAGE_NAME "react-native-prisma") 5 | set (CMAKE_VERBOSE_MAKEFILE ON) 6 | set (CMAKE_CXX_STANDARD 17) 7 | set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build) 8 | 9 | 10 | add_library( 11 | ${PACKAGE_NAME} 12 | SHARED 13 | ../cpp/react-native-prisma.cpp 14 | ../cpp/macros.h 15 | ../cpp/QueryEngineHostObject.cpp 16 | ../cpp/QueryEngineHostObject.h 17 | ../cpp/react-native-prisma.h 18 | ../cpp/ThreadPool.cpp 19 | ../cpp/ThreadPool.h 20 | ../cpp/utils.h 21 | ../cpp/utils.cpp 22 | ../engines/android/query_engine.h 23 | cpp-adapter.cpp 24 | ) 25 | 26 | include_directories( 27 | ../cpp 28 | ../engines/android 29 | ) 30 | 31 | set_target_properties( 32 | ${PACKAGE_NAME} PROPERTIES 33 | CXX_STANDARD 17 34 | CXX_EXTENSIONS OFF 35 | POSITION_INDEPENDENT_CODE ON 36 | ) 37 | 38 | find_package(ReactAndroid REQUIRED CONFIG) 39 | find_package(fbjni REQUIRED CONFIG) 40 | 41 | cmake_path(SET QUERY_ENGINE_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../engines/android/jniLibs/${ANDROID_ABI}/libquery_engine.a NORMALIZE) 42 | 43 | add_library(query_engine STATIC IMPORTED) 44 | set_target_properties(query_engine PROPERTIES IMPORTED_LOCATION ${QUERY_ENGINE_LIB}) 45 | 46 | target_link_libraries( 47 | ${PACKAGE_NAME} 48 | query_engine 49 | fbjni::fbjni 50 | ReactAndroid::jsi 51 | ReactAndroid::turbomodulejsijni 52 | ReactAndroid::react_nativemodule_core 53 | android 54 | ) -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | classpath "com.android.tools.build:gradle:7.2.1" 9 | } 10 | } 11 | 12 | def isNewArchitectureEnabled() { 13 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" 14 | } 15 | 16 | apply plugin: "com.android.library" 17 | 18 | if (isNewArchitectureEnabled()) { 19 | apply plugin: "com.facebook.react" 20 | } 21 | 22 | def getExtOrDefault(name) { 23 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Prisma_" + name] 24 | } 25 | 26 | def getExtOrIntegerDefault(name) { 27 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Prisma_" + name]).toInteger() 28 | } 29 | 30 | def supportsNamespace() { 31 | def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') 32 | def major = parsed[0].toInteger() 33 | def minor = parsed[1].toInteger() 34 | 35 | // Namespace support was added in 7.3.0 36 | return (major == 7 && minor >= 3) || major >= 8 37 | } 38 | 39 | def resolveBuildType() { 40 | Gradle gradle = getGradle() 41 | String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString() 42 | 43 | return tskReqStr.contains('Release') ? 'release' : 'debug' 44 | } 45 | 46 | android { 47 | if (supportsNamespace()) { 48 | namespace "com.prisma" 49 | 50 | sourceSets { 51 | main { 52 | manifest.srcFile "src/main/AndroidManifestNew.xml" 53 | } 54 | } 55 | } 56 | 57 | // ndkVersion getExtOrDefault("ndkVersion") 58 | compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") 59 | 60 | defaultConfig { 61 | minSdkVersion getExtOrIntegerDefault("minSdkVersion") 62 | targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") 63 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() 64 | 65 | externalNativeBuild { 66 | cmake { 67 | cppFlags "-O2", "-fexceptions", "-frtti", "-DONANDROID", "-lz" 68 | abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' 69 | arguments '-DANDROID_STL=c++_shared' 70 | } 71 | } 72 | 73 | packagingOptions { 74 | doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : '' 75 | excludes = [ 76 | "META-INF", 77 | "META-INF/**", 78 | "**/libjsi.so", 79 | "**/libreact_nativemodule_core.so", 80 | "**/libturbomodulejsijni.so", 81 | "**/libc++_shared.so", 82 | "**/libfbjni.so" 83 | ] 84 | } 85 | } 86 | 87 | externalNativeBuild { 88 | cmake { 89 | path "CMakeLists.txt" 90 | } 91 | } 92 | 93 | buildFeatures { 94 | buildConfig true 95 | prefab true 96 | } 97 | 98 | buildTypes { 99 | release { 100 | minifyEnabled false 101 | } 102 | } 103 | 104 | lintOptions { 105 | disable "GradleCompatible" 106 | } 107 | 108 | compileOptions { 109 | sourceCompatibility JavaVersion.VERSION_1_8 110 | targetCompatibility JavaVersion.VERSION_1_8 111 | } 112 | 113 | sourceSets { 114 | main { 115 | if (isNewArchitectureEnabled()) { 116 | java.srcDirs += [ 117 | "src/newarch", 118 | // This is needed to build Kotlin project with NewArch enabled 119 | "${project.buildDir}/generated/source/codegen/java" 120 | ] 121 | } else { 122 | java.srcDirs += ["src/oldarch"] 123 | } 124 | } 125 | } 126 | } 127 | 128 | repositories { 129 | mavenCentral() 130 | google() 131 | } 132 | 133 | 134 | dependencies { 135 | // For < 0.71, this will be from the local maven repo 136 | // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin 137 | //noinspection GradleDynamicVersion 138 | implementation "com.facebook.react:react-native:+" 139 | } 140 | 141 | // Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct". 142 | tasks.whenTaskAdded { task -> 143 | if (task.name.contains("configureCMakeDebug")) { 144 | rootProject.getTasksByName("packageReactNdkDebugLibs", true).forEach { 145 | task.dependsOn(it) 146 | } 147 | } 148 | // We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo 149 | if (task.name.contains("configureCMakeRel")) { 150 | rootProject.getTasksByName("packageReactNdkReleaseLibs", true).forEach { 151 | task.dependsOn(it) 152 | } 153 | } 154 | } 155 | 156 | if (isNewArchitectureEnabled()) { 157 | react { 158 | jsRootDir = file("../src/") 159 | libraryName = "Prisma" 160 | codegenJavaPackageName = "com.prisma" 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /android/cpp-adapter.cpp: -------------------------------------------------------------------------------- 1 | #include "react-native-prisma.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace jni = facebook::jni; 9 | namespace react = facebook::react; 10 | namespace jsi = facebook::jsi; 11 | 12 | struct PrismaModule : jni::JavaClass { 13 | static constexpr auto kJavaDescriptor = "Lcom/prisma/PrismaModule;"; 14 | 15 | static void registerNatives() { 16 | javaClassStatic()->registerNatives( 17 | {makeNativeMethod("installNativeJsi", PrismaModule::installNativeJsi)}); 18 | } 19 | 20 | private: 21 | static void installNativeJsi( 22 | jni::alias_ref thiz, jlong jsiRuntimePtr, 23 | jni::alias_ref jsCallInvokerHolder, 24 | jni::alias_ref docPath, 25 | jni::alias_ref migrationsPath) { 26 | auto jsiRuntime = reinterpret_cast(jsiRuntimePtr); 27 | auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); 28 | std::string docPathString = docPath->toStdString(); 29 | std::string migrationsPathString = migrationsPath->toStdString(); 30 | 31 | prisma::install_cxx(*jsiRuntime, jsCallInvoker, docPathString.c_str(), 32 | migrationsPathString.c_str()); 33 | } 34 | }; 35 | 36 | JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) { 37 | return jni::initialize(vm, [] { PrismaModule::registerNatives(); }); 38 | } -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | Prisma_kotlinVersion=1.7.0 2 | Prisma_minSdkVersion=21 3 | Prisma_targetSdkVersion=34 4 | Prisma_compileSdkVersion=34 5 | Prisma_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifestNew.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /android/src/main/java/com/prisma/PrismaModule.java: -------------------------------------------------------------------------------- 1 | package com.prisma; 2 | 3 | import android.content.res.AssetManager; 4 | import android.os.Environment; 5 | 6 | import androidx.annotation.NonNull; 7 | 8 | import com.facebook.react.bridge.Promise; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.bridge.ReactMethod; 11 | import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; 12 | 13 | import java.io.File; 14 | import java.io.FileOutputStream; 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | import java.io.OutputStream; 18 | 19 | public class PrismaModule extends PrismaSpec { 20 | public static final String NAME = "Prisma"; 21 | 22 | PrismaModule(ReactApplicationContext context) { 23 | super(context); 24 | } 25 | 26 | @Override 27 | @NonNull 28 | public String getName() { 29 | return NAME; 30 | } 31 | 32 | static { 33 | // System.loadLibrary("query-engine"); 34 | System.loadLibrary("react-native-prisma"); 35 | } 36 | 37 | public static native void installNativeJsi(long jsContextNativePointer, CallInvokerHolderImpl callInvoker, String docPath, String migrationsPath); 38 | 39 | public String copyDirorfileFromAssetManager(String arg_assetDir, String arg_destinationDir) throws IOException 40 | { 41 | String sd_path = getReactApplicationContext().getCacheDir().getAbsolutePath(); 42 | String dest_dir_path = sd_path + addLeadingSlash(arg_destinationDir); 43 | File dest_dir = new File(dest_dir_path); 44 | 45 | createDir(dest_dir); 46 | 47 | AssetManager asset_manager = getReactApplicationContext().getAssets(); 48 | String[] files = asset_manager.list(arg_assetDir); 49 | 50 | for (int i = 0; i < files.length; i++) 51 | { 52 | 53 | String abs_asset_file_path = addTrailingSlash(arg_assetDir) + files[i]; 54 | String sub_files[] = asset_manager.list(abs_asset_file_path); 55 | 56 | if (sub_files.length == 0) 57 | { 58 | // It is a file 59 | String dest_file_path = addTrailingSlash(dest_dir_path) + files[i]; 60 | copyAssetFile(abs_asset_file_path, dest_file_path); 61 | } else 62 | { 63 | // It is a sub directory 64 | copyDirorfileFromAssetManager(abs_asset_file_path, addTrailingSlash(arg_destinationDir) + files[i]); 65 | } 66 | } 67 | 68 | return dest_dir_path; 69 | } 70 | 71 | 72 | public void copyAssetFile(String assetFilePath, String destinationFilePath) throws IOException 73 | { 74 | InputStream in = getReactApplicationContext().getAssets().open(assetFilePath); 75 | OutputStream out = new FileOutputStream(destinationFilePath); 76 | 77 | byte[] buf = new byte[1024]; 78 | int len; 79 | while ((len = in.read(buf)) > 0) 80 | out.write(buf, 0, len); 81 | in.close(); 82 | out.close(); 83 | } 84 | 85 | public String addTrailingSlash(String path) 86 | { 87 | if (path.charAt(path.length() - 1) != '/') 88 | { 89 | path += "/"; 90 | } 91 | return path; 92 | } 93 | 94 | public String addLeadingSlash(String path) 95 | { 96 | if (path.charAt(0) != '/') 97 | { 98 | path = "/" + path; 99 | } 100 | return path; 101 | } 102 | 103 | public void createDir(File dir) throws IOException 104 | { 105 | if (dir.exists()) 106 | { 107 | if (!dir.isDirectory()) 108 | { 109 | throw new IOException("Can't create directory, a file is in the way"); 110 | } 111 | } else 112 | { 113 | dir.mkdirs(); 114 | if (!dir.isDirectory()) 115 | { 116 | throw new IOException("Unable to create directory"); 117 | } 118 | } 119 | } 120 | 121 | @ReactMethod(isBlockingSynchronousMethod = true) 122 | public void install() { 123 | ReactApplicationContext context = this.getReactApplicationContext(); 124 | long jsContextPointer = context.getJavaScriptContextHolder().get(); 125 | CallInvokerHolderImpl jsCallInvokerHolder = (CallInvokerHolderImpl)context.getCatalystInstance().getJSCallInvokerHolder(); 126 | String dbPath = context.getDatabasePath("defaultDatabase").getAbsolutePath().replace("defaultDatabase", ""); 127 | String migrationsPath; 128 | try { 129 | migrationsPath = copyDirorfileFromAssetManager("migrations", "migrations"); 130 | } catch (IOException e) { 131 | throw new RuntimeException(e); 132 | } 133 | installNativeJsi( 134 | jsContextPointer, 135 | jsCallInvokerHolder, 136 | dbPath, migrationsPath 137 | ); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /android/src/main/java/com/prisma/PrismaPackage.java: -------------------------------------------------------------------------------- 1 | package com.prisma; 2 | 3 | import androidx.annotation.Nullable; 4 | 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.module.model.ReactModuleInfo; 8 | import com.facebook.react.module.model.ReactModuleInfoProvider; 9 | import com.facebook.react.TurboReactPackage; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class PrismaPackage extends TurboReactPackage { 15 | 16 | @Nullable 17 | @Override 18 | public NativeModule getModule(String name, ReactApplicationContext reactContext) { 19 | if (name.equals(PrismaModule.NAME)) { 20 | return new PrismaModule(reactContext); 21 | } else { 22 | return null; 23 | } 24 | } 25 | 26 | @Override 27 | public ReactModuleInfoProvider getReactModuleInfoProvider() { 28 | return () -> { 29 | final Map moduleInfos = new HashMap<>(); 30 | boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 31 | moduleInfos.put( 32 | PrismaModule.NAME, 33 | new ReactModuleInfo( 34 | PrismaModule.NAME, 35 | PrismaModule.NAME, 36 | false, // canOverrideExistingModule 37 | false, // needsEagerInit 38 | true, // hasConstants 39 | false, // isCxxModule 40 | isTurboModule // isTurboModule 41 | )); 42 | return moduleInfos; 43 | }; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /android/src/newarch/PrismaSpec.java: -------------------------------------------------------------------------------- 1 | package com.prisma; 2 | 3 | import com.facebook.react.bridge.ReactApplicationContext; 4 | 5 | abstract class PrismaSpec extends NativePrismaSpec { 6 | PrismaSpec(ReactApplicationContext context) { 7 | super(context); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /android/src/oldarch/PrismaSpec.java: -------------------------------------------------------------------------------- 1 | package com.prisma; 2 | 3 | import com.facebook.react.bridge.ReactApplicationContext; 4 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 5 | import com.facebook.react.bridge.Promise; 6 | 7 | abstract class PrismaSpec extends ReactContextBaseJavaModule { 8 | PrismaSpec(ReactApplicationContext context) { 9 | super(context); 10 | } 11 | 12 | public abstract void install(); 13 | } 14 | -------------------------------------------------------------------------------- /app.plugin.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./expo'); 2 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | module.exports = { 3 | presets: ['module:@react-native/babel-preset'], 4 | }; 5 | -------------------------------------------------------------------------------- /copy-migrations.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Copying prisma migration files..." 4 | 5 | MIGRATIONS_TARGET=${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH} 6 | 7 | rm -rf "$MIGRATIONS_TARGET/migrations" 8 | mkdir "$MIGRATIONS_TARGET/migrations" 9 | cp -r ${SRCROOT}/../migrations ${MIGRATIONS_TARGET} 10 | 11 | echo "migration files copied ✅" -------------------------------------------------------------------------------- /cpp/QueryEngineHostObject.cpp: -------------------------------------------------------------------------------- 1 | #include "QueryEngineHostObject.h" 2 | 3 | namespace prisma { 4 | namespace jsi = facebook::jsi; 5 | 6 | QueryEngineHostObject::QueryEngineHostObject( 7 | std::string id, std::function log_callback) { 8 | this->id = id; 9 | this->log_callback = log_callback; 10 | } 11 | 12 | void QueryEngineHostObject::setEngine(QueryEngine *ptr) { this->engine = ptr; } 13 | 14 | } // namespace prisma 15 | -------------------------------------------------------------------------------- /cpp/QueryEngineHostObject.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef query_engine_host_object_h 3 | #define query_engine_host_object_h 4 | 5 | #include "query_engine.h" 6 | #include 7 | #include 8 | #include 9 | 10 | namespace prisma { 11 | namespace jsi = facebook::jsi; 12 | 13 | class JSI_EXPORT QueryEngineHostObject : public jsi::HostObject { 14 | public: 15 | QueryEngineHostObject(std::string id, 16 | std::function log_callback); 17 | 18 | void setEngine(QueryEngine *ptr); 19 | 20 | std::string id; 21 | std::function log_callback; 22 | QueryEngine *engine; 23 | }; 24 | } // namespace prisma 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /cpp/ThreadPool.cpp: -------------------------------------------------------------------------------- 1 | #include "ThreadPool.h" 2 | 3 | namespace prisma { 4 | 5 | ThreadPool::ThreadPool() : done(false) { 6 | // This returns the number of threads supported by the system. If the 7 | // function can't figure out this information, it returns 0. 0 is not good, 8 | // so we create at least 1 9 | auto numberOfThreads = std::thread::hardware_concurrency(); 10 | if (numberOfThreads == 0) { 11 | numberOfThreads = 1; 12 | } 13 | 14 | for (unsigned i = 0; i < numberOfThreads; ++i) { 15 | // The threads will execute the private member `doWork`. Note that we need 16 | // to pass a reference to the function (namespaced with the class name) as 17 | // the first argument, and the current object as second argument 18 | threads.push_back(std::thread(&ThreadPool::doWork, this)); 19 | } 20 | } 21 | 22 | // The destructor joins all the threads so the program can exit gracefully. 23 | // This will be executed if there is any exception (e.g. creating the threads) 24 | ThreadPool::~ThreadPool() { 25 | // So threads know it's time to shut down 26 | done = true; 27 | 28 | // Wake up all the threads, so they can finish and be joined 29 | workQueueConditionVariable.notify_all(); 30 | 31 | for (auto &thread : threads) { 32 | if (thread.joinable()) { 33 | thread.join(); 34 | } 35 | } 36 | 37 | threads.clear(); 38 | } 39 | 40 | // This function will be called by the server every time there is a request 41 | // that needs to be processed by the thread pool 42 | void ThreadPool::queueWork(std::function task) { 43 | // Grab the mutex 44 | std::lock_guard g(workQueueMutex); 45 | 46 | // Push the request to the queue 47 | workQueue.push(task); 48 | 49 | // Notify one thread that there are requests to process 50 | workQueueConditionVariable.notify_one(); 51 | } 52 | 53 | // Function used by the threads to grab work from the queue 54 | void ThreadPool::doWork() { 55 | // Loop while the queue is not destructing 56 | while (!done) { 57 | std::function task; 58 | 59 | // Create a scope, so we don't lock the queue for longer than necessary 60 | { 61 | std::unique_lock g(workQueueMutex); 62 | workQueueConditionVariable.wait(g, [&] { 63 | // Only wake up if there are elements in the queue or the program is 64 | // shutting down 65 | return !workQueue.empty() || done; 66 | }); 67 | 68 | // If we are shutting down exit witout trying to process more work 69 | if (done) { 70 | break; 71 | } 72 | 73 | task = workQueue.front(); 74 | workQueue.pop(); 75 | } 76 | ++busy; 77 | task(); 78 | --busy; 79 | } 80 | } 81 | 82 | void ThreadPool::waitFinished() { 83 | std::unique_lock g(workQueueMutex); 84 | workQueueConditionVariable.wait( 85 | g, [&] { return workQueue.empty() && (busy == 0); }); 86 | } 87 | 88 | void ThreadPool::restartPool() { 89 | // So threads know it's time to shut down 90 | done = true; 91 | 92 | // Wake up all the threads, so they can finish and be joined 93 | workQueueConditionVariable.notify_all(); 94 | 95 | for (auto &thread : threads) { 96 | if (thread.joinable()) { 97 | thread.join(); 98 | } 99 | } 100 | 101 | threads.clear(); 102 | 103 | auto numberOfThreads = std::thread::hardware_concurrency(); 104 | if (numberOfThreads == 0) { 105 | numberOfThreads = 1; 106 | } 107 | 108 | for (unsigned i = 0; i < numberOfThreads; ++i) { 109 | // The threads will execute the private member `doWork`. Note that we need 110 | // to pass a reference to the function (namespaced with the class name) as 111 | // the first argument, and the current object as second argument 112 | threads.push_back(std::thread(&ThreadPool::doWork, this)); 113 | } 114 | 115 | done = false; 116 | } 117 | } // namespace prisma 118 | -------------------------------------------------------------------------------- /cpp/ThreadPool.h: -------------------------------------------------------------------------------- 1 | #ifndef ThreadPool_h 2 | #define ThreadPool_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace prisma { 13 | 14 | class ThreadPool { 15 | public: 16 | ThreadPool(); 17 | ~ThreadPool(); 18 | void queueWork(std::function task); 19 | void waitFinished(); 20 | void restartPool(); 21 | 22 | private: 23 | unsigned int busy; 24 | // This condition variable is used for the threads to wait until there is work 25 | // to do 26 | std::condition_variable_any workQueueConditionVariable; 27 | 28 | // We store the threads in a vector, so we can later stop them gracefully 29 | std::vector threads; 30 | 31 | // Mutex to protect workQueue 32 | std::mutex workQueueMutex; 33 | 34 | // Queue of requests waiting to be processed 35 | std::queue> workQueue; 36 | 37 | // This will be set to true when the thread pool is shutting down. This tells 38 | // the threads to stop looping and finish 39 | bool done; 40 | 41 | // Function used by the threads to grab work from the queue 42 | void doWork(); 43 | }; 44 | 45 | } // namespace prisma 46 | 47 | #endif /* ThreadPool_h */ 48 | -------------------------------------------------------------------------------- /cpp/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef macros_h 2 | #define macros_h 3 | 4 | #define HOSTFN(name, basecount) \ 5 | jsi::Function::createFromHostFunction( \ 6 | rt, \ 7 | jsi::PropNameID::forAscii(rt, name), \ 8 | basecount, \ 9 | [=](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value 10 | 11 | #endif /* macros_h */ 12 | -------------------------------------------------------------------------------- /cpp/react-native-prisma.cpp: -------------------------------------------------------------------------------- 1 | #include "react-native-prisma.h" 2 | #include "QueryEngineHostObject.h" 3 | #include "ThreadPool.h" 4 | #include "macros.h" 5 | #include "query_engine.h" 6 | #include "utils.h" 7 | #include 8 | #include 9 | 10 | namespace prisma { 11 | 12 | namespace jsi = facebook::jsi; 13 | 14 | static std::string base_path; 15 | std::string migrations_path; 16 | std::shared_ptr call_invoker; 17 | std::unordered_map> 18 | engine_map; 19 | ThreadPool thread_pool; 20 | 21 | // Pure C function that is used by Rust to call the log callback 22 | extern void log_callback(const char *id, const char *msg) { 23 | if (engine_map.count(id)) { 24 | auto engine = engine_map[id]; 25 | engine->log_callback(msg); 26 | } 27 | } 28 | 29 | void install_cxx(jsi::Runtime &rt, 30 | std::shared_ptr call_invoker_param, 31 | const char *base_path_param, 32 | const char *migrations_path_param) { 33 | base_path = std::string(base_path_param); 34 | migrations_path = std::string(migrations_path_param); 35 | call_invoker = call_invoker_param; 36 | 37 | auto create = HOSTFN("create", 1) { 38 | // Rust will return a pointer to the internal struct, C++ has nothing to do 39 | // with this it will only be passed to the stateless functions 40 | QueryEngine *ptr; 41 | // Each query engine requires a unique id to route the logging messages 42 | std::string id = get_uuid(); 43 | 44 | jsi::Object params = args[0].asObject(rt); 45 | 46 | std::string datamodel = 47 | params.getProperty(rt, "datamodel").asString(rt).utf8(rt); 48 | std::string log_level = 49 | params.getProperty(rt, "logLevel").asString(rt).utf8(rt); 50 | bool log_queries = params.getProperty(rt, "logQueries").asBool(); 51 | std::shared_ptr js_log_callback = 52 | std::make_shared(params.getProperty(rt, "logCallback")); 53 | bool ignore_env_var_errors = 54 | params.getProperty(rt, "ignoreEnvVarErrors").asBool(); 55 | std::string env = params.getProperty(rt, "env").asString(rt).utf8(rt); 56 | std::string datasource_overrides = 57 | params.getProperty(rt, "datasourceOverrides").asString(rt).utf8(rt); 58 | 59 | ConstructorOptionsNative nativeOptions = ConstructorOptionsNative{""}; 60 | ConstructorOptions options = 61 | ConstructorOptions{.id = id.c_str(), 62 | .datamodel = datamodel.c_str(), 63 | .base_path = base_path.c_str(), 64 | .log_level = log_level.c_str(), 65 | .log_queries = log_queries, 66 | .datasource_overrides = datasource_overrides.c_str(), 67 | .env = env.c_str(), 68 | .ignore_env_var_errors = ignore_env_var_errors, 69 | .native = nativeOptions, 70 | .log_callback = &log_callback}; 71 | 72 | char *error_ptr; 73 | 74 | int prisma_res = prisma_create(options, &ptr, &error_ptr); 75 | 76 | if (prisma_res != PRISMA_OK) { 77 | auto error_string = std::string(error_ptr); 78 | free(error_ptr); 79 | throw std::runtime_error("Failed to create prisma engine: " + 80 | error_string); 81 | } 82 | 83 | auto log_callback_fn = [&rt, js_log_callback](std::string msg) { 84 | call_invoker->invokeAsync([&rt, msg, &js_log_callback] { 85 | js_log_callback->asObject(rt).asFunction(rt).call( 86 | rt, jsi::String::createFromUtf8(rt, msg)); 87 | }); 88 | }; 89 | 90 | QueryEngineHostObject engineHostObject = 91 | QueryEngineHostObject(id, log_callback_fn); 92 | 93 | engineHostObject.setEngine(ptr); 94 | 95 | auto engine = std::make_shared(engineHostObject); 96 | engine_map[id] = engine; 97 | 98 | return jsi::Object::createFromHostObject(rt, engine); 99 | }); 100 | 101 | auto connect = HOSTFN("connect", 2) { 102 | std::shared_ptr queryEngineHostObject = 103 | args[0].asObject(rt).asHostObject(rt); 104 | std::string trace = args[1].asString(rt).utf8(rt); 105 | char *error_ptr; 106 | 107 | int result = prisma_connect(queryEngineHostObject->engine, trace.c_str(), 108 | &error_ptr); 109 | if (result != PRISMA_OK) { 110 | std::string error_message(error_ptr); 111 | free(error_ptr); 112 | throw std::runtime_error(error_message); 113 | } 114 | return {}; 115 | }); 116 | 117 | auto execute = HOSTFN("execute", 4) { 118 | std::shared_ptr queryEngineHostObject = 119 | args[0].asObject(rt).asHostObject(rt); 120 | std::string body = args[1].asString(rt).utf8(rt); 121 | std::string trace = args[2].asString(rt).utf8(rt); 122 | std::string tx_id; 123 | if (count > 3 && args[3].isString()) { 124 | tx_id = args[3].asString(rt).utf8(rt); 125 | } 126 | 127 | auto promise_constructor = rt.global().getPropertyAsFunction(rt, "Promise"); 128 | 129 | auto promise = promise_constructor.callAsConstructor(rt, HOSTFN("executor", 2) { 130 | auto resolve = std::make_shared(rt, args[0]); 131 | auto reject = std::make_shared(rt, args[1]); 132 | 133 | auto task = [&rt, &queryEngineHostObject, body = std::move(body), 134 | trace = std::move(trace), tx_id = std::move(tx_id), resolve, 135 | reject]() { 136 | const char *response; 137 | char *error_ptr; 138 | 139 | if (!tx_id.empty()) { 140 | response = prisma_query(queryEngineHostObject->engine, body.c_str(), 141 | trace.c_str(), tx_id.c_str(), &error_ptr); 142 | } else { 143 | response = prisma_query(queryEngineHostObject->engine, body.c_str(), 144 | trace.c_str(), nullptr, &error_ptr); 145 | } 146 | 147 | call_invoker->invokeAsync([&rt, response = std::move(response), 148 | error_ptr, resolve, reject]() { 149 | if (error_ptr == nullptr) { 150 | resolve->asObject(rt).asFunction(rt).call( 151 | rt, jsi::String::createFromUtf8(rt, response)); 152 | } else { 153 | auto errCtr = rt.global().getPropertyAsFunction(rt, "Error"); 154 | std::string error_message(error_ptr); 155 | free(error_ptr); 156 | 157 | auto error = errCtr.callAsConstructor( 158 | rt, jsi::String::createFromUtf8(rt, error_message)); 159 | 160 | reject->asObject(rt).asFunction(rt).call(rt, error); 161 | } 162 | }); 163 | }; 164 | 165 | thread_pool.queueWork(task); 166 | 167 | return {}; 168 | })); 169 | 170 | return promise; 171 | }); 172 | 173 | auto start_transaction = HOSTFN("startTransaction", 3) { 174 | std::shared_ptr queryEngineHostObject = 175 | args[0].asObject(rt).asHostObject(rt); 176 | std::string body = args[1].asString(rt).utf8(rt); 177 | std::string trace = args[2].asString(rt).utf8(rt); 178 | 179 | const char *response = prisma_start_transaction( 180 | queryEngineHostObject->engine, body.c_str(), trace.c_str()); 181 | 182 | if (response == nullptr) { 183 | throw std::runtime_error("prisma engine did not start transaction"); 184 | } 185 | 186 | return jsi::String::createFromUtf8(rt, std::string(response)); 187 | }); 188 | 189 | auto commit_transaction = HOSTFN("commitTransaction", 3) { 190 | std::shared_ptr queryEngineHostObject = 191 | args[0].asObject(rt).asHostObject(rt); 192 | std::string body = args[1].asString(rt).utf8(rt); 193 | std::string trace = args[2].asString(rt).utf8(rt); 194 | 195 | const char *response = prisma_commit_transaction( 196 | queryEngineHostObject->engine, body.c_str(), trace.c_str()); 197 | 198 | if (response == nullptr) { 199 | throw std::runtime_error("prisma engine did not commit transaction"); 200 | } 201 | 202 | return jsi::String::createFromUtf8(rt, std::string(response)); 203 | }); 204 | 205 | auto rollback_transaction = HOSTFN("rollbackTransaction", 3) { 206 | std::shared_ptr queryEngineHostObject = 207 | args[0].asObject(rt).asHostObject(rt); 208 | std::string body = args[1].asString(rt).utf8(rt); 209 | std::string trace = args[2].asString(rt).utf8(rt); 210 | 211 | const char *response = prisma_rollback_transaction( 212 | queryEngineHostObject->engine, body.c_str(), trace.c_str()); 213 | 214 | if (response == nullptr) { 215 | throw std::runtime_error("prisma engine did not rollback transaction"); 216 | } 217 | 218 | return jsi::String::createFromUtf8(rt, std::string(response)); 219 | }); 220 | 221 | auto disconnect = HOSTFN("disconnect", 2) { 222 | std::shared_ptr queryEngineHostObject = 223 | args[0].asObject(rt).asHostObject(rt); 224 | std::string trace = args[1].asString(rt).utf8(rt); 225 | 226 | engine_map.erase(queryEngineHostObject->id); 227 | 228 | int res = prisma_disconnect(queryEngineHostObject->engine, trace.c_str()); 229 | 230 | if (res != PRISMA_OK) { 231 | throw std::runtime_error("Could not disconnect from prisma query engine"); 232 | } 233 | return {}; 234 | }); 235 | 236 | auto apply_pending_migrations = HOSTFN("applyPendingMigrations", 1) { 237 | std::shared_ptr queryEngineHostObject = 238 | args[0].asObject(rt).asHostObject(rt); 239 | char *error_ptr; 240 | int res = prisma_apply_pending_migrations( 241 | queryEngineHostObject->engine, migrations_path.c_str(), &error_ptr); 242 | 243 | if (res != PRISMA_OK) { 244 | auto error_string = std::string(error_ptr); 245 | free(error_ptr); 246 | throw std::runtime_error(error_string); 247 | } 248 | 249 | return {}; 250 | }); 251 | 252 | jsi::Object module = jsi::Object(rt); 253 | module.setProperty(rt, "create", std::move(create)); 254 | module.setProperty(rt, "connect", std::move(connect)); 255 | module.setProperty(rt, "execute", std::move(execute)); 256 | module.setProperty(rt, "startTransaction", std::move(start_transaction)); 257 | module.setProperty(rt, "commitTransaction", std::move(commit_transaction)); 258 | module.setProperty(rt, "rollbackTransaction", 259 | std::move(rollback_transaction)); 260 | module.setProperty(rt, "disconnect", std::move(disconnect)); 261 | module.setProperty(rt, "applyPendingMigrations", 262 | std::move(apply_pending_migrations)); 263 | 264 | rt.global().setProperty(rt, "__PrismaProxy", std::move(module)); 265 | } 266 | 267 | void invalidate() { 268 | for (auto &engine : engine_map) { 269 | prisma_destroy(engine.second->engine); 270 | } 271 | engine_map.clear(); 272 | } 273 | 274 | } // namespace prisma 275 | -------------------------------------------------------------------------------- /cpp/react-native-prisma.h: -------------------------------------------------------------------------------- 1 | #ifndef PRISMA_H 2 | #define PRISMA_H 3 | 4 | #include 5 | #include 6 | 7 | namespace prisma { 8 | 9 | namespace jsi = facebook::jsi; 10 | namespace react = facebook::react; 11 | 12 | void install_cxx(jsi::Runtime &rt, 13 | std::shared_ptr jsCallInvoker, 14 | const char *basePathStr, const char *migrations_path); 15 | void invalidate(); 16 | } // namespace prisma 17 | 18 | #endif /* PRISMA_H */ 19 | -------------------------------------------------------------------------------- /cpp/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | #include 3 | #include 4 | 5 | // Semi random function, more than enough for our purposes 6 | std::string get_uuid() { 7 | static std::random_device dev; 8 | static std::mt19937 rng(dev()); 9 | 10 | std::uniform_int_distribution dist(0, 15); 11 | 12 | const char *v = "0123456789abcdef"; 13 | const bool dash[] = {0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0}; 14 | 15 | std::string res; 16 | for (int i = 0; i < 16; i++) { 17 | if (dash[i]) 18 | res += "-"; 19 | res += v[dist(rng)]; 20 | res += v[dist(rng)]; 21 | } 22 | return res; 23 | } -------------------------------------------------------------------------------- /cpp/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | std::string get_uuid(); -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /example/.detoxrc.js: -------------------------------------------------------------------------------- 1 | /** @type {Detox.DetoxConfig} */ 2 | module.exports = { 3 | testRunner: { 4 | args: { 5 | $0: 'jest', 6 | config: 'e2e/jest.config.js', 7 | }, 8 | jest: { 9 | setupTimeout: 120000, 10 | }, 11 | }, 12 | apps: { 13 | 'ios.release': { 14 | type: 'ios.app', 15 | binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/Prisma.app', 16 | build: 17 | 'xcodebuild -quiet -workspace ios/PrismaExample.xcworkspace -scheme Release -configuration Release -sdk iphonesimulator -derivedDataPath ios/build', 18 | }, 19 | 'android.release': { 20 | type: 'android.apk', 21 | binaryPath: 'android/app/build/outputs/apk/release/app-release.apk', 22 | build: 23 | 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..', 24 | }, 25 | }, 26 | devices: { 27 | simulator: { 28 | type: 'ios.simulator', 29 | device: { 30 | type: 'iPhone 15', 31 | }, 32 | }, 33 | emulator: { 34 | type: 'android.emulator', 35 | device: { 36 | avdName: 'Pixel_API_28', 37 | }, 38 | }, 39 | }, 40 | configurations: { 41 | 'ios.sim.release': { 42 | device: 'simulator', 43 | app: 'ios.release', 44 | }, 45 | 'android.emu.release': { 46 | device: 'emulator', 47 | app: 'android.release', 48 | }, 49 | }, 50 | }; 51 | -------------------------------------------------------------------------------- /example/.ruby-version: -------------------------------------------------------------------------------- 1 | 3.3.0 2 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby ">= 2.6.10" 5 | 6 | gem 'cocoapods', '1.14' 7 | gem 'activesupport', '>= 6.1.7.3', '< 7.1.0' 8 | -------------------------------------------------------------------------------- /example/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | CFPropertyList (3.0.7) 5 | base64 6 | nkf 7 | rexml 8 | activesupport (6.1.7.6) 9 | concurrent-ruby (~> 1.0, >= 1.0.2) 10 | i18n (>= 1.6, < 2) 11 | minitest (>= 5.1) 12 | tzinfo (~> 2.0) 13 | zeitwerk (~> 2.3) 14 | addressable (2.8.6) 15 | public_suffix (>= 2.0.2, < 6.0) 16 | algoliasearch (1.27.5) 17 | httpclient (~> 2.8, >= 2.8.3) 18 | json (>= 1.5.1) 19 | atomos (0.1.3) 20 | base64 (0.2.0) 21 | claide (1.1.0) 22 | cocoapods (1.14.0) 23 | addressable (~> 2.8) 24 | claide (>= 1.0.2, < 2.0) 25 | cocoapods-core (= 1.14.0) 26 | cocoapods-deintegrate (>= 1.0.3, < 2.0) 27 | cocoapods-downloader (>= 2.0) 28 | cocoapods-plugins (>= 1.0.0, < 2.0) 29 | cocoapods-search (>= 1.0.0, < 2.0) 30 | cocoapods-trunk (>= 1.6.0, < 2.0) 31 | cocoapods-try (>= 1.1.0, < 2.0) 32 | colored2 (~> 3.1) 33 | escape (~> 0.0.4) 34 | fourflusher (>= 2.3.0, < 3.0) 35 | gh_inspector (~> 1.0) 36 | molinillo (~> 0.8.0) 37 | nap (~> 1.0) 38 | ruby-macho (>= 2.3.0, < 3.0) 39 | xcodeproj (>= 1.23.0, < 2.0) 40 | cocoapods-core (1.14.0) 41 | activesupport (>= 5.0, < 8) 42 | addressable (~> 2.8) 43 | algoliasearch (~> 1.0) 44 | concurrent-ruby (~> 1.1) 45 | fuzzy_match (~> 2.0.4) 46 | nap (~> 1.0) 47 | netrc (~> 0.11) 48 | public_suffix (~> 4.0) 49 | typhoeus (~> 1.0) 50 | cocoapods-deintegrate (1.0.5) 51 | cocoapods-downloader (2.1) 52 | cocoapods-plugins (1.0.0) 53 | nap 54 | cocoapods-search (1.0.1) 55 | cocoapods-trunk (1.6.0) 56 | nap (>= 0.8, < 2.0) 57 | netrc (~> 0.11) 58 | cocoapods-try (1.2.0) 59 | colored2 (3.1.2) 60 | concurrent-ruby (1.2.2) 61 | escape (0.0.4) 62 | ethon (0.16.0) 63 | ffi (>= 1.15.0) 64 | ffi (1.16.3) 65 | fourflusher (2.3.1) 66 | fuzzy_match (2.0.4) 67 | gh_inspector (1.1.3) 68 | httpclient (2.8.3) 69 | i18n (1.14.1) 70 | concurrent-ruby (~> 1.0) 71 | json (2.7.1) 72 | minitest (5.20.0) 73 | molinillo (0.8.0) 74 | nanaimo (0.3.0) 75 | nap (1.1.0) 76 | netrc (0.11.0) 77 | nkf (0.2.0) 78 | public_suffix (4.0.7) 79 | rexml (3.2.6) 80 | ruby-macho (2.5.1) 81 | typhoeus (1.4.1) 82 | ethon (>= 0.9.0) 83 | tzinfo (2.0.6) 84 | concurrent-ruby (~> 1.0) 85 | xcodeproj (1.24.0) 86 | CFPropertyList (>= 2.3.3, < 4.0) 87 | atomos (~> 0.1.3) 88 | claide (>= 1.0.2, < 2.0) 89 | colored2 (~> 3.1) 90 | nanaimo (~> 0.3.0) 91 | rexml (~> 3.2.4) 92 | zeitwerk (2.6.13) 93 | 94 | PLATFORMS 95 | ruby 96 | 97 | DEPENDENCIES 98 | activesupport (>= 6.1.7.3, < 7.1.0) 99 | cocoapods (= 1.14) 100 | 101 | RUBY VERSION 102 | ruby 2.7.6p219 103 | 104 | BUNDLED WITH 105 | 2.4.2 106 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). 2 | 3 | # Getting Started 4 | 5 | >**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. 6 | 7 | ## Step 1: Start the Metro Server 8 | 9 | First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. 10 | 11 | To start Metro, run the following command from the _root_ of your React Native project: 12 | 13 | ```bash 14 | # using npm 15 | npm start 16 | 17 | # OR using Yarn 18 | yarn start 19 | ``` 20 | 21 | ## Step 2: Start your Application 22 | 23 | Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: 24 | 25 | ### For Android 26 | 27 | ```bash 28 | # using npm 29 | npm run android 30 | 31 | # OR using Yarn 32 | yarn android 33 | ``` 34 | 35 | ### For iOS 36 | 37 | ```bash 38 | # using npm 39 | npm run ios 40 | 41 | # OR using Yarn 42 | yarn ios 43 | ``` 44 | 45 | If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. 46 | 47 | This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. 48 | 49 | ## Step 3: Modifying your App 50 | 51 | Now that you have successfully run the app, let's modify it. 52 | 53 | 1. Open `App.tsx` in your text editor of choice and edit some lines. 54 | 2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! 55 | 56 | For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! 57 | 58 | ## Congratulations! :tada: 59 | 60 | You've successfully run and modified your React Native App. :partying_face: 61 | 62 | ### Now what? 63 | 64 | - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). 65 | - If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). 66 | 67 | # Troubleshooting 68 | 69 | If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. 70 | 71 | # Learn More 72 | 73 | To learn more about React Native, take a look at the following resources: 74 | 75 | - [React Native Website](https://reactnative.dev) - learn more about React Native. 76 | - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment. 77 | - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. 78 | - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. 79 | - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. 80 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "org.jetbrains.kotlin.android" 3 | apply plugin: "com.facebook.react" 4 | apply from: "../../../react-native-prisma.gradle" 5 | 6 | /** 7 | * This is the configuration block to customize your React Native Android app. 8 | * By default you don't need to apply any configuration, just uncomment the lines you need. 9 | */ 10 | react { 11 | /* Folders */ 12 | // The root of your project, i.e. where "package.json" lives. Default is '..' 13 | // root = file("../") 14 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native 15 | // reactNativeDir = file("../node_modules/react-native") 16 | // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen 17 | // codegenDir = file("../node_modules/@react-native/codegen") 18 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js 19 | // cliFile = file("../node_modules/react-native/cli.js") 20 | 21 | /* Variants */ 22 | // The list of variants to that are debuggable. For those we're going to 23 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 24 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 25 | // debuggableVariants = ["liteDebug", "prodDebug"] 26 | 27 | /* Bundling */ 28 | // A list containing the node command and its flags. Default is just 'node'. 29 | // nodeExecutableAndArgs = ["node"] 30 | // 31 | // The command to run when bundling. By default is 'bundle' 32 | // bundleCommand = "ram-bundle" 33 | // 34 | // The path to the CLI configuration file. Default is empty. 35 | // bundleConfig = file(../rn-cli.config.js) 36 | // 37 | // The name of the generated asset file containing your JS bundle 38 | // bundleAssetName = "MyApplication.android.bundle" 39 | // 40 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 41 | // entryFile = file("../js/MyApplication.android.js") 42 | // 43 | // A list of extra flags to pass to the 'bundle' commands. 44 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 45 | // extraPackagerArgs = [] 46 | 47 | /* Hermes Commands */ 48 | // The hermes compiler command to run. By default it is 'hermesc' 49 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 50 | // 51 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 52 | // hermesFlags = ["-O", "-output-source-map"] 53 | } 54 | 55 | /** 56 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 57 | */ 58 | def enableProguardInReleaseBuilds = false 59 | 60 | /** 61 | * The preferred build flavor of JavaScriptCore (JSC) 62 | * 63 | * For example, to use the international variant, you can use: 64 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 65 | * 66 | * The international variant includes ICU i18n library and necessary data 67 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 68 | * give correct results when using with locales other than en-US. Note that 69 | * this variant is about 6MiB larger per architecture than default. 70 | */ 71 | def jscFlavor = 'org.webkit:android-jsc:+' 72 | 73 | android { 74 | ndkVersion rootProject.ext.ndkVersion 75 | buildToolsVersion rootProject.ext.buildToolsVersion 76 | compileSdk rootProject.ext.compileSdkVersion 77 | 78 | namespace "com.prismaexample" 79 | defaultConfig { 80 | applicationId "com.prismaexample" 81 | minSdkVersion rootProject.ext.minSdkVersion 82 | targetSdkVersion rootProject.ext.targetSdkVersion 83 | versionCode 1 84 | versionName "1.0" 85 | testBuildType System.getProperty('testBuildType', 'debug') 86 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 87 | } 88 | signingConfigs { 89 | debug { 90 | storeFile file('debug.keystore') 91 | storePassword 'android' 92 | keyAlias 'androiddebugkey' 93 | keyPassword 'android' 94 | } 95 | } 96 | buildTypes { 97 | debug { 98 | signingConfig signingConfigs.debug 99 | } 100 | release { 101 | // Caution! In production, you need to generate your own keystore file. 102 | // see https://reactnative.dev/docs/signed-apk-android. 103 | signingConfig signingConfigs.debug 104 | minifyEnabled enableProguardInReleaseBuilds 105 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 106 | proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro" 107 | } 108 | } 109 | } 110 | 111 | dependencies { 112 | // The version of react-native is set by the React Native Gradle Plugin 113 | implementation("com.facebook.react:react-android") 114 | implementation("com.facebook.react:flipper-integration") 115 | androidTestImplementation('com.wix:detox:+') 116 | implementation('androidx.appcompat:appcompat:1.1.0') 117 | 118 | if (hermesEnabled.toBoolean()) { 119 | implementation("com.facebook.react:hermes-android") 120 | } else { 121 | implementation jscFlavor 122 | } 123 | } 124 | 125 | configurations.all { 126 | resolutionStrategy { 127 | force 'androidx.test:core:1.5.0' 128 | } 129 | } 130 | 131 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 132 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/androidTest/java/com/prismaexample/DetoxTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.prismaexample; 3 | 4 | import com.wix.detox.Detox; 5 | import com.wix.detox.config.DetoxConfig; 6 | 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import androidx.test.ext.junit.runners.AndroidJUnit4; 12 | import androidx.test.filters.LargeTest; 13 | import androidx.test.rule.ActivityTestRule; 14 | 15 | @RunWith(AndroidJUnit4.class) 16 | @LargeTest 17 | public class DetoxTest { 18 | @Rule 19 | public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false); 20 | 21 | @Test 22 | public void runDetoxTests() { 23 | DetoxConfig detoxConfig = new DetoxConfig(); 24 | detoxConfig.idlePolicyConfig.masterTimeoutSec = 90; 25 | detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60; 26 | detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60); 27 | 28 | Detox.runTests(mActivityRule, detoxConfig); 29 | } 30 | } -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/migrations/0_init/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT, 6 | "nick" TEXT 7 | ); 8 | 9 | -- CreateTable 10 | CREATE TABLE "Profile" ( 11 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 12 | "bio" TEXT NOT NULL, 13 | "userId" INTEGER NOT NULL, 14 | CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE 15 | ); 16 | 17 | -- CreateTable 18 | CREATE TABLE "Post" ( 19 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 20 | "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, 21 | "updatedAt" DATETIME NOT NULL, 22 | "title" TEXT NOT NULL, 23 | "published" BOOLEAN NOT NULL DEFAULT false, 24 | "authorId" INTEGER NOT NULL, 25 | CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE 26 | ); 27 | 28 | -- CreateTable 29 | CREATE TABLE "Category" ( 30 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 31 | "name" TEXT NOT NULL 32 | ); 33 | 34 | -- CreateTable 35 | CREATE TABLE "_CategoryToPost" ( 36 | "A" INTEGER NOT NULL, 37 | "B" INTEGER NOT NULL, 38 | CONSTRAINT "_CategoryToPost_A_fkey" FOREIGN KEY ("A") REFERENCES "Category" ("id") ON DELETE CASCADE ON UPDATE CASCADE, 39 | CONSTRAINT "_CategoryToPost_B_fkey" FOREIGN KEY ("B") REFERENCES "Post" ("id") ON DELETE CASCADE ON UPDATE CASCADE 40 | ); 41 | 42 | -- CreateIndex 43 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 44 | 45 | -- CreateIndex 46 | CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId"); 47 | 48 | -- CreateIndex 49 | CREATE UNIQUE INDEX "_CategoryToPost_AB_unique" ON "_CategoryToPost"("A", "B"); 50 | 51 | -- CreateIndex 52 | CREATE INDEX "_CategoryToPost_B_index" ON "_CategoryToPost"("B"); 53 | 54 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/migrations/20240118142005_nick2/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "nick2" TEXT; 3 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/migrations/20240119102352_nick3/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "nick3" TEXT; 3 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/migrations/20240119143417_nick4/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "nick4" TEXT; 3 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/migrations/20240122145141_my_field/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "myField" TEXT; 3 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/prismaexample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.prismaexample 2 | 3 | import com.facebook.react.ReactActivity 4 | import com.facebook.react.ReactActivityDelegate 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate 7 | 8 | class MainActivity : ReactActivity() { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | override fun getMainComponentName(): String = "PrismaExample" 15 | 16 | /** 17 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] 18 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] 19 | */ 20 | override fun createReactActivityDelegate(): ReactActivityDelegate = 21 | DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) 22 | } 23 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/prismaexample/MainApplication.kt: -------------------------------------------------------------------------------- 1 | package com.prismaexample 2 | 3 | import android.app.Application 4 | import com.facebook.react.PackageList 5 | import com.facebook.react.ReactApplication 6 | import com.facebook.react.ReactHost 7 | import com.facebook.react.ReactNativeHost 8 | import com.facebook.react.ReactPackage 9 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load 10 | import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost 11 | import com.facebook.react.defaults.DefaultReactNativeHost 12 | import com.facebook.react.flipper.ReactNativeFlipper 13 | import com.facebook.soloader.SoLoader 14 | 15 | class MainApplication : Application(), ReactApplication { 16 | 17 | override val reactNativeHost: ReactNativeHost = 18 | object : DefaultReactNativeHost(this) { 19 | override fun getPackages(): List { 20 | // Packages that cannot be autolinked yet can be added manually here, for example: 21 | // packages.add(new MyReactNativePackage()); 22 | return PackageList(this).packages 23 | } 24 | 25 | override fun getJSMainModuleName(): String = "index" 26 | 27 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG 28 | 29 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED 30 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED 31 | } 32 | 33 | override val reactHost: ReactHost 34 | get() = getDefaultReactHost(this.applicationContext, reactNativeHost) 35 | 36 | override fun onCreate() { 37 | super.onCreate() 38 | SoLoader.init(this, false) 39 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 40 | // If you opted-in for the New Architecture, we load the native entry point for this app. 41 | load() 42 | } 43 | ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PrismaExample 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/xml/network_security_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10.0.2.2 5 | localhost 6 | 7 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | buildToolsVersion = "34.0.0" 4 | minSdkVersion = 21 5 | compileSdkVersion = 34 6 | targetSdkVersion = 34 7 | ndkVersion = "25.1.8937393" 8 | kotlinVersion = "1.8.0" 9 | } 10 | repositories { 11 | google() 12 | mavenCentral() 13 | 14 | } 15 | dependencies { 16 | classpath("com.android.tools.build:gradle") 17 | classpath("com.facebook.react:react-native-gradle-plugin") 18 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | maven { 25 | url "$rootDir/../node_modules/detox/Detox-android" 26 | } 27 | } 28 | } 29 | 30 | apply plugin: "com.facebook.react.rootproject" 31 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Use this property to specify which architecture you want to build. 28 | # You can also override it from the CLI using 29 | # ./gradlew -PreactNativeArchitectures=x86_64 30 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 31 | 32 | # Use this property to enable support to the new architecture. 33 | # This will allow you to use TurboModules and the Fabric render in 34 | # your application. You should enable this flag either if you want 35 | # to write custom TurboModules/Fabric components OR use libraries that 36 | # are providing them. 37 | newArchEnabled=false 38 | 39 | # Use this property to enable or disable the Hermes JS engine. 40 | # If set to false, you will be using JSC instead. 41 | hermesEnabled=true 42 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command; 206 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 207 | # shell script including quotes and variable substitutions, so put them in 208 | # double quotes to make sure that they get re-expanded; and 209 | # * put everything else in single quotes, so that it's not re-expanded. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'PrismaExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | includeBuild('../node_modules/@react-native/gradle-plugin') 5 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "PrismaExample", 3 | "displayName": "PrismaExample" 4 | } 5 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | const path = require('path'); 3 | 4 | const pak = require('../package.json'); 5 | 6 | module.exports = { 7 | presets: ['module:@react-native/babel-preset', 'nativewind/babel'], 8 | plugins: [ 9 | [ 10 | 'module-resolver', 11 | { 12 | extensions: ['.tsx', '.ts', '.js', '.json'], 13 | alias: { 14 | [pak.name]: path.join(__dirname, '..', pak.source), 15 | }, 16 | }, 17 | ], 18 | ], 19 | }; 20 | -------------------------------------------------------------------------------- /example/dev.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/dev.db -------------------------------------------------------------------------------- /example/dev.db-journal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/dev.db-journal -------------------------------------------------------------------------------- /example/e2e/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('@jest/types').Config.InitialOptions} */ 2 | module.exports = { 3 | rootDir: '..', 4 | testMatch: ['/e2e/**/*.test.js'], 5 | testTimeout: 120000, 6 | maxWorkers: 1, 7 | globalSetup: 'detox/runners/jest/globalSetup', 8 | globalTeardown: 'detox/runners/jest/globalTeardown', 9 | reporters: ['detox/runners/jest/reporter'], 10 | testEnvironment: 'detox/runners/jest/testEnvironment', 11 | verbose: true, 12 | }; 13 | -------------------------------------------------------------------------------- /example/e2e/starter.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | describe('Example', () => { 3 | beforeAll(async () => { 4 | await device.launchApp(); 5 | }); 6 | 7 | beforeEach(async () => { 8 | await device.reloadReactNative(); 9 | }); 10 | 11 | it('Show basic test passed indicator', async () => { 12 | await expect(element(by.id('test_indicator'))).toBeVisible(); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /example/global.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /example/globals.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | 3 | import { name as appName } from './app.json'; 4 | import App from './src/App'; 5 | 6 | AppRegistry.registerComponent(appName, () => App); 7 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/ios/.xcode.env.local: -------------------------------------------------------------------------------- 1 | export NODE_BINARY=$(command -v node) -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // PrismaExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Resolve react_native_pods.rb with node to allow for hoisting 2 | require Pod::Executable.execute_command('node', ['-p', 3 | 'require.resolve( 4 | "react-native/scripts/react_native_pods.rb", 5 | {paths: [process.argv[1]]}, 6 | )', __dir__]).strip 7 | 8 | platform :ios, min_ios_version_supported 9 | prepare_react_native_project! 10 | inhibit_all_warnings! 11 | 12 | linkage = ENV['USE_FRAMEWORKS'] 13 | if linkage != nil 14 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 15 | use_frameworks! :linkage => linkage.to_sym 16 | end 17 | 18 | target 'PrismaExample' do 19 | config = use_native_modules! 20 | 21 | use_react_native!( 22 | :path => config[:reactNativePath], 23 | :app_path => "#{Pod::Config.instance.installation_root}/.." 24 | ) 25 | 26 | post_install do |installer| 27 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 28 | react_native_post_install( 29 | installer, 30 | config[:reactNativePath], 31 | :mac_catalyst_enabled => false 32 | ) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /example/ios/PrismaExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/ios/PrismaExample.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 44 | 46 | 52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 68 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /example/ios/PrismaExample.xcodeproj/xcshareddata/xcschemes/Release.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/ios/PrismaExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/PrismaExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "GCDWebServer/GCDWebServer.h" 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"PrismaExample"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | [GCDWebServer setLogLevel:4]; 15 | 16 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 17 | } 18 | 19 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 20 | { 21 | return [self getBundleURL]; 22 | } 23 | 24 | - (NSURL *)getBundleURL 25 | { 26 | #if DEBUG 27 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 28 | #else 29 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 30 | #endif 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Frame 20.png", 5 | "idiom" : "universal", 6 | "platform" : "ios", 7 | "size" : "1024x1024" 8 | } 9 | ], 10 | "info" : { 11 | "author" : "xcode", 12 | "version" : 1 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/Images.xcassets/AppIcon.appiconset/Frame 20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/ios/PrismaExample/Images.xcassets/AppIcon.appiconset/Frame 20.png -------------------------------------------------------------------------------- /example/ios/PrismaExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/Images.xcassets/Logo.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Frame 20.png", 5 | "idiom" : "universal" 6 | } 7 | ], 8 | "info" : { 9 | "author" : "xcode", 10 | "version" : 1 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/Images.xcassets/Logo.imageset/Frame 20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prisma/react-native-prisma/78fa48b7c9b67757b4ecd10a713fe8c0964cb78f/example/ios/PrismaExample/Images.xcassets/Logo.imageset/Frame 20.png -------------------------------------------------------------------------------- /example/ios/PrismaExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | Prisma 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSAllowsArbitraryLoads 30 | 31 | NSAllowsLocalNetworking 32 | 33 | 34 | NSLocationWhenInUseUsageDescription 35 | 36 | UILaunchStoryboardName 37 | LaunchScreen 38 | UIRequiredDeviceCapabilities 39 | 40 | armv7 41 | 42 | UISupportedInterfaceOrientations 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | UIViewControllerBasedStatusBarAppearance 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/ios/PrismaExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/ios/PrismaExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/PrismaExampleTests/PrismaExampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface PrismaExampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation PrismaExampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction( 38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 39 | if (level >= RCTLogLevelError) { 40 | redboxError = message; 41 | } 42 | }); 43 | #endif 44 | 45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 48 | 49 | foundElement = [self findSubviewInView:vc.view 50 | matching:^BOOL(UIView *view) { 51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 52 | return YES; 53 | } 54 | return NO; 55 | }]; 56 | } 57 | 58 | #ifdef DEBUG 59 | RCTSetLogFunction(RCTDefaultLogFunction); 60 | #endif 61 | 62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /example/ios/link-assets-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "migIndex": 1, 3 | "data": [ 4 | { 5 | "path": "migrations/20240117094901_init/migration.sql", 6 | "sha1": "c2cba8c542661584c2409ac71985d902b25bdd71" 7 | }, 8 | { 9 | "path": "migrations/migration_lock.toml", 10 | "sha1": "d31af1640ea175950b3b0e25f68481f74ef5d8ed" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); 3 | const escape = require('escape-string-regexp'); 4 | const exclusionList = require('metro-config/src/defaults/exclusionList'); 5 | const { withNativeWind } = require('nativewind/metro'); 6 | const path = require('path'); 7 | 8 | const pak = require('../package.json'); 9 | 10 | const root = path.resolve(__dirname, '..'); 11 | const modules = Object.keys({ ...pak.peerDependencies }); 12 | 13 | /** 14 | * Metro configuration 15 | * https://facebook.github.io/metro/docs/configuration 16 | * 17 | * @type {import('metro-config').MetroConfig} 18 | */ 19 | const config = { 20 | watchFolders: [root], 21 | 22 | // We need to make sure that only one version is loaded for peerDependencies 23 | // So we block them at the root, and alias them to the versions in example's node_modules 24 | resolver: { 25 | blacklistRE: exclusionList( 26 | modules.map( 27 | (m) => 28 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 29 | ) 30 | ), 31 | 32 | extraNodeModules: modules.reduce((acc, name) => { 33 | acc[name] = path.join(__dirname, 'node_modules', name); 34 | return acc; 35 | }, {}), 36 | }, 37 | 38 | transformer: { 39 | getTransformOptions: async () => ({ 40 | transform: { 41 | experimentalImportSupport: false, 42 | inlineRequires: true, 43 | }, 44 | }), 45 | }, 46 | }; 47 | 48 | module.exports = withNativeWind( 49 | mergeConfig(getDefaultConfig(__dirname), config), 50 | { input: './global.css' } 51 | ); 52 | -------------------------------------------------------------------------------- /example/migrations/0_init/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT, 6 | "nick" TEXT 7 | ); 8 | 9 | -- CreateTable 10 | CREATE TABLE "Profile" ( 11 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 12 | "bio" TEXT NOT NULL, 13 | "userId" INTEGER NOT NULL, 14 | CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE 15 | ); 16 | 17 | -- CreateTable 18 | CREATE TABLE "Post" ( 19 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 20 | "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, 21 | "updatedAt" DATETIME NOT NULL, 22 | "title" TEXT NOT NULL, 23 | "published" BOOLEAN NOT NULL DEFAULT false, 24 | "authorId" INTEGER NOT NULL, 25 | CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE 26 | ); 27 | 28 | -- CreateTable 29 | CREATE TABLE "Category" ( 30 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 31 | "name" TEXT NOT NULL 32 | ); 33 | 34 | -- CreateTable 35 | CREATE TABLE "_CategoryToPost" ( 36 | "A" INTEGER NOT NULL, 37 | "B" INTEGER NOT NULL, 38 | CONSTRAINT "_CategoryToPost_A_fkey" FOREIGN KEY ("A") REFERENCES "Category" ("id") ON DELETE CASCADE ON UPDATE CASCADE, 39 | CONSTRAINT "_CategoryToPost_B_fkey" FOREIGN KEY ("B") REFERENCES "Post" ("id") ON DELETE CASCADE ON UPDATE CASCADE 40 | ); 41 | 42 | -- CreateIndex 43 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 44 | 45 | -- CreateIndex 46 | CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId"); 47 | 48 | -- CreateIndex 49 | CREATE UNIQUE INDEX "_CategoryToPost_AB_unique" ON "_CategoryToPost"("A", "B"); 50 | 51 | -- CreateIndex 52 | CREATE INDEX "_CategoryToPost_B_index" ON "_CategoryToPost"("B"); 53 | 54 | -------------------------------------------------------------------------------- /example/migrations/20240118142005_nick2/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "nick2" TEXT; 3 | -------------------------------------------------------------------------------- /example/migrations/20240119102352_nick3/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "nick3" TEXT; 3 | -------------------------------------------------------------------------------- /example/migrations/20240119143417_nick4/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "nick4" TEXT; 3 | -------------------------------------------------------------------------------- /example/migrations/20240122145141_my_field/migration.sql: -------------------------------------------------------------------------------- 1 | -- AlterTable 2 | ALTER TABLE "User" ADD COLUMN "myField" TEXT; 3 | -------------------------------------------------------------------------------- /example/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-prisma-example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios --simulator='iPhone 15' --scheme='Debug'", 8 | "start": "react-native start", 9 | "pods": "pod-install", 10 | "build:android": "cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a", 11 | "build:ios": "cd ios && xcodebuild -workspace PrismaExample.xcworkspace -scheme PrismaExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO", 12 | "ios:release": "react-native run-ios --simulator='iPhone 15' --scheme='Release'", 13 | "prisma:generate": "prisma generate" 14 | }, 15 | "dependencies": { 16 | "@prisma/client": "6.1.0-dev.17", 17 | "chance": "^1.1.11", 18 | "nativewind": "^4.0.23", 19 | "react": "18.2.0", 20 | "react-native": "0.73.2", 21 | "react-native-http-bridge-refurbished": "^1.2.9", 22 | "react-native-network-info": "^5.2.1", 23 | "react-native-quick-base64": "^2.0.8", 24 | "react-native-reanimated": "^3.7.2", 25 | "react-native-url-polyfill": "^2.0.0", 26 | "text-encoding": "^0.7.0" 27 | }, 28 | "devDependencies": { 29 | "@babel/core": "^7.20.0", 30 | "@babel/preset-env": "^7.20.0", 31 | "@babel/runtime": "^7.20.0", 32 | "@react-native/babel-preset": "^0.73.18", 33 | "@react-native/metro-config": "^0.73.2", 34 | "@react-native/typescript-config": "^0.73.1", 35 | "@types/chance": "^1.1.6", 36 | "@types/text-encoding": "^0", 37 | "babel-plugin-module-resolver": "^5.0.0", 38 | "detox": "20.20.3", 39 | "jest": "^29", 40 | "pod-install": "0.2.0", 41 | "prisma": "6.1.0-dev.17", 42 | "tailwindcss": "^3.4.0" 43 | }, 44 | "engines": { 45 | "node": ">=18" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | const path = require('path'); 3 | 4 | const pak = require('../package.json'); 5 | 6 | module.exports = { 7 | dependencies: { 8 | [pak.name]: { 9 | root: path.join(__dirname, '..'), 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /example/schema.prisma: -------------------------------------------------------------------------------- 1 | generator client { 2 | provider = "prisma-client-js" 3 | previewFeatures = ["reactNative"] 4 | } 5 | 6 | datasource db { 7 | provider = "sqlite" 8 | url = "file:./dev.db" 9 | } 10 | 11 | model User { 12 | id Int @id @default(autoincrement()) 13 | email String @unique 14 | name String? 15 | posts Post[] 16 | profile Profile? 17 | nick String? 18 | nick2 String? 19 | nick3 String? 20 | nick4 String? 21 | myField String? 22 | } 23 | 24 | model Profile { 25 | id Int @id @default(autoincrement()) 26 | bio String 27 | user User @relation(fields: [userId], references: [id]) 28 | userId Int @unique 29 | } 30 | 31 | model Post { 32 | id Int @id @default(autoincrement()) 33 | createdAt DateTime @default(now()) 34 | updatedAt DateTime @updatedAt 35 | title String 36 | published Boolean @default(false) 37 | author User @relation(fields: [authorId], references: [id]) 38 | authorId Int 39 | categories Category[] 40 | } 41 | 42 | model Category { 43 | id Int @id @default(autoincrement()) 44 | name String 45 | posts Post[] 46 | } 47 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import '@prisma/react-native'; 2 | import React, { useEffect, useState } from 'react'; 3 | import { 4 | Clipboard, 5 | SafeAreaView, 6 | ScrollView, 7 | Text, 8 | TouchableOpacity, 9 | View, 10 | } from 'react-native'; 11 | import { NetworkInfo } from 'react-native-network-info'; 12 | import { atob, btoa } from 'react-native-quick-base64'; 13 | 14 | import 'react-native-url-polyfill/auto'; 15 | import '../global.css'; 16 | import { Button } from './Button'; 17 | import './server'; 18 | import { 19 | hooksPrisma, 20 | createRandomUser, 21 | deleteUsers, 22 | initializeDB, 23 | runE2EQuery, 24 | // createRandomUserGeneric, 25 | } from './db'; 26 | 27 | // global.TextEncoder = require('text-encoding').TextEncoder; 28 | global.atob = atob; 29 | global.btoa = btoa; 30 | 31 | export default function App() { 32 | const [prismaTime, setPrismaTime] = useState(0); 33 | const [IP, setIP] = useState(''); 34 | const [dbInitialized, setDbInitialized] = useState(false); 35 | const [e2eSuccess, setE2ESuccess] = useState(false); 36 | 37 | useEffect(() => { 38 | const setup = async () => { 39 | await initializeDB(); 40 | NetworkInfo.getIPAddress().then((ip) => { 41 | setIP(`${ip}:3000`); 42 | }); 43 | setDbInitialized(true); 44 | await runE2EQuery(); 45 | setE2ESuccess(true); 46 | }; 47 | 48 | setup(); 49 | }, []); 50 | 51 | const createUser = async () => { 52 | const start = performance.now(); 53 | 54 | await createRandomUser(); 55 | 56 | const end = performance.now(); 57 | setPrismaTime(end - start); 58 | }; 59 | 60 | const users = hooksPrisma.user.useFindMany(); 61 | 62 | if (!dbInitialized) { 63 | return ( 64 | 65 | Initializing database... 66 | 67 | ); 68 | } 69 | 70 | const copyIP = () => { 71 | Clipboard.setString(IP); 72 | console.warn('IP copied to clipboard'); 73 | }; 74 | 75 | return ( 76 | 77 | 78 | 79 | ▲ Prisma 80 | {e2eSuccess ? ( 81 | 85 | ) : ( 86 | 90 | )} 91 | 92 | 93 | 94 | HTTP Server Running on Port 3000 95 | 96 | 97 | 98 | 99 | Engine Response 100 | 101 | {prismaTime.toFixed(0)}ms 102 | 103 | 104 | {JSON.stringify(users, null, 4)} 105 | 106 | 107 |