feat: Add prisma sample for javascript #73
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connect to OceanBase with Prisma
This document describes how to connect to OceanBase with Prisma.
Preparation
Make sure
Node.js
andnpm
are installed.Configuration
Clone the project and navigate to the appropriate directory:
Set the global environment variables (for reasons see https://open.oceanbase.com/blog/15137753618):
Install dependencies (note that the versions of
prisma
and@prisma/client
should be^5.20.0
or higher):Modify the connection string in the
.env
file, formatted as follows. Note thatprefer_socket=false
must be set to avoid errors when connecting to OceanBase.DATABASE_URL="mysql://root:@127.0.0.1:2881/test?prefer_socket=false&a=.psdb.cloud"
Execute the following command to synchronize the
User
,Post
andProfile
data models defined inprisma/schema.prisma
to the database:Execute
index.ts
:The output should be as follows, indicating successful execution:
Check the corresponding
users
,posts
andprofiles
tables and the data has been inserted: