Prisma Types
This file defines TypeScript types for configuring and interacting with the Prisma client in the @sodacore/core
Prisma integration. These types provide strong typing for plugin/service configuration and Prisma client usage.
Types
IConfig
Configuration options for the Prisma plugin/service.
export type IConfig = {
schemaFileLocation?: string, // Optional: Path to the Prisma schema file. Use if the automatic resolver fails.
onInit?: (prisma: any) => void | Promise<void>, // Optional: Hook called after Prisma client initialization.
};
schemaFileLocation: Optional string specifying the path to the Prisma schema file. Use this if the automatic resolver cannot find the schema.
onInit: Optional callback function that receives the Prisma client instance after it is initialized. Can be used for custom setup logic, seeding, or migrations. Supports both synchronous and asynchronous functions.
IPrismaClient
Type definition for the Prisma client instance.
export type IPrismaClient = {
$connect: () => Promise<void>, // Connects the client to the database.
$disconnect: () => Promise<void>, // Disconnects the client from the database.
[model: string]: any, // Dynamic access to Prisma models and methods.
};
$connect: Function to establish a connection to the database.
$disconnect: Function to close the connection to the database.
[model: string]: any: Allows dynamic access to Prisma models and their methods.
Usage
import type { IConfig, IPrismaClient } from './types';
const config: IConfig = {
schemaFileLocation: './prisma/schema.prisma',
onInit: async (prisma) => {
// Custom initialization logic
await prisma.user.create({ data: { name: 'Admin' } });
},
};
let prisma: IPrismaClient;
// ...initialize prisma and use as needed
Notes
- These types are intended for internal use by the Sodacore Prisma plugin and service, but can be used in your application for type safety.
- The
onInit
hook is useful for advanced initialization scenarios. - The dynamic model access in
IPrismaClient
allows for flexible usage with any Prisma schema.