c15t
/
C15T Logo
Select a version
Frameworks
Welcome to c15t Docs
Introduction to Consent Management (c15t)
AI Tools Integrations
OSS
Contributing to c15t.com
License
Building Privacy Tools in the Open
Legal
Cookie Policy
Privacy Policy
C15T Logo
HomeFrontendIntegrationsSelf HostChangelog
xbskydiscordgithub1.4k
c15t
/
C15T Logo
Select a version
Frameworks
Welcome to c15t Docs
Introduction to Consent Management (c15t)
AI Tools Integrations
OSS
Contributing to c15t.com
License
Building Privacy Tools in the Open
Legal
Cookie Policy
Privacy Policy
home-2Docs
chevron-rightSelf-host
chevron-rightV1
chevron-rightAdapters
chevron-rightPrisma

Prisma Adapter

The Prisma adapter integrates c15t Backend with Prisma ORM, providing type-safe database access with migration support and automatic schema generation.

Deprecated Feature

@c15t/backend v1 did not deliver the flexibility we wanted and fell short of our standards. It is now deprecated as we work on a full rewrite, with v2 entering canary soon. This does not affect consent.io deployments, which remain stable.

Installation

First, install Prisma and initialize your project:

npm install @prisma/client
npm install -D prisma
npx prisma init

Configuration

  1. Define your Prisma schema in prisma/schema.prisma:
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql" // or "mysql", "sqlite", etc.
  url      = env("DATABASE_URL")
}

model User {
  id        String   @id @default(uuid())
  name      String
  email     String   @unique
  createdAt DateTime @default(now()) @map("created_at")
}
  1. Generate the Prisma client:
npx prisma generate
  1. Configure the c15t instance with the Prisma adapter:
import { c15tInstance } from '@c15t/backend';
import { prismaAdapter } from '@c15t/backend/db/adapters/prisma';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

const instance = c15tInstance({
  baseURL: 'http://localhost:3000',
  database: prismaAdapter({ 
    client: prisma,
    // Optional: Configure logging
    logging: process.env.NODE_ENV !== 'production'
  }),
});

Usage Examples

Basic CRUD Operations

// Create a new record
const user = await instance.database.create('User', {
  name: 'John Doe',
  email: 'john@example.com'
});

// Find records
const users = await instance.database.find('User', {
  where: { email: 'john@example.com' },
  orderBy: { createdAt: 'desc' },
  limit: 10
});

// Update a record
const updatedUser = await instance.database.update(
  'User',
  { where: { id: user.id } },
  { name: 'John Smith' }
);

// Delete a record
await instance.database.delete('User', { where: { id: user.id } });

Transactions

await instance.database.transaction(async (trx) => {
  const user = await trx.create('User', { 
    name: 'Alice',
    email: 'alice@example.com'
  });
  
  await trx.create('Profile', { 
    userId: user.id,
    bio: 'Software engineer'
  });
});

Migrations

Run migrations using the Prisma CLI:

# Create a migration
npx prisma migrate dev --name add-user-model

# Apply migrations in production
npx prisma migrate deploy

Type Safety

The Prisma adapter provides type safety when used with TypeScript:

// Define your types to match your Prisma schema
type User = {
  id: string;
  name: string;
  email: string;
  createdAt: Date;
};

// Type-safe operations
const users = await instance.database.find<User>('User', {
  where: { email: 'john@example.com' }
});

Best Practices

  • Define schema in Prisma format - Use Prisma's schema format for auto-generated migration files
  • Use migrations for schema changes - Let Prisma handle database schema migrations
  • Enable query logging in development - Monitor query performance and debug issues
  • Consider connection pooling - Configure connection pools for production performance

Limitations

  • Table names must match Prisma model names
  • Some advanced query features may require direct Prisma client usage

Related Resources

  • Prisma Documentation
  • Database Adapter Interface
  • Core Concepts
C15T Logo
Leverage native React components for seamless integration and high performance in a robust Consent Management solution that empowers your development team while prioritizing privacy and compliance.
Product
  • Documentation
  • Components
Company
  • GitHub
  • Contact
Legal
  • Privacy Policy
  • Cookie Policy
c15t