1.0.3 • Published 9 months ago

@exlabs/clickhouse-prisma-adapter v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Clickhouse Prisma Adapter

Installation

Install the adapter using npm:

npm install @exlabs/clickhouse-prisma-adapter

Make sure that you have the following dependencies installed:

Usage

Step 1: Add the adapter to your Prisma schema

Add the adapter to your Prisma schema file:

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

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

Make sure that prisma schema reflects the schema of the Clickhouse database.

Note that the driverAdapters preview feature is required to use the adapter. Datasource provider should be set to mysql. This is a workaround to make Prisma CLI generate the client.

After updating the schema, run the following command to generate the Prisma client:

npx prisma generate

Step 2: Configure the adapter

Create new file, for example clickhouse-adapter.ts and add the following code:

import { createClient } from "@clickhouse/client";
import { PrismaClient } from "@prisma/client";
import ClickhousePrismaAdapter from "@exlabs/clickhouse-prisma-adapter";

export const client = createClient({
  url: "http://localhost:8123",
  password: "",
  username: "default",
  database: "default",
});

const adapter = new ClickhousePrismaAdapter({ client, schemaName: "default" });

export const prisma = new PrismaClient({ adapter });

Step 3: Use the adapter

Now you can use the adapter in your application:

import { prisma } from "./clickhouse-adapter";

async function main() {
  const users = await prisma.user.findMany();
  console.log(users);
}
1.0.3

9 months ago