OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog ServiceOceanBase DataPilot

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog ServiceOceanBase DataPilot
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Database

  • Overview of the ecosystem
  • ORM frameworks
    • Java
      • Spring Boot
      • Spring Batch
      • Use Spring JDBC to connect to OceanBase Database
      • Spring Data JPA
      • Hibernate
      • MyBatis
      • jOOQ
    • Python
      • Use SQLAlchemy to connect to OceanBase Database
      • Connect to OceanBase Database by using peewee
      • Use Tortoise ORM to connect to OceanBase Database
    • Go
      • Connect to OceanBase Database by using GORM
      • beego ORM
    • Rust
      • SeaORM Connection to OceanBase Database
      • Diesel Connection to OceanBase Database
    • Ruby
      • Active Record
      • Sequel Connection to OceanBase Database
      • Connect to OceanBase Database by using Ruby on Rails
    • Node.js
      • Sequelize
      • TypeORM
      • Prisma
      • Drizzle
    • C#
      • Dapper
      • SqlSugar
      • FreeSQL
    • PHP
      • Connect to OceanBase Database by using the Yii 2.0 ORM
      • Connect to OceanBase Database by using Laravel Eloquent ORM
      • CakePHP
  • Database version management
    • Liquibase
    • Flyway
  • Data integration
    • Flink
      • Apache Flink
      • Flink DirectLoad
      • Flink Connector OceanBase
    • dbt
    • SeaTunnel
    • Maxwell
    • Debezium
    • Spark Catalog
    • NiFi
    • Qlik Replicate
    • RisingWave CDC
    • Flume
    • Migrate data from SQL Server to OceanBase Database by using MySQL Workbench
  • SQL development
    • WebLogic
    • DBeaver
    • Navicat
    • DataGrip
    • TablePlus
    • DMS
  • Orchestration and scheduling
    • Airflow
    • PowerJob
    • DolphinScheduler
    • Linkis
  • Visualization tools
    • Superset
    • Excel
    • Power BI
    • Quick BI
    • Tableau
    • GuanData
    • vividime
    • DataV
    • Metabase
    • Redash
    • FineReport
  • Database management
    • NineData
    • Bytebase
    • DataHub
    • Zabbix
  • AI
    • OpenAI
    • Qwen
    • LangChain
    • LlamaIndex
    • Dify
    • n8n
    • Trae
    • SpringAI
    • Cline
    • Cursor
    • Continue
    • MCP Toolbox
    • CamelAI
    • Firecrawl
    • Hugging Face
    • Ollama
    • Google Gemini
    • Cloudflare Workers AI
    • DB GPT
    • Jina AI
    • Augment Code
    • Claude Code
    • Kiro
    • GPT4All
  • Application
    • Ghost
    • Jira
    • Seata
    • SAP Crystal Reports
  • Middleware
    • Apache Pulsar

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Database
  3. master

Connect to OceanBase Database by using Prisma

Last Updated:2026-09-04 07:40:45

Prerequisites
Procedure
Step 1: Check the versions of Node.js and npm
Step 2: Install the required dependencies
Step 3: Try out some data operations
References

Applicability

Prisma is applicable to OceanBase Database's MySQL-compatible mode.

Prisma is a modern database toolkit that provides type-safe access to your data. This guide walks you through connecting to OceanBase's MySQL-compatible mode by using Prisma.

Prerequisites

  • You have installed Node.js 14.0.0 or later.
  • You have installed the npm or Yarn package manager.
  • You have installed deployed OceanBase Database and created a MySQL-compatible tenant.

Procedure

  1. Check the versions of Node.js and npm.
  2. Install the required dependencies.
  3. Obtain the connection information of OceanBase Database.
  4. Create and configure the project.
  5. Run the sample program.

Step 1: Check the versions of Node.js and npm

Open the terminal and run the following commands to check the versions of Node.js and npm:

node -v
npm -v

