Comprehensive guide to the database adapter system in c15t Backend, covering available adapters, query interface, and performance considerations.
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.
The c15t Backend package provides a flexible database adapter system that allows you to use different database backends while maintaining a consistent interface.
Overview
Database adapters provide a standardized way to interact with different database systems. Each adapter implements the DatabaseAdapter interface:
The Prisma adapter integrates with Prisma ORM for type-safe database access.
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 }),});
Features
Prisma ORM integration
Type safety
Schema management
Migration support
Drizzle Adapter
The Drizzle adapter provides integration with Drizzle ORM.
import { drizzleAdapter } from '@c15t/backend/db/adapters/drizzle';import { drizzle } from 'drizzle-orm/node-postgres';import { Pool } from 'pg';const pool = new Pool({ connectionString: 'postgres://user:password@localhost:5432/c15t',});const db = drizzle(pool);const instance = c15tInstance({ baseURL: 'http://localhost:3000', database: drizzleAdapter( db as unknown as { [p: string]: unknown }, { provider: 'pg', }, ),});
Features
Drizzle ORM integration
Type safety
Schema management
Query building
Creating Custom Adapters
You can create custom adapters by implementing the DatabaseAdapter interface: