Skip to content

Prisma Types

This file defines the core TypeScript types used 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.

typescript
export type IConfig = {
	generatedClientPath?: string, // Optional: Path to the generated Prisma client. Use if automatic resolver fails.
	onInit?: (prisma: any) => void | Promise<void>, // Optional: Hook called after Prisma client initialization.
};
  • generatedClientPath: Optional string specifying the path to the generated Prisma client. Use this if the automatic resolver cannot find the client.

  • 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.

typescript
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

typescript
import type { IConfig, IPrismaClient } from './types';

const config: IConfig = {
	generatedClientPath: './prisma/generated/client',
	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.

Released under the Apache-2.0 License.