Step 2: Install the required dependencies

  1. Create a project directory and initialize it:

    mkdir prisma-oceanbase-demo
    cd prisma-oceanbase-demo
    npm init -y
    npm install prisma @prisma/client
    
  2. Initialize Prisma:

    npx prisma init --datasource-provider mysql
    

    After initialization, you will see the following output:

    ✔ Your Prisma schema was created at prisma/schema.prisma
      You can now open it in your favorite editor.
    
    Next steps:
    1. Set the DATABASE_URL in the .env file to point to your existing database.
    2. Run prisma db pull to turn your database schema into a Prisma schema.
    3. Run prisma generate to generate the Prisma Client.
    4. Start querying your database with Prisma Client.
    
    More information in our documentation:
    https://pris.ly/d/getting-started
    
  3. Configure the environment variables:

    After initialization, Prisma will automatically create the .env file and the prisma/schema.prisma file. Edit the .env file and set the connection information for OceanBase Database:

    # .env
    DATABASE_URL="mysql://username:password@host:port/database?schema=public"
    

    Notice

    • Replace username, password, host, port, and database with your OceanBase Database connection information.
    • Make sure that the schema parameter matches the name of your database schema.
    • If you use an SSL connection, add the ?sslmode=require parameter.
  4. Pull the database schema (if your database already contains tables):

    npx prisma db pull
    

    This command pulls the table structure from the existing database and updates the prisma/schema.prisma file.

  5. Generate the Prisma client:

    npx prisma generate
    

    This command reads the prisma/schema.prisma file and generates the corresponding TypeScript type definitions and Prisma client code.

  6. Create a database migration (for new projects only):

    npx prisma migrate dev --name init
    

    For a new project, this command will:

    • Creates a migration file
    • Applies the migration to the database
    • Regenerates the Prisma client

    Notice

    If you have already used db pull to pull the schema from an existing database, you can skip this step.

Step 3: Try out some data operations

This section shows how to use Prisma to insert and query data in the users table.

1. Initialize the Prisma client

First, create an index.js file in your project's root directory and add the following code:

const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()

async function main() {
  // 1. Create a new user
  const newUser = await prisma.users.create({
    data: {
      username: 'ambermoe',
      email: 'amber@example.com',
      password_hash: 'hashed_password_here',  // Use bcrypt for password hashing in production
    },
  })
  console.log('User created successfully:', newUser)

  // 2. Query user
  const user = await prisma.users.findUnique({
    where: {
      email: 'amber@example.com',
    },
  })
  console.log('Retrieved user:', user)
}

main()
  .catch((e) => {
    console.error('Error:', e)
    process.exit(1)
  })
  .finally(async () => {
    await prisma.$disconnect()
  })

2. Run the example

Make sure you have completed the following steps:

  1. The users table model is correctly defined in prisma/schema.prisma

  2. For new projects, apply the database migration:

    npx prisma migrate dev --name init
    

    If you pulled the schema from an existing database, you can skip this step.

  3. Generate the Prisma client:

    npx prisma generate
    
  4. Run the example code:

    node index.js
    

After running the code, you will see the information of the newly created user and the queried user in the console.

User created successfully: {
  id: 2,
  username: 'ambermoe',
  email: 'amber@example.com',
  password_hash: 'hashed_password_here',
  created_at: 2025-06-04T03:40:43.000Z,
  updated_at: 2025-06-04T03:40:43.000Z
}
Retrieved user: {
  id: 2,
  username: 'ambermoe',
  email: 'amber@example.com',
  password_hash: 'hashed_password_here',
  created_at: 2025-06-04T03:40:43.000Z,
  updated_at: 2025-06-04T03:40:43.000Z
}

Note

In real-world projects, make sure to:

  • Encrypt passwords (for example, using bcrypt)
  • Handle potential errors appropriately
  • Manage database connection information with environment variables
  • Add proper input validation

References

  • Prisma Documentation
  • OceanBase Documentation

Previous topic

TypeORM
Last

Next topic

Drizzle
Next
on this page
Prerequisites
Procedure
Step 1: Check the versions of Node.js and npm
Step 2: Install the required dependencies
Step 3: Try out some data operations
References