GithubHelp home page GithubHelp logo

prisma-mysql-adapter's Introduction

@babrasoft/prisma-mysql-adapter

This package contains the driver adapter for Prisma ORM that enables usage of the node-mysql (mysql2) database driver for MySQL.

mysql2 is one of the most popular drivers in the JavaScript ecosystem for MySQL databases. It can be used with any MySQL database that's accessed via TCP.

Note: Support for the mysql driver is available from Prisma versions 5.4.0 and later.

Usage

This section explains how you can use it with Prisma ORM and the @babrasoft/prisma-mysql-adapter driver adapter. Be sure that the DATABASE_URL environment variable is set to your MySQL connection string (e.g. in a .env file).

1. Enable the driverAdapters Preview feature flag

Since driver adapters are currently in Preview, you need to enable its feature flag on the datasource block in your Prisma schema:

// schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

Once you have added the feature flag to your schema, re-generate Prisma Client:

npx prisma generate

2. Install the dependencies

Next, install the mysql2 package and our driver adapter:

npm install mysql2
npm install @babrasoft/prisma-mysql-adapter

3. Instantiate Prisma Client using the driver adapter

Finally, when you instantiate Prisma Client, you need to pass an instance of our driver adapter to the PrismaClient constructor:

import { createPool } from "mysql2/promise";
import { PrismaMySql } from "@babrasoft/prisma-mysql-adapter";
import { PrismaClient } from "@prisma/client";

const connectionString = `${process.env.DATABASE_URL}`;

const pool = createPool(connectionString);
const adapter = new PrismaMySql(pool);
const prisma = new PrismaClient({ adapter });

Feedback

This is an unofficial driver adapter until Prisma makes an official driver adapter for MySQL.

If you find something missing or run into a bug, please create an issue.

prisma-mysql-adapter's People

Contributors

fedebabrauskas avatar

Stargazers

Shinobi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.